条纹,使用幂等键的多个请求返回错误

问题描述 投票:0回答:2

需要条纹错误响应援助。一切似乎都按照创建时的客户,然后他们招收到认购,因此产生的费用,在那里与到位幂等按键进行多个请求的情况下,以条纹仪表盘日志工作。如何过其中一个页面(charge.php)打开运行这些代码,而不是发送成功的页面,在此事件中,我得到这个stripe error response(例外$ error6的捕获)。

charge.php

\Stripe\Stripe::setApiKey('sk_live_xxxxxxxxxxx');

$POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);

$email = $POST['email'];
$token = $POST['stripeToken'];
$membership_type = $POST['membership_type'];
$user_id = $POST['user_id'];
$success = 0;

try {
// Create customer in Stripe
$customer = \Stripe\Customer::create([
  "email" => $email,
  "source" => $token,
],[
  "idempotency_key" => $_SESSION['sid2'],
]);
$success = 1;
} catch(Stripe_CardError $e) {
  $error1 = $e->getMessage();
} catch (Stripe_InvalidRequestError $e) {
  // Invalid parameters were supplied to Stripe's API
  $error2 = $e->getMessage();
} catch (Stripe_AuthenticationError $e) {
  // Authentication with Stripe's API failed
  $error3 = $e->getMessage();
} catch (Stripe_ApiConnectionError $e) {
  // Network communication with Stripe failed
  $error4 = $e->getMessage();
} catch (Stripe_Error $e) {
  // Display a very generic error to the user, and maybe send
  // yourself an email
  $error5 = $e->getMessage();
} catch (Exception $e) {
  // Something else happened, completely unrelated to Stripe
  $error6 = $e->getMessage();
}

if ($success!=1)
{
    $_SESSION['error1'] = $error1;
    $_SESSION['error2'] = $error2;
    $_SESSION['error3'] = $error3;
    $_SESSION['error4'] = $error4;
    $_SESSION['error5'] = $error5;
    $_SESSION['error6'] = $error6;
    print_r($_SESSION);
}

// Add Customer to a Subscription in Stripe
$subscription = \Stripe\Subscription::create([
    'customer' => $customer->id,
    'items' => [['plan' => $membership_type]]
  ],[
    "idempotency_key" => $_SESSION['sid'],
]); 
//adding all relevent info into data base...

//send user to success page
header('Location: ../success.php?id='.$user_id.'&product='.$subscription->plan->nickname);

难道这是因为每次条纹JS $ token参数的变化?这是正常的还是我做错了什么? (我只在一个订阅客户运行时幂等了一个类似的错误,但随后条纹创建多个客户提供相同的电子邮件和支付卡,但不同的客户 - > ID),任何人都可以亲切建议我怎么能解决这个错误页面?

php stripe-payments
2个回答
0
投票

难道这是因为每次条纹JS $ token参数的变化?

是的,我怀疑这里发生了什么是你正在重用$_SESSION['sid2']具有不同source参数创建一个客户两个独立的请求。而这个错误响应是预期的行为!

你应该能够看到这个在你的仪表盘日志:假设这是一个测试模式的要求,https://dashboard.stripe.com/test/logs/iar_IgylJRGpbLyVb6应该告诉你相同的密钥最初使用。


0
投票

我能找到的最好的办法是禁用条纹JS事件侦听器后的按钮

var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
  event.preventDefault();

$('.button').attr("disabled", true);
stripe.createToken(card).then(function(result) {...........
© www.soinside.com 2019 - 2024. All rights reserved.