class OffsitePayments::Integrations::Coinbase::Helper

def form_fields

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

def initialize(order_id, account, options)

options[:credential2] should be the corresponding API secret
account should be a Coinbase API key; see https://coinbase.com/account/integrations
def initialize(order_id, account, options)
  super
  @order = order_id
  @account = account
  @options = options
  @options[:credential1] ||= ''
  @options[:credential2] ||= ''
end