I am trying to build a subscription page like like
I have a GetPrices method to get my Stripe prices and have included the Price Product information too.
public StripeList<Price> GetPrices()
{
StripeConfiguration.ApiKey = Options.SecretKey;
var service = new PriceService();
var priceListOption = new PriceListOptions
{
Limit = 3,
Active = true
};
priceListOption.AddExpand("data.product");
return service.List(options: priceListOption);
}
I also have a GetPaymentLinks method which just returns a count number of PaymentLinks.
public StripeList<PaymentLink> GetPaymentLinks(int count)
{
StripeConfiguration.ApiKey = Options.SecretKey;
var paymentLinkListOptions = new PaymentLinkListOptions
{
Limit = count,
Active = true
};
var service = new PaymentLinkService();
return service.List(paymentLinkListOptions);
}
What I can not seem to do is find the link between Price/Product and PaymentLinks
I can lookup through the list of Prices and display the Name, Description and Price. But I need to use the PaymentLink within the "Buy Now" button. Is there any way to do this with the Stripe Api?
>Solution :
The Price / Product would be found in the line_items array of your Payment Link(s).
https://stripe.com/docs/api/payment_links/payment_links/object#payment_link_object-line_items
This array doesn’t populate by default, you need to expand it:
https://stripe.com/docs/expand
If you want to expand both the Price and Product from this array, you can nest your expand == data.line_items.data.price.
That’s the furthest you’ll be able to go with a list because of that data prefix. In a Payment Link retrieve, you could go further with line_items.data.price.product.
