Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sherrardb opened this issue Jan 11, 2020 · 2 comments · Fixed by #153
Closed

Comments

@sherrardb
Copy link
Collaborator

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
    
@sherrardb
Copy link
Collaborator Author

sherrardb commented Jan 11, 2020

and, even if you do create a card on a different customer in order to pass a card object to post_customer(), it fails outright.

creating a customer:

~$ 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 );'
Error: invalid_request_error - Could not find payment information
Card error: missing_payment_information

updating a customer:

~$ 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( customer=> $customer->id, card=> $card );'
Error: invalid_request_error - Could not find payment information
Card error: missing_payment_information

updating the card attribute of the customer object and re-posting that object:

~$ 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 );
$customer->card( $card );
$stripe->post_customer( customer=> $customer );'
Error: invalid_request_error - Could not find payment information
Card error: missing_payment_information

this is because the card object does not serialize into a useful form. the API expects the id of an object "created via the Token or Sources APIs" :

Sending to Stripe:
------
POST https://api.stripe.com/v1/customers
Authorization: Basic *******
Content-Length: 311
Content-Type: application/x-www-form-urlencoded
Stripe-Version: 2015-02-16

card%5Bmetadata%5D%5Bsomecardmetadata%5D=testing%2C+testing%2C+1-2-3&card%5Bname%5D=Anonymous&card%5Baddress_line1%5D=123+Main+Street&card%5Baddress_zip%5D=55555&card%5Baddress_city%5D=Anytown&card%5Baddress_state%5D=Anystate&card%5Baddress_country%5D=United+States&card%5Bexp_month%5D=1&card%5Bexp_year%5D=2021

@sherrardb sherrardb changed the title card object and card id not legitimate arguments to post_customer() card object and card id not legitimate arguments to post_customer() and post_card() Jan 20, 2020
@sherrardb
Copy link
Collaborator Author

similar reasoning applies to post_card(). ie you cannot be creating a card if you already have a card object, and if you are updating a card, you cannot do so by updating the attributes of the existing card object.

sherrardb added a commit to sherrardb/stripe-perl that referenced this issue Jan 22, 2020
 * remove invalid argument types from post_card(), per <lukec#138>
 * remove dead code paths from post_card() and make conditional structure more explicit, per discussion in <lukec#133>
 * add unit tests for all calling forms, per <lukec#139>
 * update the POD
sherrardb added a commit to sherrardb/stripe-perl that referenced this issue Jan 22, 2020
 * updated Kavorka signature to remove non-functional or illegitimate argument types
 * removed Net::Stripe::Card and disallowed card id for card, as neither form is valid conceptually <lukec#138>
 * always create a Net::Stripe::Customer object before _post() to take advantage of argument coercion during objectification <lukec#148>
 * include omitted arguments in object creation
 * clean up and centralize Net::Stripe:Token coercion code, since we always need the token id
 * added unit tests to exercise all allowed argument forms for customer creation and customer update <lukec#139>
 * closes <lukec#138>
sherrardb added a commit that referenced this issue Jan 26, 2020
 * updated Kavorka signature to remove non-functional or illegitimate argument types
 * removed Net::Stripe::Card and disallowed card id for card, as neither form is valid conceptually <#138>
 * always create a Net::Stripe::Customer object before _post() to take advantage of argument coercion during objectification <#148>
 * include omitted arguments in object creation
 * clean up and centralize Net::Stripe:Token coercion code, since we always need the token id
 * added unit tests to exercise all allowed argument forms for customer creation and customer update <#139>
 * closes <#138>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant