Skip to content

post_charge() fails on card object or card hashref #137

Closed
@sherrardb

Description

@sherrardb

in retrospect, i should have discovered this while working on #94, since a similar pattern applies. ie we were missing test that confirmed correct handling of the parameter types we claim to accept and we need to massage the parameter as appropriate before passing along.

passing a card object

sburton@d01:/srv/git/Net-Stripe$ 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,
  name=> "Anonymous",
  metadata=> { "somecardmetadata"=> "testing, testing, 1-2-3", },
  address_line1=> "123 Main Street",
  address_city=> "Anytown",
  address_state=> "Anystate",
  address_zip=> "55555",
  address_country=> "United States"
};
my $customer = $stripe->post_customer();
my $card = $stripe->post_card( customer=> $customer, card=> $fake_card );
$stripe->post_charge(
  amount=> 250,
  currency=> "usd",
  customer=> $customer->id,
  card=> $card
);'
Error: invalid_request_error - Invalid string: {:metadata=>{:somecardmetadata=>"testing, testing, 1-2-3"}, :name=>"Anonymous", :address_line1=>"123 Main Street", :address_zip=>"55555", :address_city=>"Anytown", :address_state=>"Anystate", :address_country=>"United States", :exp_month=>"12", :exp_year=>"2030", :object=>"card"} On parameter: card

passing a card hashref

~$ 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,
  name=> "Anonymous",
  metadata=> { "somecardmetadata"=> "testing, testing, 1-2-3" },
  address_line1=> "123 Main Street",
  address_city=> "Anytown",
  address_state=> "Anystate",
  address_zip=> "55555",
  address_country=> "United States"
};
my $customer = $stripe->post_customer();
$stripe->post_charge(
  amount=> 250,
  currency=> "usd",
  customer=> $customer->id,
  card=> $fake_card
);'
Error: invalid_request_error - Invalid string: {:metadata=>{:somecardmetadata=>"testing, testing, 1-2-3"}, :number=>"4242-42**-****-4242", :cvc=>"***", :name=>"Anonymous", :address_line1=>"123 Main Street", :address_zip=>"55555", :address_city=>"Anytown", :address_state=>"Anystate", :address_country=>"United States", :exp_month=>"12", :exp_year=>"2030", :object=>"card"} On parameter: card

the docs indicate that this field should be an ID

A payment source to be charged. This can be the ID of a card (i.e., credit or debit card), a bank account, a source, a token, or a connected account.

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