Class: OffsitePayments::Integrations::Coinbase::Helper

Inherits:
Helper
  • Object
show all
Defined in:
lib/offsite_payments/integrations/coinbase.rb

Instance Attribute Summary

Attributes inherited from Helper

#fields

Instance Method Summary collapse

Methods inherited from Helper

#add_field, #add_fields, #add_raw_html_field, #billing_address, #form_method, inherited, mapping, #raw_html_fields, #shipping_address, #test?

Constructor Details

#initialize(order_id, account, options) ⇒ Helper

account should be a Coinbase API key; see coinbase.com/account/integrations options should be the corresponding API secret



25
26
27
28
29
30
31
32
33
# File 'lib/offsite_payments/integrations/coinbase.rb', line 25

def initialize(order_id, , options)
  super

  @order = order_id
  @account = 
  @options = options
  @options[:credential1] ||= ''
  @options[:credential2] ||= ''
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OffsitePayments::Helper

Instance Method Details

#form_fieldsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/offsite_payments/integrations/coinbase.rb', line 39

def form_fields
  uri = URI.parse(Coinbase.buttoncreate_url)

  request_body = {
    'button[auto_redirect]' => true,
    'button[name]' => @options[:description] || "Your Order",
    'button[price_string]' => @options[:amount],
    'button[price_currency_iso]' => @options[:currency],
    'button[custom]' => @order,
    'button[callback_url]' => @fields['notify_url'],
    'button[success_url]' => @fields['return_url'],
    'button[cancel_url]' => @fields['cancel_return_url'],
    'api_key' => @account
  }.to_query

  data = Coinbase.do_request(uri, @account, @options[:credential2], request_body)
  json = JSON.parse(data)

  raise ActionViewHelperError, "Error occured while contacting gateway : #{json['error']}" if json['error']

  {'id' => json['button']['code']}
rescue JSON::ParserError
  raise ActionViewHelperError, 'Invalid response from gateway. Please try again.'
end