Class: OffsitePayments::Integrations::Coinbase::Notification
- Inherits:
-
Notification
- Object
- Notification
- OffsitePayments::Integrations::Coinbase::Notification
show all
- Defined in:
- lib/offsite_payments/integrations/coinbase.rb
Instance Attribute Summary
Attributes inherited from Notification
#params, #raw
Instance Method Summary
collapse
#amount, #empty!, #gross_cents, #initialize, #iso_currency, #test?, #valid_sender?
Instance Method Details
#acknowledge(authcode = {}) ⇒ Object
Acknowledge the transaction to Coinbase. This method has to be called after a new apc arrives. Coinbase will verify that all the information we received are correct and will return a ok or a fail.
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/offsite_payments/integrations/coinbase.rb', line 107
def acknowledge(authcode = {})
uri = URI.parse(Coinbase.notification_confirmation_url % transaction_id)
response = Coinbase.do_request(uri, @options[:credential1], @options[:credential2])
return false if response.nil?
posted_order = @params
parse(response)
return false unless @params
%w(id custom total_native status).all? { |param| posted_order[param] == @params[param] }
end
|
#complete? ⇒ Boolean
67
68
69
|
# File 'lib/offsite_payments/integrations/coinbase.rb', line 67
def complete?
status == "Completed"
end
|
#currency ⇒ Object
91
92
93
|
# File 'lib/offsite_payments/integrations/coinbase.rb', line 91
def currency
params['total_native']['currency_iso']
end
|
#gross ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/offsite_payments/integrations/coinbase.rb', line 83
def gross
if params['total_original'].present?
"%.2f" % (params['total_original']['cents'].to_f / 100)
else
"%.2f" % (params['total_native']['cents'].to_f / 100)
end
end
|
#item_id ⇒ Object
71
72
73
|
# File 'lib/offsite_payments/integrations/coinbase.rb', line 71
def item_id
params['custom']
end
|
#received_at ⇒ Object
79
80
81
|
# File 'lib/offsite_payments/integrations/coinbase.rb', line 79
def received_at
Time.iso8601(params['created_at']).to_time.to_i
end
|
#status ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'lib/offsite_payments/integrations/coinbase.rb', line 95
def status
case params['status']
when "completed"
"Completed"
else
"Failed"
end
end
|
#transaction_id ⇒ Object
75
76
77
|
# File 'lib/offsite_payments/integrations/coinbase.rb', line 75
def transaction_id
params['id']
end
|