Module: RootInsurance::Api::Payment

Included in:
Client
Defined in:
lib/root_insurance/api/payment.rb

Instance Method Summary collapse

Instance Method Details

#create_payment_method(policyholder_id:, type: 'debit_order', bank_details: {}, policy_ids: nil) ⇒ Hash

Create a payment method

Bank details

account_holder (string)

Name of account holder.

bank (string)

Bank name - one of [absa, capitec, fnb, investec, nedbank, postbank, standard_bank]

branch_code (string)

Branch code for bank account

account_number (string)

Bank account number

Examples:

bank_details = {
  first_name:     "Erlich",
  last_name:      "Bachman",
  bank:           "absa",
  branch_code:    "12345",
  account_number: "123456789"
}
client.create_payment_method(
        policyholder_id: "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
        bank_details:    bank_details)

Parameters:

  • policyholder_id (String)

    The unique identifier of the policy holder.

  • type (String) (defaults to: 'debit_order')

    The payment method type. Curently only ‘debit_order’ is supported. If omitted, defaults to ‘debit_order’ (optional)

  • bank_details (Hash) (defaults to: {})

    Bank details to use for the debit order. See below for details.

  • policy_ids (String) (defaults to: nil)

    The date on the which the incident occured. (optional)

Returns:

  • (Hash)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/root_insurance/api/payment.rb', line 31

def create_payment_method(policyholder_id:, type: 'debit_order', bank_details: {}, policy_ids: nil)
  validate_bank_details(bank_details)

  data = {
    type:         type,
    bank_details: bank_details
  }

  if policy_ids && policy_ids.is_a?(Array)
    data.merge!(policy_ids: policy_ids)
  elsif policy_ids && policy_ids.is_a?(String)
    data.merge!(policy_ids: [policy_ids])
  end

  post("policyholders/#{policyholder_id}/payment-methods", data)
end

Link a payment method to a policy

Examples:

client.link_payment_method(
  policy_id:         "128ba0c0-3f6a-4f8b-9b40-e2066b02b59e",
  payment_method_id: "e0b7b222-772f-47ac-b08d-c7ba38aa1b25")

Parameters:

  • policy_id (String)

    The unique identifier of the policy.

  • payment_method_id (String)

    The unique identifier of the payment method.



58
59
60
61
62
# File 'lib/root_insurance/api/payment.rb', line 58

def link_payment_method(policy_id:, payment_method_id:)
  data = {payment_method_id: payment_method_id}

  put("policies/#{policy_id}/payment-method", data)
end