Description
i struggled with the wording for the title because the issue is not that the code will not handle a card object being passed to post_customer()
, but rather that there is no way for that to actually happen, unless i am misunderstanding something. post_customer()
can be called either to create or update a customer, and in either of those cases you cannot get a card object unless it is already attached to that customer.
in order to have a card object in hand, you must have called one of post_card()
, get_card()
, get_cards()
, etc. all of these methods require that you have an existing customer with an id.
-
if you have an existing customer with an id, you obviously cannot be calling
post_customer()
in create mode. -
in order to retrieve a card from an existing customer, that card must already be attached to that customer, meaning that it is a no-op to retrieve that card only to re-post it to the same customer. i have confirmed this via the below, then comparing the JSON returned from
get_customer()
and the secondpost_customer()
.~$ perl -Mstrict -Mwarnings -mNet::Stripe -e 'my $stripe = Net::Stripe->new(api_key => $ENV{STRIPE_API_KEY}, debug=> 1, debug_network=> 1); my $fake_card = { number=> "4242-4242-4242-4242", exp_month=> 12, exp_year=> 2030, cvc=> 123 }; my $customer = $stripe->post_customer(); my $card = $stripe->post_card( customer=> $customer->id, card=> $fake_card ); $stripe->get_customer( customer_id=> $customer->id ); $stripe->post_customer( customer=> $customer->id, card=> $card->id );'
-
attempting to attach a card which was retrieved from a different customer generates an API error, which i read to mean "you can only pass a token id during customer creation".
~$ perl -Mstrict -Mwarnings -mNet::Stripe -e 'my $stripe = Net::Stripe->new(api_key => $ENV{STRIPE_API_KEY}); my $fake_card = { number=> "4242-4242-4242-4242", exp_month=> 12, exp_year=> 2030, cvc=> 123 }; my $customer = $stripe->post_customer(); my $card = $stripe->post_card( customer => $customer->id, card => $fake_card ); $stripe->post_customer( card=> $card->id );' Error: invalid_request_error - No such token: card_1Fzin2Argp8DNlGofNYpk3QD On parameter: card Card error: resource_missing