gocardless v0.1.1 Gocardless.Client

Starts up Gocardless Client

Uses Gocardless.ClientApi.Customer and other client APIs from /lib/client_apis/

Link to this section Summary

Functions

Cancels a mandate based on their ID in GoCardless

Cancels the payment if it has not already been submitted to the banks

Creates a new Customer

Creates a new Customer Bank Account

Creates a new mandate

Creates a new Payment

Gets a Customer based on their ID in GoCardless

Gets a Customer Bank Account based on their ID in GoCardless

Gets a mandate based on their ID in GoCardless

Gets an individual payment by ID

Lists Customer Bank Accounts from GoCardless

Lists Customers from GoCardless

Lists mandates from GoCardless

Lists all payments

Reinstates a mandate based on their ID in GoCardless

Retries a failed payment if the underlying mandate is active

Updates a Customer based on their ID in GoCardless

Updates a Customer Bank Account metadata based on their ID in GoCardless. Only the metadata parameter is allowed

Updates a mandate based on their ID in GoCardless

Updates a Payment metadata based by ID. Only the metadata parameter is allowed

Link to this section Functions

Link to this function cancel_mandate(mandate_id)

Cancels a mandate based on their ID in GoCardless

Examples

iex> Gocardless.Client.cancel_mandate("MD000999999999")
{:ok,
 %{"mandates" => %{"created_at" => "2017-06-23T15:31:52.850Z",
     "id" => "MD000999999999",
     "links" => %{"creditor" => "CR000999999999",
       "customer" => "CU000999999999",
       "customer_bank_account" => "BA000999999999"},
     "metadata" => %{}, "next_possible_charge_date" => nil,
     "payments_require_approval" => false, "reference" => "REF-REF",
     "scheme" => "bacs", "status" => "cancelled"}}}

Callback implementation for Gocardless.Behaviour.Mandate.cancel_mandate/1.

Link to this function cancel_payment(payment_id, params \\ %{})

Cancels the payment if it has not already been submitted to the banks.

Examples

iex> Gocardless.Client.cancel_payment("PM000099999999")
{:ok,
%{"payments" => %{"amount" => 100, "amount_refunded" => 0,
    "charge_date" => "2017-06-30", "created_at" => "2017-06-23T15:27:18.656Z",
    "currency" => "GBP", "description" => nil, "id" => "PM000099999999",
    "links" => %{"creditor" => "CR000099999999",
      "mandate" => "MD000099999999"}, "metadata" => %{"db_id" => "1234"},
    "reference" => nil, "status" => "cancelled"}}}

Callback implementation for Gocardless.Behaviour.Payment.cancel_payment/2.

Link to this function create_customer(params)

Creates a new Customer

Examples

iex> params = %{
  email: "name@email.com",
  given_name: "Firstname",
  family_name: "Lastname",
  country_code: "GB"
}
iex> Gocardless.Client.create_customer(%{customers: params})
{:ok,
  %{"customers" => %{"address_line1" => nil, "address_line2" => nil,
     "address_line3" => nil, "city" => nil, "company_name" => nil,
     "country_code" => "GB", "created_at" => "2017-06-23T13:04:45.459Z",
     "email" => "name@email.com", "family_name" => "Lastname",
     "given_name" => "Firstname", "id" => "CU000201WWT5RS", "language" => "en",
     "metadata" => %{}, "postal_code" => nil, "region" => nil,
     "swedish_identity_number" => nil}}}

Callback implementation for Gocardless.Behaviour.Customer.create_customer/1.

Link to this function create_customer_bank_account(params)

Creates a new Customer Bank Account

Examples

iex> params = %{
  customer_bank_accounts: %{
    account_holder_name: "FirstName LastName", 
    account_number: "55779911", 
    branch_code: "200000", 
    country_code: "GB", 
    links: %{
      customer: "CU000999999998"
    }
  }
}
iex> Gocardless.Client.create_customer_bank_account(params)
{:ok,
%{"customer_bank_accounts" => %{"account_holder_name" => "FirstName LastName",
    "account_number_ending" => "11", "bank_name" => "BARCLAYS BANK PLC",
    "country_code" => "GB", "created_at" => "2017-06-23T13:37:09.967Z",
    "currency" => "GBP", "enabled" => true, "id" => "BA000999999998",
    "links" => %{"customer" => "CU000999999998"}, "metadata" => %{}}}}

Callback implementation for Gocardless.Behaviour.CustomerBankAccount.create_customer_bank_account/1.

Link to this function create_mandate(params)

Creates a new mandate

Examples

iex> params = %{
  scheme: "bacs",
  links: %{customer_bank_account: "BA000999999999"}
}
iex> Gocardless.Client.create_mandate(%{mandates: params})
{:ok,
 %{"mandates" => %{"created_at" => "2017-06-23T15:29:20.872Z",
     "id" => "MD000999999999",
     "links" => %{"creditor" => "CR000999999999",
       "customer" => "CU000999999999",
       "customer_bank_account" => "BA000999999999"}, "metadata" => %{},
     "next_possible_charge_date" => "2017-06-30",
     "payments_require_approval" => false, "reference" => "REF-REF",
     "scheme" => "bacs", "status" => "pending_submission"}}}

Callback implementation for Gocardless.Behaviour.Mandate.create_mandate/1.

Link to this function create_payment(params)

Creates a new Payment

Examples

iex> params = %{
  payments: %{
    amount: 100,
    currency: "GBP",
    charge_date: "2017-06-30",
    links: %{
      mandate: "MD000099999999"
    }
  }
}
iex> Gocardless.Client.create_payment(params)                                                                        {:ok,
{:ok, 
%{"payments" => %{"amount" => 100, "amount_refunded" => 0,
    "charge_date" => "2017-06-30", "created_at" => "2017-06-23T15:27:18.656Z",
    "currency" => "GBP", "description" => nil, "id" => "PM000099999999",
    "links" => %{"creditor" => "CR000099999999",
      "mandate" => "MD000099999999"}, "metadata" => %{}, "reference" => nil,
    "status" => "pending_submission"}}}

Callback implementation for Gocardless.Behaviour.Payment.create_payment/1.

Link to this function disable_customer_bank_account(customer_bank_account_id)

Examples

iex> Gocardless.Client.disable_customer_bank_account("BA000999999998")
{:ok,
%{"customer_bank_accounts" => %{"account_holder_name" => "FirstName LastName",
    "account_number_ending" => "11", "bank_name" => "BARCLAYS BANK PLC",
    "country_code" => "GB", "created_at" => "2017-06-23T13:37:09.967Z",
    "currency" => "GBP", "enabled" => false, "id" => "BA000999999998",
    "links" => %{"customer" => "CU000999999998"},
    "metadata" => %{}}}}

Callback implementation for Gocardless.Behaviour.CustomerBankAccount.disable_customer_bank_account/1.

Link to this function get_customer(customer_id)

Gets a Customer based on their ID in GoCardless

Examples

iex> Gocardless.Client.get_customer("CU000999999998")
{:ok,
 %{"customers" => %{"address_line1" => nil, "address_line2" => nil,
     "address_line3" => nil, "city" => nil, "company_name" => nil,
     "country_code" => "GB", "created_at" => "2017-06-23T10:47:22.248Z",
     "email" => "name@email.com", "family_name" => "Lastname",
     "given_name" => "Firstname", "id" => "CU000999999998", "language" => "en",
     "metadata" => %{}, "postal_code" => nil, "region" => nil,
     "swedish_identity_number" => nil}}}

Callback implementation for Gocardless.Behaviour.Customer.get_customer/1.

Link to this function get_customer_bank_account(customer_bank_account_id)

Gets a Customer Bank Account based on their ID in GoCardless

Examples

iex> Gocardless.Client.get_customer_bank_account("BA000999999998")
{:ok,
%{"customer_bank_accounts" => %{"account_holder_name" => "FirstName LastName",
    "account_number_ending" => "11", "bank_name" => "BARCLAYS BANK PLC",
    "country_code" => "GB", "created_at" => "2017-06-23T13:37:09.967Z",
    "currency" => "GBP", "enabled" => true, "id" => "BA000999999998",
    "links" => %{"customer" => "CU000999999998"},
    "metadata" => %{"account_holder_name" => "FirstName LastName"}}}}

Callback implementation for Gocardless.Behaviour.CustomerBankAccount.get_customer_bank_account/1.

Link to this function get_mandate(mandate_id)

Gets a mandate based on their ID in GoCardless

Examples

iex> Gocardless.Client.get_mandate("MD000999999998")
{:ok,
 %{"mandates" => %{"created_at" => "2017-06-23T15:29:20.872Z",
     "id" => "MD000999999998",
     "links" => %{"creditor" => "CR000999999998",
       "customer" => "CU000999999998",
       "customer_bank_account" => "BA000999999998"}, "metadata" => %{},
     "next_possible_charge_date" => "2017-06-30",
     "payments_require_approval" => false, "reference" => "REF-REF",
     "scheme" => "bacs", "status" => "pending_submission"}}}

Callback implementation for Gocardless.Behaviour.Mandate.get_mandate/1.

Link to this function get_payment(payment_id)

Gets an individual payment by ID

Examples

iex> Gocardless.Client.get_payment("PM000099999999")
{:ok,
%{"payments" => %{"amount" => 100, "amount_refunded" => 0,
    "charge_date" => "2017-06-30", "created_at" => "2017-06-23T15:27:18.656Z",
    "currency" => "GBP", "description" => nil, "id" => "PM000099999999",
    "links" => %{"creditor" => "CR000099999999",
      "mandate" => "MD000099999999"}, "metadata" => %{}, "reference" => nil,
    "status" => "pending_submission"}}}

Callback implementation for Gocardless.Behaviour.Payment.get_payment/1.

Link to this function list_customer_bank_accounts(params \\ %{})

Lists Customer Bank Accounts from GoCardless

Examples

iex> Gocardless.Client.list_customer_bank_accounts
{:ok,
%{"customer_bank_accounts" => [%{"account_holder_name" => "FirstName LastName",
      "account_number_ending" => "11", "bank_name" => "BARCLAYS BANK PLC",
      "country_code" => "GB", "created_at" => "2017-06-23T13:37:09.967Z",
      "currency" => "GBP", "enabled" => true, "id" => "BA000999999998",
      "links" => %{"customer" => "CU000999999998"},
      "metadata" => %{"account_holder_name" => "FirstName LastName"}}],
  "meta" => %{"cursors" => %{"after" => nil, "before" => nil}, "limit" => 50}}}

Callback implementation for Gocardless.Behaviour.CustomerBankAccount.list_customer_bank_accounts/1.

Link to this function list_customers(params \\ %{})

Lists Customers from GoCardless

Examples

iex> Gocardless.Client.list_customers()
{:ok,
%{"customers" => [%{"address_line1" => nil, "address_line2" => nil,
    "address_line3" => nil, "city" => nil, "company_name" => nil,
    "country_code" => "GB", "created_at" => "2017-06-23T10:47:22.248Z",
    "email" => "name@email.com", "family_name" => "Lastname",
    "given_name" => "Firstname", "id" => "CU000999999997", "language" => "en",
    "metadata" => %{}, "postal_code" => nil, "region" => nil,
    "swedish_identity_number" => nil},
  %{"address_line1" => nil, "address_line2" => nil, "address_line3" => nil,
    "city" => nil, "company_name" => nil, "country_code" => "GB",
    "created_at" => "2017-06-22T17:11:04.112Z",
    "email" => "name@email.com", "family_name" => "Lastname2",
    "given_name" => "Firstname2", "id" => "CU000999999998", "language" => "en",
    "metadata" => %{}, "postal_code" => nil, "region" => nil,
    "swedish_identity_number" => nil}],
 "meta" => %{"cursors" => %{"after" => nil, "before" => nil}, "limit" => 50}}}

iex> Gocardless.Client.list_customers(%{"created_at[gt]" => "2017-06-22T17:18:06.000Z"})
{:ok,
 %{"customers" => [%{"address_line1" => nil, "address_line2" => nil,
      "address_line3" => nil, "city" => nil, "company_name" => nil,
      "country_code" => "GB", "created_at" => "2017-06-23T10:47:22.248Z",
      "email" => "name@email.com", "family_name" => "Lastname",
      "given_name" => "Firstname", "id" => "CU000999999997", "language" => "en",
      "metadata" => %{}, "postal_code" => nil, "region" => nil,
      "swedish_identity_number" => nil}],
   "meta" => %{"cursors" => %{"after" => nil, "before" => nil}, "limit" => 50}}}

Callback implementation for Gocardless.Behaviour.Customer.list_customers/1.

Link to this function list_mandates(params \\ %{})

Lists mandates from GoCardless

Examples

iex> Gocardless.Client.list_mandates()
{:ok,
 %{"mandates" => [%{"created_at" => "2017-06-23T15:31:52.850Z",
      "id" => "MD000999999998",
      "links" => %{"creditor" => "CR000999999998",
        "customer" => "CU000999999998",
        "customer_bank_account" => "BA000999999998"}, "metadata" => %{},
      "next_possible_charge_date" => "2017-06-30",
      "payments_require_approval" => false, "reference" => "REF-REF",
      "scheme" => "bacs", "status" => "pending_submission"},
    %{"created_at" => "2017-06-23T15:29:20.872Z", "id" => "MD000999999997",
      "links" => %{"creditor" => "CR000999999998",
        "customer" => "CU000999999998",
        "customer_bank_account" => "BA000999999998"}, "metadata" => %{},
      "next_possible_charge_date" => "2017-06-30",
      "payments_require_approval" => false, "reference" => "REF-REF",
      "scheme" => "bacs", "status" => "pending_submission"},
    %{"created_at" => "2017-06-23T15:24:31.356Z", "id" => "MD000999999996",
      "links" => %{"creditor" => "CR000999999998",
        "customer" => "CU000999999998",
        "customer_bank_account" => "BA000999999998"}, "metadata" => %{},
      "next_possible_charge_date" => "2017-06-30",
      "payments_require_approval" => false, "reference" => "REF-REF",
      "scheme" => "bacs", "status" => "pending_submission"}],
   "meta" => %{"cursors" => %{"after" => nil, "before" => nil}, "limit" => 50}}}

iex> Gocardless.Client.list_mandates(%{customer: "CU000999999999"})
{:ok,
 %{"mandates" => [%{"created_at" => "2017-06-23T15:31:52.850Z",
      "id" => "MD000999999999",
      "links" => %{"creditor" => "CR000999999999",
        "customer" => "CU000999999999",
        "customer_bank_account" => "BA000999999999"}, "metadata" => %{},
      "next_possible_charge_date" => "2017-06-30",
      "payments_require_approval" => false, "reference" => "REF-REF",
      "scheme" => "bacs", "status" => "pending_submission"}],
  "meta" => %{"cursors" => %{"after" => nil, "before" => nil}, "limit" => 50}}}

Callback implementation for Gocardless.Behaviour.Mandate.list_mandates/1.

Link to this function list_payments(params \\ %{})

Lists all payments

Examples

iex> Gocardless.Client.list_payments
{:ok,
%{"meta" => %{"cursors" => %{"after" => nil, "before" => nil}, "limit" => 50},
  "payments" => [%{"amount" => 100, "amount_refunded" => 0,
      "charge_date" => "2017-06-30", "created_at" => "2017-06-23T15:27:18.656Z",
      "currency" => "GBP", "description" => nil, "id" => "PM000099999999",
      "links" => %{"creditor" => "CR000099999999",
        "mandate" => "MD000099999999"}, "metadata" => %{}, "reference" => nil,
      "status" => "pending_submission"}]}}

iex> Gocardless.Client.list_payments(%{"created_at[gt]" => "2017-06-22T17:18:06.000Z"})
{:ok,
%{"meta" => %{"cursors" => %{"after" => nil, "before" => nil}, "limit" => 50},
  "payments" => [%{"amount" => 100, "amount_refunded" => 0,
      "charge_date" => "2017-06-30", "created_at" => "2017-06-23T15:27:18.656Z",
      "currency" => "GBP", "description" => nil, "id" => "PM000099999999",
      "links" => %{"creditor" => "CR000099999999",
        "mandate" => "MD000099999999"}, "metadata" => %{}, "reference" => nil,
      "status" => "pending_submission"}]}}

Callback implementation for Gocardless.Behaviour.Payment.list_payments/1.

Link to this function reinstate_mandate(mandate_id)

Reinstates a mandate based on their ID in GoCardless

Examples

iex> Gocardless.Client.reinstate_mandate("MD000999999999")
{:ok,
 %{"mandates" => %{"created_at" => "2017-06-23T15:31:52.850Z",
     "id" => "MD000999999999",
     "links" => %{"creditor" => "CR000999999999",
       "customer" => "CU000999999999",
       "customer_bank_account" => "BA000999999999"},
     "metadata" => %{},
     "next_possible_charge_date" => "2017-06-30",
     "payments_require_approval" => false, "reference" => "REF-REF",
     "scheme" => "bacs", "status" => "pending_submission"}}}

Callback implementation for Gocardless.Behaviour.Mandate.reinstate_mandate/1.

Link to this function retry_payment(payment_id, params \\ %{})

Retries a failed payment if the underlying mandate is active.

Examples

iex> Gocardless.Client.retry_payment("PM000099999999")

Callback implementation for Gocardless.Behaviour.Payment.retry_payment/2.

Link to this function update_customer(customer_id, params)

Updates a Customer based on their ID in GoCardless

Examples

iex> params = %{email: "new@email.com"}
iex> Gocardless.Client.update_customer("CU000999999998", %{customers: params})
{:ok,
 %{"customers" => %{"address_line1" => nil, "address_line2" => nil,
     "address_line3" => nil, "city" => nil, "company_name" => nil,
     "country_code" => "GB", "created_at" => "2017-06-23T13:04:45.459Z",
     "email" => "new@email.com", "family_name" => "Lastname",
     "given_name" => "Firstname", "id" => "CU000999999998", "language" => "en",
     "metadata" => %{}, "postal_code" => nil, "region" => nil,
     "swedish_identity_number" => nil}}}

Callback implementation for Gocardless.Behaviour.Customer.update_customer/2.

Link to this function update_customer_bank_account(customer_bank_account_id, params)

Updates a Customer Bank Account metadata based on their ID in GoCardless. Only the metadata parameter is allowed.

Examples

iex> params = %{
  customer_bank_accounts: %{
    metadata: %{
      db_id: "1234"
    }
  }
}
iex> Gocardless.Client.update_customer_bank_account("BA000999999998", params)
{:ok,
%{"customer_bank_accounts" => %{"account_holder_name" => "FirstName LastName",
    "account_number_ending" => "11", "bank_name" => "BARCLAYS BANK PLC",
    "country_code" => "GB", "created_at" => "2017-06-23T13:37:09.967Z",
    "currency" => "GBP", "enabled" => true, "id" => "BA000999999998",
    "links" => %{"customer" => "CU000999999998"},
    "metadata" => %{"db_id" => "1234"}}}}

Callback implementation for Gocardless.Behaviour.CustomerBankAccount.update_customer_bank_account/2.

Link to this function update_mandate(mandate_id, params)

Updates a mandate based on their ID in GoCardless

Examples

iex> params = %{
  mandates: %{
    metadata: %{
      db_id: "1234"
    }
  }
}
iex> Gocardless.Client.update_mandate("MD000999999999", params)
{:ok,
 %{"mandates" => %{"created_at" => "2017-06-23T15:31:52.850Z",
     "id" => "MD000999999999",
     "links" => %{"creditor" => "CR000999999999",
       "customer" => "CU000999999999",
       "customer_bank_account" => "BA000999999999"},
     "metadata" => %{"db_id" => "1234"},
     "next_possible_charge_date" => "2017-06-30",
     "payments_require_approval" => false, "reference" => "REF-REF",
     "scheme" => "bacs", "status" => "pending_submission"}}}

Callback implementation for Gocardless.Behaviour.Mandate.update_mandate/2.

Link to this function update_payment(payment_id, params)

Updates a Payment metadata based by ID. Only the metadata parameter is allowed.

Examples

iex> params = %{
  payments: %{
    metadata: %{
      db_id: "1234"
    }
  }
}
iex> Gocardless.Client.update_payment("PM000099999999", mtd)
{:ok,
%{"payments" => %{"amount" => 100, "amount_refunded" => 0,
    "charge_date" => "2017-06-30", "created_at" => "2017-06-23T15:27:18.656Z",
    "currency" => "GBP", "description" => nil, "id" => "PM000099999999",
    "links" => %{"creditor" => "CR000099999999",
      "mandate" => "MD000099999999"}, "metadata" => %{"db_id" => "1234"},
    "reference" => nil, "status" => "pending_submission"}}}

Callback implementation for Gocardless.Behaviour.Payment.update_payment/2.