#Dooing-customer-sub
1 messages · Page 1 of 1 (latest)
Hey, you can get all subscriptions for a specific customer using this endpoint: https://stripe.com/docs/api/subscriptions/list#list_subscriptions-customer
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
From there, the items field will contain price/product data: https://stripe.com/docs/api/subscriptions/object#subscription_object-items
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
list? isnt it rather retrieve?
Subscription.retrieve(subscriptionId, retrieveParams, requestOptions);
And then I probably need 1-2 extends for the price and product?
SubscriptionRetrieveParams retrieveParams = SubscriptionRetrieveParams.builder()
.addExpand("items.data.plan.product")
.build();
Subscription subscription = retrieveSubscription(stripeSubscriptionId, retrieveParams);
?
You'd use the retrieve method if you have the sub_xxx ID
You can't pass customer to retrieve
And that would only return a single object, where as the customer could have multiple subscriptions
Nope, no expand required
ok. understood, thanks.
subscriptionCollection.getData()
will this return object be NULL when there isno subscription?
or can I call get Data to retrieve the list of subscriptions in any case?
Again, will this list be empty or null, when there is no subscription?
In our case, it would just always be just one subscription per customer, at least at this point
List<Subscription> subscriptions = subscriptionCollection.getData();
if (subscriptions.isEmpty()) {
return null;
}
Subscription subscription = subscriptions.get(0);
SubscriptionItem subscriptionItem = subscription.getItems().getData().get(0);
String priceId = subscriptionItem.getPrice().getId();
String productId = subscriptionItem.getPlan().getProduct();
It seems, get plan.getProduct is the only way to retrieve the product id? Seems still legacy?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
SubscriptionCollection subscriptionCollection = Subscription.list(SubscriptionListParams.builder()
.addExpand("items.data.price.product")
.setCustomer(stripeCustomerId)
.build());
like so?
Hey, Taking over for my colleague. Let me catch up.
Yes something like that, don't hesitate to test your code in your test environment.
If you need just the price obejct items.data.price no need to expand