Module: ArrowPayments::PaymentMethods

Included in:
Client
Defined in:
lib/arrow_payments/client/payment_methods.rb

Instance Method Summary collapse

Instance Method Details

#complete_payment_method(token_id) ⇒ PaymentMethod

Complete payment method creation

Parameters:

  • token (String)

    ID

Returns:



55
56
57
58
# File 'lib/arrow_payments/client/payment_methods.rb', line 55

def complete_payment_method(token_id)
  resp = post('/paymentmethod/complete', 'TokenID' => token_id)
  ArrowPayments::PaymentMethod.new(resp)
end

#create_payment_method(customer_id, address, card) ⇒ PaymentMethod

Create a new payment method. This is a wrapper on top of 3 step process

Parameters:

Returns:



65
66
67
68
69
70
# File 'lib/arrow_payments/client/payment_methods.rb', line 65

def create_payment_method(customer_id, address, card)
  url   = start_payment_method(customer_id, address)
  token = setup_payment_method(url, card)
  
  complete_payment_method(token)
end

#delete_payment_method(id) ⇒ Boolean

Delete an existing payment method

Parameters:

  • payment (Integer)

    method ID

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/arrow_payments/client/payment_methods.rb', line 75

def delete_payment_method(id)
  resp = post('/paymentmethod/delete', 'PaymentMethodId' => id)
  resp['Success'] == true
end

#payment_method(customer_id, id) ⇒ PaymentMethod Also known as: get_payment_method

Get a single payment method

Parameters:

  • customer (Integer)

    ID

  • payment (Integer)

    method ID

Returns:



7
8
9
# File 'lib/arrow_payments/client/payment_methods.rb', line 7

def payment_method(customer_id, id)
  customer(customer_id).payment_methods.select { |cc| cc.id == id }.first
end

#setup_payment_method(form_url, payment_method) ⇒ String

Setup a new payment method

Parameters:

  • payment (String)

    method form url

  • payment (PaymentMethod)

    method instance or hash

Returns:

  • (String)

    confirmation token



41
42
43
44
45
46
47
48
49
50
# File 'lib/arrow_payments/client/payment_methods.rb', line 41

def setup_payment_method(form_url, payment_method)
  cc = payment_method

  if payment_method.kind_of?(Hash)
    cc = ArrowPayments::PaymentMethod.new(payment_method)
  end

  resp = post_to_url(form_url, payment_method_form(cc))
  resp.headers['location'].scan(/token-id=(.*)/).flatten.first
end

#start_payment_method(customer_id, billing_address, return_url = nil) ⇒ String

Start a new payment method

Parameters:

  • customer (Integer)

    ID

  • billing (Address)

    address instance

  • return (String)

    url

Returns:

  • (String)

    payment method form url



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/arrow_payments/client/payment_methods.rb', line 18

def start_payment_method(customer_id, billing_address, return_url=nil)
  if billing_address.kind_of?(Hash)
    billing_address = ArrowPayments::Address.new(billing_address)
  end

  params = {
    'CustomerId'     => customer_id,
    'BillingAddress' => billing_address.to_source_hash
  }

  # If return url is blank means that its not browser-less payment method
  # creation. Reponse should include token ID for the Step 3.
  if return_url
    params['ReturnUrl'] = return_url
  end

  post("/paymentmethod/start", params)['FormPostUrl']
end