Skip to content

card object and card id not legitimate arguments to post_customer() and post_card() #138

Closed
@sherrardb

Description

@sherrardb

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.

  1. if you have an existing customer with an id, you obviously cannot be calling post_customer() in create mode.

  2. 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 second post_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 );'
    
  3. 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
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions