【发布时间】:2016-11-10 14:44:13
【问题描述】:
我遇到了 Stripe 的问题,它会很高兴地创建令牌并将其发送到我的 php 收费脚本,此时在 Stripe 控制面板上创建了一个 200 OK - Token 日志。它只是不会对卡收费,据我所知,我已经正确完成了所有操作,在 php 或 Stripe API 中我没有收到任何错误。
error_reporting(E_ALL);
ini_set('display_errors', 1);
$error = 0;
require_once('stripe-php-master/init.php');
$trialAPIKey = "sk_test_???"; // These are the SECRET keys!
$liveAPIKey = "sk_live_???";
\Stripe\Stripe::$apiBase = "https://api-tls12.stripe.com";
// Switch to change between live and test environments
\Stripe\Stripe::setApiKey($trialAPIKey);
/* \Stripe\Stripe::setApiKey($liveAPIKey); */
$token = $_POST['token'];
$price = $_POST['amount'];
$price = $price * 100;
$desc = $_POST['desc'];
try {
$charge = \Stripe\Charge::create(array(
"amount" => $price,
"currency" => "gbp",
"source" => $token,
"description" => $desc
));
} catch(\Stripe\Error\Card $e) {
// The card has been declined
$error++;
}
if($error>=1) {
echo "There was an error processing your card, please try again.";
} else {
echo "Thank you, your payment was successful.";
}
【问题讨论】:
标签: php stripe-payments