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

Defines the behaviour for Subscriptions

Summary

Callbacks

Examples

iex> Gocardlex.Client.cancel_subscription("SB000999999998")
{:ok,
 %{"subscriptions" => %{"amount" => 2500,
     "created_at" => "2017-06-26T11:03:27.037Z", "currency" => "GBP",
     "day_of_month" => 1, "end_date" => nil, "id" => "SB000999999998",
     "interval" => 1, "interval_unit" => "monthly",
     "links" => %{"mandate" => "MD000999999998"},
     "metadata" => %{"order_no" => "ABCD1234"}, "month" => nil,
     "name" => "Updated Name", "payment_reference" => nil,
     "start_date" => "2017-07-03", "status" => "cancelled",
     "upcoming_payments" => []}}}

Creates a new Subscription

Gets a Subscription based on their ID in GoCardless

Lists Subscriptions from GoCardless

Updates a Subscription in GoCardless.

Callbacks

cancel_subscription(t)

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

Examples

iex> Gocardlex.Client.cancel_subscription("SB000999999998")
{:ok,
 %{"subscriptions" => %{"amount" => 2500,
     "created_at" => "2017-06-26T11:03:27.037Z", "currency" => "GBP",
     "day_of_month" => 1, "end_date" => nil, "id" => "SB000999999998",
     "interval" => 1, "interval_unit" => "monthly",
     "links" => %{"mandate" => "MD000999999998"},
     "metadata" => %{"order_no" => "ABCD1234"}, "month" => nil,
     "name" => "Updated Name", "payment_reference" => nil,
     "start_date" => "2017-07-03", "status" => "cancelled",
     "upcoming_payments" => []}}}

create_subscription(map)

@callback create_subscription(map()) :: tuple()

Creates a new Subscription

Examples

iex> params = %{
  subscriptions: %{
    amount: "2500",
    currency: "GBP",
    name: "Monthly Magazine",
    interval_unit: "monthly",
    day_of_month:  "1",
    metadata: %{
      "order_no": "ABCD1234"
    },
    links: %{
      mandate: "MD000999999998"
    }
  }
}
iex> Gocardlex.Client.create_subscription(params)
{:ok,
 %{"subscriptions" => %{"amount" => 2500,
     "created_at" => "2017-06-26T11:03:27.037Z", "currency" => "GBP",
     "day_of_month" => 1, "end_date" => nil, "id" => "SB000999999998",
     "interval" => 1, "interval_unit" => "monthly",
     "links" => %{"mandate" => "MD000999999998"},
     "metadata" => %{"order_no" => "ABCD1234"}, "month" => nil,
     "name" => "Monthly Magazine", "payment_reference" => nil,
     "start_date" => "2017-07-03", "status" => "active",
     "upcoming_payments" => [%{"amount" => 2500, "charge_date" => "2017-07-03"},
      %{"amount" => 2500, "charge_date" => "2017-08-01"},
      %{"amount" => 2500, "charge_date" => "2017-09-01"},
      %{"amount" => 2500, "charge_date" => "2017-10-02"},
      %{"amount" => 2500, "charge_date" => "2017-11-01"},
      %{"amount" => 2500, "charge_date" => "2017-12-01"},
      %{"amount" => 2500, "charge_date" => "2018-01-02"},
      %{"amount" => 2500, "charge_date" => "2018-02-01"},
      %{"amount" => 2500, "charge_date" => "2018-03-01"},
      %{"amount" => 2500, "charge_date" => "2018-04-03"}]}}}

get_subscription(t)

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

Gets a Subscription based on their ID in GoCardless

Examples

iex> Gocardlex.Client.get_subscription("SB000999999998")
{:ok,
 %{"subscriptions" => %{"amount" => 2500,
     "created_at" => "2017-06-26T11:03:27.037Z", "currency" => "GBP",
     "day_of_month" => 1, "end_date" => nil, "id" => "SB000999999998",
     "interval" => 1, "interval_unit" => "monthly",
     "links" => %{"mandate" => "MD000999999998"},
     "metadata" => %{"order_no" => "ABCD1234"}, "month" => nil,
     "name" => "Monthly Magazine", "payment_reference" => nil,
     "start_date" => "2017-07-03", "status" => "active",
     "upcoming_payments" => [%{"amount" => 2500, "charge_date" => "2017-07-03"},
      %{"amount" => 2500, "charge_date" => "2017-08-01"},
      %{"amount" => 2500, "charge_date" => "2017-09-01"},
      %{"amount" => 2500, "charge_date" => "2017-10-02"},
      %{"amount" => 2500, "charge_date" => "2017-11-01"},
      %{"amount" => 2500, "charge_date" => "2017-12-01"},
      %{"amount" => 2500, "charge_date" => "2018-01-02"},
      %{"amount" => 2500, "charge_date" => "2018-02-01"},
      %{"amount" => 2500, "charge_date" => "2018-03-01"},
      %{"amount" => 2500, "charge_date" => "2018-04-03"}]}}}

list_subscriptions(map)

@callback list_subscriptions(map()) :: tuple()

Lists Subscriptions from GoCardless

Examples

iex> Gocardlex.Client.list_subscriptions
{:ok,
 %{"meta" => %{"cursors" => %{"after" => nil, "before" => nil}, "limit" => 50},
   "subscriptions" => [%{"amount" => 2500,
      "created_at" => "2017-06-26T11:03:27.037Z", "currency" => "GBP",
      "day_of_month" => 1, "end_date" => nil, "id" => "SB000999999998",
      "interval" => 1, "interval_unit" => "monthly",
      "links" => %{"mandate" => "MD000999999998"},
      "metadata" => %{"order_no" => "ABCD1234"}, "month" => nil,
      "name" => "Monthly Magazine", "payment_reference" => nil,
      "start_date" => "2017-07-03", "status" => "active",
      "upcoming_payments" => [%{"amount" => 2500,
         "charge_date" => "2017-07-03"},
       %{"amount" => 2500, "charge_date" => "2017-08-01"},
       %{"amount" => 2500, "charge_date" => "2017-09-01"},
       %{"amount" => 2500, "charge_date" => "2017-10-02"},
       %{"amount" => 2500, "charge_date" => "2017-11-01"},
       %{"amount" => 2500, "charge_date" => "2017-12-01"},
       %{"amount" => 2500, "charge_date" => "2018-01-02"},
       %{"amount" => 2500, "charge_date" => "2018-02-01"},
       %{"amount" => 2500, "charge_date" => "2018-03-01"},
       %{"amount" => 2500, "charge_date" => "2018-04-03"}]}]}}

update_subscription(t, map)

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

Updates a Subscription in GoCardless.

Examples

iex> params = %{
  subscriptions: %{
    name: "Updated Name"
  }
}
iex> Gocardlex.Client.update_subscription("SB000999999998", params)
{:ok,
 %{"subscriptions" => %{"amount" => 2500,
     "created_at" => "2017-06-26T11:03:27.037Z", "currency" => "GBP",
     "day_of_month" => 1, "end_date" => nil, "id" => "SB000999999998",
     "interval" => 1, "interval_unit" => "monthly",
     "links" => %{"mandate" => "MD000999999998"},
     "metadata" => %{"order_no" => "ABCD1234"}, "month" => nil,
     "name" => "Updated Name", "payment_reference" => nil,
     "start_date" => "2017-07-03", "status" => "active",
     "upcoming_payments" => [%{"amount" => 2500, "charge_date" => "2017-07-03"},
      %{"amount" => 2500, "charge_date" => "2017-08-01"},
      %{"amount" => 2500, "charge_date" => "2017-09-01"},
      %{"amount" => 2500, "charge_date" => "2017-10-02"},
      %{"amount" => 2500, "charge_date" => "2017-11-01"},
      %{"amount" => 2500, "charge_date" => "2017-12-01"},
      %{"amount" => 2500, "charge_date" => "2018-01-02"},
      %{"amount" => 2500, "charge_date" => "2018-02-01"},
      %{"amount" => 2500, "charge_date" => "2018-03-01"},
      %{"amount" => 2500, "charge_date" => "2018-04-03"}]}}}