如何获取已连接帐户的Stripe Session ID?

问题描述

我正在使用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调用Webhook时,我正在寻找PaymentIntent对象。

我的结帐网络摘录中的摘录:

<?
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');
?>
,

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

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