Class: Bambora::V1::PaymentResource

Inherits:
Object
  • Object
show all
Defined in:
lib/bambora/v1/payment_resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, api_key:) ⇒ PaymentResource

Returns a new instance of PaymentResource.



8
9
10
11
12
# File 'lib/bambora/v1/payment_resource.rb', line 8

def initialize(client:, api_key:)
  @client = client
  @api_key = api_key
  @sub_path = '/v1/payments'
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



6
7
8
# File 'lib/bambora/v1/payment_resource.rb', line 6

def api_key
  @api_key
end

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/bambora/v1/payment_resource.rb', line 6

def client
  @client
end

#sub_pathObject (readonly)

Returns the value of attribute sub_path.



6
7
8
# File 'lib/bambora/v1/payment_resource.rb', line 6

def sub_path
  @sub_path
end

Instance Method Details

#create(payment_data) ⇒ Hash Also known as: make_payment

Make a payment with a credit card. Also aliased as make_payment.

Examples:


client = Bambora::Rest::JSONClient(base_url: '...', api_key: '...', merchant_id: '...')
payments = Bambora::V1::PaymentResource(client: client)
payments.create(
  {
    amount: 50,
    payment_method: 'card',
    card: {
      name: 'Hup Podling',
      number: '4504481742333',
      expiry_month: '12',
      expiry_year: '20',
      cvd: '123',
    },
  },
)

Parameters:

  • payment_data (Hash)

    All information relevant to making a payment.

Returns:

  • (Hash)

    Indicating success or failure of the operation.

See Also:



42
43
44
# File 'lib/bambora/v1/payment_resource.rb', line 42

def create(payment_data)
  client.post(path: sub_path, body: payment_data, api_key: api_key)
end

#create_with_payment_profile(customer_code:, amount:, card_id: 1, complete: false) ⇒ Hash Also known as: make_payment_with_payment_profile

Make a payment with a credit card. Aliased as make_payment_with_payment_profile.

Examples:


client = Bambora::Rest::JSONClient(base_url: '...', api_key: '...', merchant_id: '...')
payments = Bambora::V1::PaymentResource(client: client)
payments.create_with_payment_profile(
  customer_code: '2355E2e58Bf488EAB4EaFAD7083dB6A', amount: 50, complete: false
)

Parameters:

  • customer_code (String)

    Bambora’s payment profile ID.

  • amount (Float)

    A decimal value in dollars. Uses up to two decimal places. Max value is account specific. Default max value is 1000.

  • card_id (Integer) (defaults to: 1)

    Default 1. Which credit card to use. Starts at 1 for the first card. You must configure how many cards can be stored by visiting the profile options in the back office.

  • complete (Boolean) (defaults to: false)

    Default false. Set to false for Pre-Authorize, and true to complete a payment.

Returns:

  • (Hash)

    Indicating success or failure of the operation.



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bambora/v1/payment_resource.rb', line 67

def create_with_payment_profile(customer_code:, amount:, card_id: 1, complete: false)
  create(
    amount: amount,
    payment_method: 'payment_profile',
    payment_profile: {
      customer_code: customer_code,
      card_id: card_id,
      complete: complete,
    },
  )
end

#get(transaction_id:) ⇒ Hash

Retrieve the details of a previously attempted payment.

Examples:


client = Bambora::Rest::JSONClient(base_url: '...', api_key: '...', merchant_id: '...')
payments = Bambora::V1::PaymentResource(client: client)
payments.get(transaction_id: 1000341)

Parameters:

  • transaction_id (Integer)

    An integer identifier for the associated transaction.

Returns:

  • (Hash)

    Transaction details.



93
94
95
# File 'lib/bambora/v1/payment_resource.rb', line 93

def get(transaction_id:)
  client.get(path: "#{sub_path}/#{transaction_id}", api_key: api_key)
end