Php 条带-使用手动确认的相同支付意图

Php 条带-使用手动确认的相同支付意图,php,stripe-payments,Php,Stripe Payments,我正在尝试将我的支付流从费用API迁移到支付意图 条带迁移文档在步骤2中指出,您需要在服务器上创建支付意图 如果付款失败,用户尝试另一次付款,那么我将为同一订单创建多个付款意向 如果我在知道金额后立即创建了付款意向,然后使用手动确认方法将该订单的付款意向存储在数据库表中,是否有办法重用相同的付款意向 比如说: // create intent $intent = \Stripe\PaymentIntent::create([ 'amount' => 1099, 'curre

我正在尝试将我的支付流从费用API迁移到支付意图

条带迁移文档在步骤2中指出,您需要在服务器上创建支付意图

如果付款失败,用户尝试另一次付款,那么我将为同一订单创建多个付款意向

如果我在知道金额后立即创建了付款意向,然后使用手动确认方法将该订单的付款意向存储在数据库表中,是否有办法重用相同的付款意向

比如说:

 // create intent
 $intent = \Stripe\PaymentIntent::create([
   'amount' => 1099,
   'currency' => 'usd',
   'confirmation_method' => 'manual',
 ],[
   'idempotency_key' => $orderId,
 ]);

 // Update orders table with payment intent id and set order status to unpaid
然后,当用户付款时:

 # vendor using composer
 require_once('vendor/autoload.php');

 \Stripe\Stripe::setApiKey(getenv('STRIPE_SECRET_KEY'));

 header('Content-Type: application/json');

 # retrieve json from POST body
 $json_str = file_get_contents('php://input');
 $json_obj = json_decode($json_str);

 #$intent = null;
 $order = // get from database
 $intent = \Stripe\PaymentIntent::retrieve($order->payment_intent_id);

 try {
   if (isset($json_obj->payment_method_id)) {

      # Create the PaymentIntent
      #$intent = \Stripe\PaymentIntent::create([
      #   'payment_method' => $json_obj->payment_method_id,
      #   'amount' => 1099,
      #   'currency' => 'usd',
      #   'confirmation_method' => 'manual',
      #   'confirm' => true,
      #]);

     # Instead of creating a new payment intent we update the previously saved PaymentIntent
     \Stripe\PaymentIntent::update($intent->id,
       [
         'payment_method' => $json_obj->payment_method_id,
         'confirm' => true,
       ]
     );
  }
  if (isset($json_obj->payment_intent_id)) {
     $intent = \Stripe\PaymentIntent::retrieve(
        $json_obj->payment_intent_id
     );
     $intent->confirm();
   }
   generatePaymentResponse($intent);
} catch (\Stripe\Error\Base $e) {
  # Display error on client
   echo json_encode([
      'error' => $e->getMessage()
   ]);
}

function generatePaymentResponse($intent) {
   # Note that if your API version is before 2019-02-11, 'requires_action'
   # appears as 'requires_source_action'.
   if ($intent->status == 'requires_action' &&
       $intent->next_action->type == 'use_stripe_sdk') {
        # Tell the client to handle the action
       echo json_encode([
         'requires_action' => true,
         'payment_intent_client_secret' => $intent->client_secret
      ]);
   } else if ($intent->status == 'succeeded') {
       # The payment didn’t need any additional actions and completed!
       # Handle post-payment fulfillment
       echo json_encode([
          "success" => true
      ]);
   } else {
      # Invalid status
      http_response_code(500);
      echo json_encode(['error' => 'Invalid PaymentIntent status']);
   }
 }

任何提示和建议都将不胜感激。

您创建的付款意图是短暂的。它返回阶段2(在某些情况下)所需的秘密。你为什么不想创建另一个意图?你创建的支付意图是短暂的。它返回阶段2(在某些情况下)所需的秘密。你为什么不想创造另一个意图?