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..35670463 100644 --- a/lib/stripe/cards.ex +++ b/lib/stripe/cards.ex @@ -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 diff --git a/test/stripe/card_test.exs b/test/stripe/card_test.exs index df861e6b..1e2fbc1e 100644 --- a/test/stripe/card_test.exs +++ b/test/stripe/card_test.exs @@ -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