class OffsitePayments::Integrations::Coinbase::Helper
Public Class Methods
new(order_id, account, options)
click to toggle source
account should be a Coinbase
API key; see coinbase.com/account/integrations options should be the corresponding API secret
Calls superclass method
# File lib/offsite_payments/integrations/coinbase.rb, line 25 def initialize(order_id, account, options) super @order = order_id @account = account @options = options @options[:credential1] ||= '' @options[:credential2] ||= '' end
Public Instance Methods
form_fields()
click to toggle source
# 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