class OffsitePayments::Integrations::YandexMoney::Notification

Public Class Methods

new(post, options = {}) click to toggle source
Calls superclass method OffsitePayments::Notification::new
# File lib/offsite_payments/integrations/yandex_money.rb, line 51
def initialize(post, options = {})
  super
  @response_code = '200'
end

Public Instance Methods

acknowledge(authcode = nil) click to toggle source

Acknowledge the transaction to YandexMoney. This method has to be called after a new apc arrives. YandexMoney will verify that all the information we received are correct and will return a ok or a fail.

Example:

def ipn
  notify = YandexMoneyNotification.new(request.raw_post)

  if notify.acknowledge(authcode)
    if notify.complete?
      ... process order ...
    end
  else
    ... log possible hacking attempt ...
  end
  render text: notify.response
# File lib/offsite_payments/integrations/yandex_money.rb, line 141
def acknowledge(authcode = nil)
  string = [params['_raw_action'],
            params['_raw_orderSumAmount'],
            params['_raw_orderSumCurrencyPaycash'],
            params['_raw_orderSumBankPaycash'],
            params['_raw_shopId'],
            params['_raw_invoiceId'],
            params['_raw_customerNumber'],
            authcode
  ].join(';')

  digest = Digest::MD5.hexdigest(string)
  res = params['_raw_md5'] == digest.upcase
  if res
    @response_code = '0'
  else
    @response_code = '1'
  end
end
complete?() click to toggle source
# File lib/offsite_payments/integrations/yandex_money.rb, line 56
def complete?
  params['_raw_action'] == 'paymentAviso'
end
currency() click to toggle source
# File lib/offsite_payments/integrations/yandex_money.rb, line 73
def currency
  params['_raw_orderSumCurrencyPaycash']
end
customer_id() click to toggle source
# File lib/offsite_payments/integrations/yandex_money.rb, line 86
def customer_id
  params['_raw_customerNumber']
end
get_response() click to toggle source
# File lib/offsite_payments/integrations/yandex_money.rb, line 94
def get_response()
  @response_code
end
gross() click to toggle source

the money amount we received in X.2 decimal.

# File lib/offsite_payments/integrations/yandex_money.rb, line 82
def gross
  params['_raw_orderSumAmount'].to_f
end
item_id() click to toggle source
# File lib/offsite_payments/integrations/yandex_money.rb, line 60
def item_id
  params['_raw_orderNumber']
end
payer_email() click to toggle source
# File lib/offsite_payments/integrations/yandex_money.rb, line 77
def payer_email
  params['_raw_cps_email']
end
received_at() click to toggle source

When was this payment received by the client.

# File lib/offsite_payments/integrations/yandex_money.rb, line 69
def received_at
  params['_raw_orderCreatedDatetime']
end
response() click to toggle source
# File lib/offsite_payments/integrations/yandex_money.rb, line 113
def response
  shop_id = params['_raw_shopId']
  method = params['_raw_action']
  dt = Time.now.iso8601
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
      "<#{method}Response performedDatetime=\"#{dt}\" code=\"#{@response_code}\"" +
      " invoiceId=\"#{transaction_id}\" shopId=\"#{shop_id}\"/>"
end
set_response(code) click to toggle source
# File lib/offsite_payments/integrations/yandex_money.rb, line 90
def set_response(code)
  @response_code = code
end
status() click to toggle source
# File lib/offsite_payments/integrations/yandex_money.rb, line 103
def status
  case params['_raw_action']
    when 'checkOrder'
      'pending'
    when 'paymentAviso'
      'completed'
    else 'unknown'
  end
end
test?() click to toggle source

Was this a test transaction?

# File lib/offsite_payments/integrations/yandex_money.rb, line 99
def test?
  false
end
transaction_id() click to toggle source
# File lib/offsite_payments/integrations/yandex_money.rb, line 64
def transaction_id
  params['_raw_invoiceId']
end

Private Instance Methods

parse(post) click to toggle source

Take the posted data and move the relevant data into a hash

# File lib/offsite_payments/integrations/yandex_money.rb, line 164
def parse(post)
  @raw = post.to_s
  for line in @raw.split('&')
    key, value = *line.scan( %r{^([A-Za-z0-9_.-]+)\=(.*)$} ).flatten
    # to divide raw values from other
    params['_raw_' + key] = CGI.unescape(value.to_s) if key.present?
  end
end