【问题标题】:Retrieve Subscription current_period_end via Stripe API通过 Stripe API 检索订阅 current_period_end
【发布时间】:2017-12-30 10:56:48
【问题描述】:

我正在尝试使用 PHP 从 Stripe API 获取订阅 current_period_end 值。 (我认为我使用的 PHP API 库已经过时(1.13.0),但我无法更新它。)

我想这样称呼:

$subscription = Stripe_Subscription::retrieve($pram)

很遗憾,我的 API 库只有订阅方法:

Stripe_Subscription::instanceUrl()
Stripe_Subscription::cancel()
Stripe_Subscription::save()
Stripe_Subscription::deleteDiscount()

如果我选择使用instanceUrl() 方法,它会返回订阅的“API URL”。这是我可以用来获取 Subscription 对象和 current_period_end 值的东西吗?

谢谢 迈克

【问题讨论】:

    标签: php api stripe-payments


    【解决方案1】:

    顶级 Subscription 对象是 API 和库中相对较新的添加。

    您需要执行类似的操作来检索订阅,从客户那里获取它。

    $customer = \Stripe\Customer::retrieve("cus_84Dxgo0C1lgDEI");
    $subscription = $customer->subscriptions->retrieve("sub_84FobhEyhtlQw1");
    

    您可能会发现旧版本的 API 文档或库的 v1.13.0 分支中的测试有用的参考点。

    https://github.com/stripe/stripe-php/blob/v1.13.0/test/Stripe/SubscriptionTest.php#L28

    https://web.archive.org/web/20160312073633/https://stripe.com/docs/api/php

    【讨论】:

      【解决方案2】:

      我相信这应该对您有所帮助。 Stripe 并不容易找到。我认为您的错误是retrieve 拼写错误。

      https://stripe.com/docs/api?lang=php#retrieve_subscription

      您应该能够使用$subscription = Stripe_Subscription::retrieve($pram);,然后$subscription->current_period_end 应该包含您想要的值。

      如果您的 api 库确实太旧而无法检索该数据,您可以使用 cURL 库直接请求对象。这可以通过

      shell_exec('curl https://api.stripe.com/v1/subscriptions/'.$pram.'\ -u '.$api_key.':')
      

      或者使用更安全的php cURL库。

      注意: 前面假设您的 $pram 持有订阅 ID。如果它具有客户 ID 或其他值,您需要共享以便鸭子或我可以告诉您传递什么以获得您正在寻找的订阅 ID。

      【讨论】:

        猜你喜欢
        • 2018-10-20
        • 2015-07-26
        • 1970-01-01
        • 2017-07-03
        • 2015-02-14
        • 2017-08-20
        • 2020-06-06
        • 1970-01-01
        • 2018-05-31
        相关资源
        最近更新 更多