admin管理员组

文章数量:1133883

I'm using Stripe subscriptions in my application. The subscription is initiated by purchasing an appropriate item defined on the Stripe side by executing Stripe\Checkout\Session (roughly as shown below):

$checkout_session = \Stripe\Checkout\Session::create([
    'line_items' => $line_items,
    'customer' => $stripe_customer_array['id'],
    'automatic_tax' => [
        'enabled' => true,
    ],
    'mode' => 'subscription',
    'payment_method_types' => ['card'],
    'allow_promotion_codes' => true,
    'currency' => 'USD',
    'success_url' => $this->generateUrl('user_panel_payments', [], UrlGeneratorInterface::ABSOLUTE_URL) . '/confirmation?session_id={CHECKOUT_SESSION_ID}',
    'cancel_url' => $this->generateUrl('user_panel_payments_plan', [], UrlGeneratorInterface::ABSOLUTE_URL) . '?canceled=true',
    'invoice_creation' => [
        'enabled' => true,
    ],
]);

The webhook then receives subscription details, invoices, and everything works fine.

However, if I create a subscription directly in the Stripe dashboard, the subscription's billing method is set to "Send invoice" by default, which makes sense since I can't process the payment on behalf of the user. In this case, the invoice is also created on the Stripe side, and I receive a webhook with a payment_intent.

What can I do next with this? I'd like to create a custom button on my website to initialize the payment for a given existing invoice, but I'm not sure how to achieve this. I don't see a way to pass the payment_intent ID into Stripe\Checkout\Session. Maybe I should create a payment link?

Is it possible to create such a link or button?

Also, I'm not interested in using the hosted_invoice_url, as it's not suitable for my use case (I need to hide Stripe-hosted invoices since I already have my own invoices for specific reasons).

I'm using Stripe subscriptions in my application. The subscription is initiated by purchasing an appropriate item defined on the Stripe side by executing Stripe\Checkout\Session (roughly as shown below):

$checkout_session = \Stripe\Checkout\Session::create([
    'line_items' => $line_items,
    'customer' => $stripe_customer_array['id'],
    'automatic_tax' => [
        'enabled' => true,
    ],
    'mode' => 'subscription',
    'payment_method_types' => ['card'],
    'allow_promotion_codes' => true,
    'currency' => 'USD',
    'success_url' => $this->generateUrl('user_panel_payments', [], UrlGeneratorInterface::ABSOLUTE_URL) . '/confirmation?session_id={CHECKOUT_SESSION_ID}',
    'cancel_url' => $this->generateUrl('user_panel_payments_plan', [], UrlGeneratorInterface::ABSOLUTE_URL) . '?canceled=true',
    'invoice_creation' => [
        'enabled' => true,
    ],
]);

The webhook then receives subscription details, invoices, and everything works fine.

However, if I create a subscription directly in the Stripe dashboard, the subscription's billing method is set to "Send invoice" by default, which makes sense since I can't process the payment on behalf of the user. In this case, the invoice is also created on the Stripe side, and I receive a webhook with a payment_intent.

What can I do next with this? I'd like to create a custom button on my website to initialize the payment for a given existing invoice, but I'm not sure how to achieve this. I don't see a way to pass the payment_intent ID into Stripe\Checkout\Session. Maybe I should create a payment link?

Is it possible to create such a link or button?

Also, I'm not interested in using the hosted_invoice_url, as it's not suitable for my use case (I need to hide Stripe-hosted invoices since I already have my own invoices for specific reasons).

Share Improve this question asked Jan 7 at 21:27 RLXRLX 867 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Problem

If you create a Subscription with a collection_method of 'send_invoice', Stripe will expect you to send the Invoice to the customer (or Stripe can do it for you) to collect payment. Based on the wording in your question, I think you do not want the customer interfacing with the Hosted Invoice Page which is Stripe's prebuilt and hosted UI for collecting payment method information and applying to an Invoice.

Solution

If you are fine with redirecting your customers to the Hosted Invoice Page, then that is the approach that requires the least effort up front.

However, in cases where you have already created a Subscription with an Invoice and Payment Intent, and you do not want to use Stripe's own UIs, then you will need to build your own UI to collect payment method details and submit them to Stripe.

I recommend using the Payment Element and following the Accept a Payment guide to cover how you set up the Payment Element and connect it to your Payment Intent using Stripe.js.

Building your own UI is significantly more engineering effort on your part but would allow you the greater flexibility of controlling more of the UI.

本文标签: phpCreating Payment Buttons for Existing Payment Intents in StripeStack Overflow