简体   繁体   English

通过Stripe API检索订阅current_period_end

[英]Retrieve Subscription current_period_end via Stripe API

I'm trying to get the subscription current_period_end value from the Stripe API using PHP. 我正在尝试使用PHP从Stripe API获取订阅current_period_end值。 (I think the PHP API library I'm using is outdated (1.13.0) but I'm not able to update it.) (我认为我正在使用的PHP API库已经过时(1.13.0),但无法更新。)

I want to call something like: 我想打这样的电话:

$subscription = Stripe_Subscription::retrieve($pram)

Unfortunately, my API library only has the subscription methods: 不幸的是,我的API库仅具有订阅方法:

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

If I choose to use the instanceUrl() method it returns the "API URL" for the subscription. 如果我选择使用instanceUrl()方法,它将返回订阅的“ API URL”。 Is this something I could use to get the Subscription object and the current_period_end value? 这是我可以用来获取Subscription对象和current_period_end值的东西吗?

Thanks Mike 谢谢迈克

I believe this should help you. 我相信这会对您有所帮助。 Stripe did not make it easy to find. 条纹不容易找到。 I think your mistake is mispelling retrieve. 我认为您的错误是错误的检索。

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

You should be able to use $subscription = Stripe_Subscription::retrieve($pram); 您应该可以使用$subscription = Stripe_Subscription::retrieve($pram); and then $subscription->current_period_end should contain the value you want. 然后$subscription->current_period_end应该包含您想要的值。

In the event that your api library really is too old to retrieve that data you could use the cURL library to directly request the object. 如果您的api库确实太旧而无法检索该数据,则可以使用cURL库直接请求该对象。 This could be done either through 这可以通过以下方式完成

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

or with the php cURL library which is more secure. 或使用更安全的php cURL库。

Note: The preceding assumes that your $pram holds the subscription id. 注意:以上假设您的$ pram拥有订阅ID。 If it has the customer id or some other value, you'll need to share so that duck or I could tell you what to pass in order to get the subscription id you're looking for. 如果它具有客户ID或其他值,则需要共享,以便鸭子或我可以告诉您要传递什么以获取所需的订阅ID。

The top level Subscription object is a relatively recent addition to the API and libraries. 顶级Subscription对象是API和库的最新添加。

You'll want to do something like this to retrieve a subscription, grabbing it from the Customer. 您将需要执行以下操作来检索订阅,从客户那里获取订阅。

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

You might find an older version of the API docs or the tests in the v1.13.0 branch of the library helpful point of reference. 您可能会在库的v1.13.0分支中找到较旧版本的API文档或测试,这对您有帮助。

https://github.com/stripe/stripe-php/blob/v1.13.0/test/Stripe/SubscriptionTest.php#L28 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 https://web.archive.org/web/20160312073633/https://stripe.com/docs/api/php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM