Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stripe – Get Prices and their Payment Links

I am trying to build a subscription page like like

Payment Layout

I have a GetPrices method to get my Stripe prices and have included the Price Product information too.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading