【问题标题】:Stripe success page trying to get details from session_id条纹成功页面试图从 session_id 获取详细信息
【发布时间】:2022-07-27 13:02:48
【问题描述】:

我正在尝试从 php 中的 Stripe 成功交易中检索详细信息。官方文档告诉我要安装和使用 Slim,在我目前的情况下是做不到的。

到目前为止,我得到了以下代码,它向我抛出了某种报告,但我不完全理解我在看什么,我不确定从这里去哪里,或者即使我'我首先得到了正确的信息!

<?php

error_reporting(E_ALL);
ini_set('display_errors', 'on');

require_once('../../stripe/init.php');

$stripe = new \Stripe\StripeClient(
  '[my test key]'
);
$stripe->checkout->sessions->retrieve(
  $_GET['session_id'],
  []
);
echo "<pre>";
print_r($stripe);
echo "</pre>";

?>

这给了我以下信息:

  Stripe\Service\Checkout\SessionService Object
(
    [client:protected] => Stripe\StripeClient Object
        (
            [coreServiceFactory:Stripe\StripeClient:private] => Stripe\Service\CoreServiceFactory Object
                (
                    [client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object
 *RECURSION*
                    [services:Stripe\Service\AbstractServiceFactory:private] => Array
                        (
                            [checkout] => Stripe\Service\Checkout\CheckoutServiceFactory Object
                                (
                                    [client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object
 *RECURSION*
                                    [services:Stripe\Service\AbstractServiceFactory:private] => Array
                                        (
                                            [sessions] => Stripe\Service\Checkout\SessionService Object
 *RECURSION*
                                        )

                                )

                        )

                )

            [config:Stripe\BaseStripeClient:private] => Array
                (
                    [api_key] => [my_api_key]
                    [client_id] => 
                    [stripe_account] => 
                    [stripe_version] => 
                    [api_base] => https://api.stripe.com
                    [connect_base] => https://connect.stripe.com
                    [files_base] => https://files.stripe.com
                )

            [defaultOpts:Stripe\BaseStripeClient:private] => Stripe\Util\RequestOptions Object
                (
                    [apiKey] => 
                    [headers] => Array
                        (
                            [Stripe-Account] => 
                            [Stripe-Version] => 
                        )

                    [apiBase] => 
                )

        )

    [streamingClient:protected] => Stripe\StripeClient Object
        (
            [coreServiceFactory:Stripe\StripeClient:private] => Stripe\Service\CoreServiceFactory Object
                (
                    [client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object
 *RECURSION*
                    [services:Stripe\Service\AbstractServiceFactory:private] => Array
                        (
                            [checkout] => Stripe\Service\Checkout\CheckoutServiceFactory Object
                                (
                                    [client:Stripe\Service\AbstractServiceFactory:private] => Stripe\StripeClient Object
 *RECURSION*
                                    [services:Stripe\Service\AbstractServiceFactory:private] => Array
                                        (
                                            [sessions] => Stripe\Service\Checkout\SessionService Object
 *RECURSION*
                                        )

                                )

                        )

                )

            [config:Stripe\BaseStripeClient:private] => Array
                (
                    [api_key] => [my_api_key]
                    [client_id] => 
                    [stripe_account] => 
                    [stripe_version] => 
                    [api_base] => https://api.stripe.com
                    [connect_base] => https://connect.stripe.com
                    [files_base] => https://files.stripe.com
                )

            [defaultOpts:Stripe\BaseStripeClient:private] => Stripe\Util\RequestOptions Object
                (
                    [apiKey] => 
                    [headers] => Array
                        (
                            [Stripe-Account] => 
                            [Stripe-Version] => 
                        )

                    [apiBase] => 
                )

        )

)

【问题讨论】:

  • 看看这里,也许? stackoverflow.com/a/70777795/130230
  • 我在发帖之前就看到了,但那不是 node.js 吗?另外,老实说,我什至无法阅读将其翻译成 php。
  • 是的,但是对于 PHP 客户端,Stripe API 应该非常相似..
  • 好的,但我仍然无法将其转换为 php。我得到了基本的想法并尝试了:$stripe-&gt;checkout-&gt;sessions-&gt;retrieve( $_GET['session_id'], ['line-items'] );,但它没有用。
  • 我需要添加 expand 对象名称。也许您需要类似的东西?

标签: php stripe-payments


【解决方案1】:

我是根据我最初拥有的代码计算出来的。这样其他人就不必经历我的挫败感了:

require_once('../../stripe/init.php');

$stripe = new \Stripe\StripeClient(
  '{{my api key}}'
);
$line_items = $stripe->checkout->sessions->retrieve(
  $_GET['session_id'],
  []
);
echo "<pre>";
print_r($line_items);
echo "</pre>";

我只需要将检索到的对象放入一个对象中,然后我可以将该对象以 json 的形式输出。或者类似的东西。试一试就明白我的意思了。

【讨论】:

    【解决方案2】:

    你来了

    require 'vendor/autoload.php';
    
    \Stripe\Stripe::setApiKey('sk_test_Your_Test_Key');
    
    $session = \Stripe\Checkout\Session::retrieve($_GET['session_id']);
    $customer = \Stripe\Customer::retrieve($session->customer);
    
    print_r($customer);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 2012-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 1970-01-01
      相关资源
      最近更新 更多