我正在尝试设置一个Perl脚本,该脚本将使用Net::Stripe
通过 Stripe 处理信用卡费用。
我能够成功请求令牌,但当我使用该令牌发布费用时,我收到此错误:
错误:invalid_request_error - 无效字符串:{“exp_month”=>“12”,“exp_year”=>“2021”,“object”=>“卡片”}在Stripe.pm第637行
这是我的代码
$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 $@
}
我应该使用$card_token
以外的其他内容作为卡片值吗?
答案 0 :(得分:0)
Stripe API调用Create a card token的文档(由post_token
包装)表示以下字段 required
exp_month
exp_year
number
currency
cvc
但是你只提供其中的四个
答案 1 :(得分:0)
感谢korben我只使用返回的令牌ID成功修改了我的代码:
$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'},
name => $FORM{'Name on Card'},
}
);
print Dumper($card_token);
$token_id = $card_token->{id};
try {
my $charge = $stripe->post_charge(
amount => $amount_of_charge_in_cents,
currency => 'usd',
card => $token_id,
description => 'ABC Charge'
);
} catch {
warn "caught error: $_"; # not $@
}
我还删除了“customer”值,因为这是现有客户的ID,并在卡令牌代码中添加了“name”。