简体   繁体   中英

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. (I think the PHP API library I'm using is outdated (1.13.0) but I'm not able to update it.)

I want to call something like:

$subscription = Stripe_Subscription::retrieve($pram)

Unfortunately, my API library only has the subscription methods:

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. Is this something I could use to get the Subscription object and the current_period_end value?

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

You should be able to use $subscription = Stripe_Subscription::retrieve($pram); and then $subscription->current_period_end should contain the value you want.

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. 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.

Note: The preceding assumes that your $pram holds the subscription 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.

The top level Subscription object is a relatively recent addition to the API and libraries.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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