如何从Stripe中检索非活动(已取消)订阅

时间:2014-10-19 12:20:57

标签: stripe-payments stripe.net

我想确认客户订阅已被取消。 Stripe API documentation仅指返回"有效"订阅。如何获得所有订阅的列表?

  

列出订阅

     

您可以看到客户的有效订阅列表。

GET https://api.stripe.com/v1/customers/{CUSTOMER_ID}/subscriptions
     

检索客户的订阅

     

默认情况下,您可以直接在客户对象上查看存储在客户上的10个最新活动订阅,但您也可以检索有关客户的特定活动订阅的详细信息。

GET https://api.stripe.com/v1/customers/{CUSTOMER_ID}/subscriptions/{SUBSCRIPTION_ID}

3 个答案:

答案 0 :(得分:5)

对不起这里的困惑! Stripe仅返回活动订阅; API不会返回已取消的API。但是,您知道通过在您的webhook网址中观看该活动来取消订阅。而且,如果您的网站正在取消取消请求(而不是因付款失败而自动取消),如果该请求失败,我们会抛出异常。

希望有所帮助, 拉里

PS我在Stripe的支持工作。

答案 1 :(得分:3)

自7/06/16 API更新开始:

  

现在,您可以通过在列出订阅时指定status = canceled或status = all来查看已取消的订阅。此外,您现在可以通过其ID来检索已取消的订阅。

https://stripe.com/docs/upgrades#api-changelog

因此,如果你正在使用ruby API,那么你应该能够获取这样的取消订阅:

Stripe::Subscription.all(status: 'canceled')

获取所有订阅的列表,如上所述,如下所示:

Stripe::Subscription.all(status: 'all')

答案 2 :(得分:0)

对于PHP:

require_once('stripe/init.php');

\Stripe\Stripe::setApiKey(YOUR_STRIPE_SECRETKEY);

// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);

if($event_json->type=='customer.subscription.deleted')
{
    $stripe_customerid = $event_json->data->object->customer; // cus_123456
    $customer = \Stripe\Customer::retrieve($stripe_customerid);
    $usermail = $customer->email;
    // ...
}
  

如果订阅已取消,则会关闭最新的未付款发票,并且不会生成其他发票。在之前的charge.failed和invoice.payment_failed事件之后触发customer.subscription.deleted事件。您可以看到订阅已自动取消 - 而不是您的请求 - 如果customer.subscription.deleted事件的请求属性为null。

相关问题