From d87d592dc33d95493c1f0e3b6411557c2c10b41d Mon Sep 17 00:00:00 2001 From: Eugene Pirogov Date: Thu, 4 Aug 2016 14:46:32 +0300 Subject: [PATCH 1/2] Use POST in cards/update API method --- fixture/vcr_cassettes/card_test/update.json | 70 +++++++++++++++++++++ lib/stripe/cards.ex | 2 +- test/stripe/card_test.exs | 22 +++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 fixture/vcr_cassettes/card_test/update.json diff --git a/fixture/vcr_cassettes/card_test/update.json b/fixture/vcr_cassettes/card_test/update.json new file mode 100644 index 00000000..ba28bc8c --- /dev/null +++ b/fixture/vcr_cassettes/card_test/update.json @@ -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" + } + } +] diff --git a/lib/stripe/cards.ex b/lib/stripe/cards.ex index 21c5a6ce..7be9a911 100644 --- a/lib/stripe/cards.ex +++ b/lib/stripe/cards.ex @@ -79,7 +79,7 @@ defmodule Stripe.Cards do 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 diff --git a/test/stripe/card_test.exs b/test/stripe/card_test.exs index f79d1a9e..9fcbfc7e 100644 --- a/test/stripe/card_test.exs +++ b/test/stripe/card_test.exs @@ -214,4 +214,26 @@ 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 end From c62ae800079f89ee68eed41af321761ab483e578 Mon Sep 17 00:00:00 2001 From: Eugene Pirogov Date: Fri, 5 Aug 2016 11:16:32 +0300 Subject: [PATCH 2/2] Add Stripe.Cards.update/4 --- lib/stripe/cards.ex | 3 +++ test/stripe/card_test.exs | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/stripe/cards.ex b/lib/stripe/cards.ex index 7be9a911..35670463 100644 --- a/lib/stripe/cards.ex +++ b/lib/stripe/cards.ex @@ -77,6 +77,9 @@ 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(:post, "#{endpoint_for_entity(owner_type, owner_id)}/#{id}", key, params) diff --git a/test/stripe/card_test.exs b/test/stripe/card_test.exs index 9fcbfc7e..6a4e476d 100644 --- a/test/stripe/card_test.exs +++ b/test/stripe/card_test.exs @@ -236,4 +236,26 @@ defmodule Stripe.CardTest do 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