Class: OffsitePayments::Integrations::YandexMoney::Notification

Inherits:
Notification
  • Object
show all
Defined in:
lib/offsite_payments/integrations/yandex_money.rb

Instance Attribute Summary

Attributes inherited from Notification

#params, #raw

Instance Method Summary collapse

Methods inherited from Notification

#amount, #empty!, #gross_cents, #iso_currency, #valid_sender?

Constructor Details

#initialize(post, options = {}) ⇒ Notification

Returns a new instance of Notification.



51
52
53
54
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 51

def initialize(post, options = {})
  super
  @response_code = '200'
end

Instance Method Details

#acknowledge(authcode = nil) ⇒ Object

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


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# 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?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 56

def complete?
  params['_raw_action'] == 'paymentAviso'
end

#currencyObject



73
74
75
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 73

def currency
  params['_raw_orderSumCurrencyPaycash']
end

#customer_idObject



86
87
88
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 86

def customer_id
  params['_raw_customerNumber']
end

#get_responseObject



94
95
96
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 94

def get_response()
  @response_code
end

#grossObject

the money amount we received in X.2 decimal.



82
83
84
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 82

def gross
  params['_raw_orderSumAmount'].to_f
end

#item_idObject



60
61
62
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 60

def item_id
  params['_raw_orderNumber']
end

#payer_emailObject



77
78
79
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 77

def payer_email
  params['_raw_cps_email']
end

#received_atObject

When was this payment received by the client.



69
70
71
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 69

def received_at
  params['_raw_orderCreatedDatetime']
end

#responseObject



113
114
115
116
117
118
119
120
# 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) ⇒ Object



90
91
92
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 90

def set_response(code)
  @response_code = code
end

#statusObject



103
104
105
106
107
108
109
110
111
# 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?Boolean

Was this a test transaction?

Returns:

  • (Boolean)


99
100
101
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 99

def test?
  false
end

#transaction_idObject



64
65
66
# File 'lib/offsite_payments/integrations/yandex_money.rb', line 64

def transaction_id
  params['_raw_invoiceId']
end