ストライプでチャージを作成しているうちに400エラーが発生し続けます。奇妙なことは時々それはうまくいくが、ほとんどの場合、それはまったく動作しないということです。支払いは毎回行われます。エラーに関係なく。このPHPスクリプトは支払い処理に適していますか?ストライプエラー:ストライプトークンを複数回使用することはできません
注:私がチェックしたことは、私が請求を作成するたびに、トークンは最後のトークンから一意であることです。
<?php
require_once('stripe.php');
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("key");
$token = $_POST['stripeToken'];
$email = $_POST['email'];
// Create the charge on Stripe's servers - this will charge the user's card
try {
// Create a Customer:
$customer = \Stripe\Customer::create(array(
"email" => $email,
"source" => $token,
));
// Charge the Customer instead of the card:
$charge = \Stripe\Charge::create(array(
"amount" => 1000,
"currency" => "usd",
"customer" => $customer->id
));
} catch(\Stripe\Error\Card $e) {
// Since it's a decline, \Stripe\Error\Card will be caught
$body = $e->getJsonBody();
$err = $body['error'];
print('Status is:' . $e->getHttpStatus() . "\n");
print('Type is:' . $err['type'] . "\n");
print('Code is:' . $err['code'] . "\n");
// param is '' in this case
print('Param is:' . $err['param'] . "\n");
print('Message is:' . $err['message'] . "\n");
} catch (\Stripe\Error\RateLimit $e) {
$response["error"] = TRUE;
\t \t $response["error_msg"] = "Error processing payment - Rate Limit.";
\t \t echo json_encode($response);
} catch (\Stripe\Error\InvalidRequest $e) {
\t $response["error"] = TRUE;
\t \t $response["error_msg"] = "Error processing payment - Invalid request.";
\t \t echo json_encode($response);
} catch (\Stripe\Error\Authentication $e) {
$response["error"] = TRUE;
\t \t $response["error_msg"] = "Error processing payment - Authentication.";
\t \t echo json_encode($response);
} catch (\Stripe\Error\ApiConnection $e) {
$response["error"] = TRUE;
\t \t $response["error_msg"] = "Error processing payment - API Connection.";
\t \t echo json_encode($response);
} catch (\Stripe\Error\Base $e) {
$response["error"] = TRUE;
\t \t $response["error_msg"] = "Error processing payment - Base.";
\t \t echo json_encode($response);
} catch (Exception $e) {
$response["error"] = TRUE;
\t \t $response["error_msg"] = "Error processing payment - Exception.";
\t \t echo json_encode($response);
}
?>