Skip to content

Commit

Permalink
Merge pull request #66 from gmile/fix-for-issue-63
Browse files Browse the repository at this point in the history
Use POST in cards/update API method
  • Loading branch information
robconery authored Aug 7, 2016
2 parents d48c688 + c62ae80 commit 00906f9
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
70 changes: 70 additions & 0 deletions fixture/vcr_cassettes/card_test/update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[
{
"request": {
"body": "source[object]=card&source[number]=4111111111111111&source[cvc]=123&source[exp_month]=12&source[exp_year]=2020",
"headers": {
"Authorization": "Bearer non_empty_secret_key_string",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Stripe/v1 stripity-stripe/1.4.0"
},
"method": "post",
"options": [],
"request_body": "",
"url": "https://api.stripe.com/v1/customers/cus_8r2j7zRowtrski/sources"
},
"response": {
"body": "{\n \"id\": \"card_8wdRRGS43PIzGs\",\n \"object\": \"card\",\n \"address_city\": null,\n \"address_country\": null,\n \"address_line1\": null,\n \"address_line1_check\": null,\n \"address_line2\": null,\n \"address_state\": null,\n \"address_zip\": null,\n \"address_zip_check\": null,\n \"brand\": \"Visa\",\n \"country\": \"US\",\n \"customer\": \"cus_8wdRiJUcG4EOci\",\n \"cvc_check\": \"pass\",\n \"dynamic_last4\": null,\n \"exp_month\": 12,\n \"exp_year\": 2020,\n \"fingerprint\": \"Ze2h9CyiqlKZzGuV\",\n \"funding\": \"unknown\",\n \"last4\": \"1111\",\n \"metadata\": {},\n \"name\": null,\n \"tokenization_method\": null\n}\n",
"headers": {
"Server": "nginx",
"Date": "Thu, 04 Aug 2016 11:38:04 GMT",
"Content-Type": "application/json",
"Content-Length": "569",
"Connection": "keep-alive",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Methods": "GET, POST, HEAD, OPTIONS, DELETE",
"Access-Control-Allow-Origin": "*",
"Access-Control-Max-Age": "300",
"Cache-Control": "no-cache, no-store",
"Request-Id": "req_8wdRp5na0zbVAg",
"Stripe-Version": "2016-07-06",
"Strict-Transport-Security": "max-age=31556926; includeSubDomains"
},
"status_code": 200,
"type": "ok"
}
},
{
"request": {
"body": "exp_month=11",
"headers": {
"Authorization": "Bearer non_empty_secret_key_string",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Stripe/v1 stripity-stripe/1.4.0"
},
"method": "post",
"options": [],
"request_body": "",
"url": "https://api.stripe.com/v1/customers/cus_8r2j7zRowtrski/sources/card_8wdRRGS43PIzGs"
},
"response": {
"body": "{\n \"id\": \"card_8wdRRGS43PIzGs\",\n \"object\": \"card\",\n \"address_city\": null,\n \"address_country\": null,\n \"address_line1\": null,\n \"address_line1_check\": null,\n \"address_line2\": null,\n \"address_state\": null,\n \"address_zip\": null,\n \"address_zip_check\": null,\n \"brand\": \"Visa\",\n \"country\": \"US\",\n \"customer\": \"cus_8wdRiJUcG4EOci\",\n \"cvc_check\": \"pass\",\n \"dynamic_last4\": null,\n \"exp_month\": 11,\n \"exp_year\": 2020,\n \"fingerprint\": \"Ze2h9CyiqlKZzGuV\",\n \"funding\": \"unknown\",\n \"last4\": \"1111\",\n \"metadata\": {},\n \"name\": null,\n \"tokenization_method\": null\n}\n",
"headers": {
"Server": "nginx",
"Date": "Thu, 04 Aug 2016 11:38:04 GMT",
"Content-Type": "application/json",
"Content-Length": "569",
"Connection": "keep-alive",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Methods": "GET, POST, HEAD, OPTIONS, DELETE",
"Access-Control-Allow-Origin": "*",
"Access-Control-Max-Age": "300",
"Cache-Control": "no-cache, no-store",
"Request-Id": "req_8wdRLhCminnDBF",
"Stripe-Version": "2016-07-06",
"Strict-Transport-Security": "max-age=31556926; includeSubDomains"
},
"status_code": 200,
"type": "ok"
}
}
]
5 changes: 4 additions & 1 deletion lib/stripe/cards.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ defmodule Stripe.Cards do
|> Stripe.Util.handle_stripe_response
end

def update(owner_type, owner_id, id, params) do
update(owner_type, owner_id, id, params, Stripe.config_or_env_key)
end

def update(owner_type, owner_id, id, params, key) do
Stripe.make_request_with_key(:put, "#{endpoint_for_entity(owner_type, owner_id)}/#{id}", key, params)
Stripe.make_request_with_key(:post, "#{endpoint_for_entity(owner_type, owner_id)}/#{id}", key, params)
|> Stripe.Util.handle_stripe_response
end

Expand Down
44 changes: 44 additions & 0 deletions test/stripe/card_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,48 @@ defmodule Stripe.CardTest do
end
end
end

@tag disabled: false
test "Update with key works", %{customer: customer} do
use_cassette "card_test/update", match_requests_on: [:query, :request_body] do
new_card = [
source: [
object: "card",
number: "4111111111111111",
cvc: 123,
exp_month: 12,
exp_year: 2020
]
]

{ :ok, card } = Stripe.Cards.create :customer, customer.id, new_card

case Stripe.Cards.update(:customer, customer.id, card.id, [exp_month: 11], Stripe.config_or_env_key) do
{:ok, res} -> assert res.exp_month == 11
{:error, err} -> flunk err
end
end
end

@tag disabled: false
test "Update works", %{customer: customer} do
use_cassette "card_test/update", match_requests_on: [:query, :request_body] do
new_card = [
source: [
object: "card",
number: "4111111111111111",
cvc: 123,
exp_month: 12,
exp_year: 2020
]
]

{ :ok, card } = Stripe.Cards.create :customer, customer.id, new_card

case Stripe.Cards.update(:customer, customer.id, card.id, [exp_month: 11], Stripe.config_or_env_key) do
{:ok, res} -> assert res.exp_month == 11
{:error, err} -> flunk err
end
end
end
end

0 comments on commit 00906f9

Please sign in to comment.