I am trying to set up a Perl script that will process credit card charges through Stripe using Net::Stripe
.
I am able to successfully request a token, but when I use that token to post the charge, I get this error:
Error: invalid_request_error - Invalid string: {"exp_month"=>"12", "exp_year"=>"2021", "object"=>"card"} at Stripe.pm line 637
Here is my code
$API_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
my $stripe = Net::Stripe->new(
api_key => $API_KEY,
debug => '1',
debug_network => '1'
);
my $card_token = $stripe->post_token(
card => {
number => $FORM{'Credit Card #'},
exp_month => $FORM{'Expiration Month'},
exp_year => $FORM{'Expiration Year'},
cvc => $FORM{'Credit Card Security Code'}
}
);
print Dumper( $card_token );
try {
my $charge = $stripe->post_charge(
amount => $amount_of_charge_in_cents,
currency => 'usd',
card => $card_token,
description => 'ABC Charge',
customer => $FORM{'Name'}
);
}
catch {
warn "caught error: $_"; # not $@
}
Should I be using something other than $card_token
as the card value?
tok_xxx
). – korben