【问题标题】:How do I retrieve Stripe Session ID for a connected account?如何检索已连接帐户的 Stripe 会话 ID?
【发布时间】:2021-04-09 21:45:50
【问题描述】:

我正在使用 Stripe 结帐。我创建会话并处理费用。成功后,我有会话 ID。我想检索已连接帐户的会话对象。 (这适用于向我的标准帐户收费,但在检索已连接帐户的会话时失败)。

供参考,这里是收费前创建会话的PHP代码:

     \Stripe\Stripe::setApiKey($Skey);
     $session = \Stripe\Checkout\Session::create([
       'customer_email' => $Email,
       'payment_method_types' => ['card'],
       'line_items' => $itms,
       'payment_intent_data' => [
          'description' => $Web_Short_Name . '*' .$Transaction_ID,
          'application_fee_amount' => $Fee,
          'metadata' => ['Transaction_ID' => $Transaction_ID],
       ],

       'success_url' => 'https://[myweb]/success.php?session_id={CHECKOUT_SESSION_ID}',
       'cancel_url' => 'https://[myweb]/cart.php',
     ],
     ['stripe_account' => $Stripe_Account] );
     }

第一次尝试:

$s = $_GET['session_id'];
$stripe = new \Stripe\StripeClient(
  ['api_key' => '[my secret key'],
  ['stripe_account' => '[connected account]']
);
$s2=$stripe->checkout->sessions->retrieve($s,[]); 

第二次尝试:

$s = $_GET['session_id'];
\Stripe\Stripe::setApiKey('[my secret key]');
$stripe = new \Stripe\StripeClient(
 '[my secret key]'
);
$s2=$stripe->checkout->sessions->retrieve($s,[]);

提前致谢! 鲍勃 (我多年来一直使用 StackOverflow 作为资源......但这是我的第一篇文章)。

【问题讨论】:

  • 标准和关联帐户是您在 Stripe 中拥有的产品?您能否发送有关该错误的更多信息?

标签: stripe-payments


【解决方案1】:

对于已连接的帐户,您可以填写检索函数的第二个参数,就像您在创建会话时所做的那样:

     \Stripe\Stripe::setApiKey('<your API key>');
     $session = \Stripe\Checkout\Session::retrieve('<the session id>', [
         'stripe_account' => '<the id of the connected Stripe account>'
     ]);

【讨论】:

    【解决方案2】:

    得到了我工作所需的东西。基本上,当我从 Stripe 接到对我的 webhook 的调用时,我正在寻找 PaymentIntent 对象。

    来自我的结帐 webhook 的片段:

    <?
    require __DIR__ . '/vendor/autoload.php';
    $payload = @file_get_contents('php://input');
    $event = null;
    try {
        $event = \Stripe\Event::constructFrom(
            json_decode($payload, true)
        );
    } catch(\UnexpectedValueException $e) {
        // Invalid payload
        http_response_code(400);
        exit();
    }
    
    
    // Handle the event
    \Stripe\Stripe::setApiKey({YOUR_SECRET_KEY});
    
    $session_id = $event->data->object->id;
    
    switch ($event->type) {
        case 'checkout.session.completed':
            $checkout = $event->data->object; // contains a \Stripe\PaymentIntent
            // Then define and call a method to handle the successful payment intent.
             //handleCheckoutSucceeded($checkout);
             handleCheckout($db,$Transaction_ID,$session_id,'SUCCEEDED');
    ?>
    

    【讨论】:

      猜你喜欢
      • 2021-05-21
      • 2021-12-24
      • 2020-07-18
      • 2020-12-02
      • 1970-01-01
      • 2018-10-12
      • 1970-01-01
      • 2019-04-29
      • 1970-01-01
      相关资源
      最近更新 更多