Gocardlex.Behaviour.Payment behaviour (gocardlex v1.0.4)

Summary

Callbacks

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

Creates a new Payment

Gets an individual payment by ID

Lists all payments

Retries a failed payment if the underlying mandate is active.

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

Callbacks

cancel_payment(t, map)

@callback cancel_payment(String.t(), map()) :: tuple()

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

Examples

iex> Gocardlex.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"}}}

create_payment(map)

@callback create_payment(map()) :: tuple()

Creates a new Payment

Examples

iex> params = %{
  payments: %{
    amount: 100,
    currency: "GBP",
    charge_date: "2017-06-30",
    links: %{
      mandate: "MD000099999999"
    }
  }
}
iex> Gocardlex.Client.create_payment(params)
{: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"}}}

get_payment(t)

@callback get_payment(String.t()) :: tuple()

Gets an individual payment by ID

Examples

iex> Gocardlex.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"}}}

list_payments(map)

@callback list_payments(map()) :: tuple()

Lists all payments

Examples

iex> Gocardlex.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> Gocardlex.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"}]}}

retry_payment(t, map)

@callback retry_payment(String.t(), map()) :: tuple()

Retries a failed payment if the underlying mandate is active.

Examples

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

update_payment(t, map)

@callback update_payment(String.t(), map()) :: tuple()

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

Examples

iex> params = %{
  payments: %{
    metadata: %{
      db_id: "1234"
    }
  }
}
iex> Gocardlex.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"}}}