Stripe Charge卡php文件总是返回200

时间:2016-05-27 15:57:25

标签: php stripe-payments

我用PHP实现条带化。 我的PHP如下:

    <?php
require_once('vendor/autoload.php');
// See your keys here https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey($_POST['stripeAPIKey']);
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$amount = $_POST['amount'];
$currency = "eur";
$description = $_POST['description'];
$email = $_POST['email'];
$statement = $_POST['statement'];
echo $token;

//THIS IS THE SIMPLE LOGIC FOR CHARGING ONCE
try {
 $charge = \Stripe\Charge::create(array(
 "amount" => $amount, // Convert amount in cents to dollar
 "currency" => $currency,
 "source" => $token,
 "receipt_email" => $email,
 "statement_descriptor" => $statement,
 "description" => $description)
 );

}  catch (\Stripe\Error\Card $e) {// Card was declined.
    $body= $e->getJsonBody();
    $err = $body['error'];
    $response = array( 'status'=> $e->getHttpStatus(), 'type' => $err['type'],'code'=> $err['code'],'param'=> $err['param'],'message'=> $err['message']);
    header('Content-Type: application/json');
    exit(json_encode($response));
}
?>

但即使发生错误,它也总是返回200(OK)。它有什么问题?

我的客户端在iOS Swift / Alamofire上运行。

0 个答案:

没有答案