Skip to content

Commit

Permalink
Merge pull request #20 from williamhogman/master
Browse files Browse the repository at this point in the history
Add method for changing payment source for subscriptions
  • Loading branch information
robconery committed Dec 22, 2015
2 parents a799895 + 70950a6 commit 4c738a3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/stripe/subscriptions.ex
Expand Up @@ -184,6 +184,21 @@ defmodule Stripe.Subscriptions do
end
end

@doc """
Changes the payment source for a subscription.
#Example
```
source = [object: "card", number: "4111111111111111", exp_month: 01, exp_year: 2018, cvc: 123]
Stripe.Subscriptions.change_payment_source("customer_id", "subscription_id", source)
```
"""
def change_payment_source(customer_id, sub_id, source) do
data = [source: source]
Stripe.make_request(:post, "#{@endpoint}/#{customer_id}/subscriptions/#{sub_id}", data)
|> Stripe.Util.handle_stripe_response
end

@max_fetch_size 100
@doc """
List all subscriptions.
Expand Down
14 changes: 14 additions & 0 deletions test/stripe/subscription_test.exs
Expand Up @@ -141,6 +141,20 @@ defmodule Stripe.SubscriptionTest do
end
end

@tag disable: false
test "Change creditcards works", %{customer: c, sub2: sub2} do
source = [
object: "card",
number: "4012888888881881",
exp_year: "20",
exp_month: "12",
]
case Stripe.Subscriptions.change_payment_source(c.id, sub2.id, source) do
{:ok, res} ->
assert res[:status] == "active"
{:error, err} -> flunk err
end
end
@tag disabled: false
test "Cancel all works", %{customer: customer, sub1: _, sub2: _} do
Stripe.Subscriptions.cancel_all customer.id, []
Expand Down

0 comments on commit 4c738a3

Please sign in to comment.