条带错误:您不能多次使用条带标记

时间:2017-05-31 00:00:00

标签: php stripe-payments

使用Stripe创建充电时,我一直收到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;
		$response["error_msg"] = "Error processing payment - Rate Limit.";
		echo json_encode($response);
} catch (\Stripe\Error\InvalidRequest $e) {
	 $response["error"] = TRUE;
		$response["error_msg"] = "Error processing payment - Invalid request.";
		echo json_encode($response);
} catch (\Stripe\Error\Authentication $e) {
  $response["error"] = TRUE;
		$response["error_msg"] = "Error processing payment - Authentication.";
		echo json_encode($response);
} catch (\Stripe\Error\ApiConnection $e) {
  $response["error"] = TRUE;
		$response["error_msg"] = "Error processing payment - API Connection.";
		echo json_encode($response);
} catch (\Stripe\Error\Base $e) {
  $response["error"] = TRUE;
		$response["error_msg"] = "Error processing payment - Base.";
		echo json_encode($response);
} catch (Exception $e) {
  $response["error"] = TRUE;
		$response["error_msg"] = "Error processing payment - Exception.";
		echo json_encode($response);
}

?>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

最可能的原因是令牌被客户端代码多次发布 - 要么是因为客户点击了多次,要么是因为代码导致数据被多次提交。 / p>

答案 1 :(得分:0)

您正在使用令牌两次。一次充电,另一次创建客户。您不必使用令牌来创建客户。

    $customer = \Stripe\Customer::create(array(
  "email" => $email,
  // "source" => $token, //remove
));