0

I am building a new feature on top of what is already provided with the WooCommerce Stripe plugin, to enable customers to change their existing ongoing subscriptions which basically cancels their current subscription and sets up a new one to start when their previous one ends. I do this via the Stripe API and then update it accordingly in WooCommerce which works great.

I seem to be missing one part, ensuring the charge is recurring. Does anyone know how WooCommerce Subscriptions sets up the charges to be recurring for future payments with Stripe?

enter image description here

I initiate the charge in the following way:

    $charge = $stripe->charges->create([
        'amount' => intval( $newOrder->get_total() * 100 ),
        'currency' => 'gbp',
        'source' => $card,
        'description' => 'Subscription Update ' . $user->user_email,
        'metadata' => [
            'Order ID' => $newOrder->get_id(),
            'payment_type' => 'recurring',
        ...

I noticed that they set a metadata field of 'payment_type' to recurring, so I added that.

I did find this article for setting up a card for future payments but I am not sure if this is what I need or if I would have to do it a different way?

https://stripe.com/docs/payments/save-and-reuse

Should I be using the PaymentIntent instead of Charge?

https://stripe.com/docs/api/payment_intents/create

Thanks

zen_1991
  • 599
  • 1
  • 10
  • 27

1 Answers1

1

The process of setting up a Subscription (i.e. recurring charges) can be found here [1]. The provided code creates a one-off Charge only. Metadata is rather a way to pass ad-hoc data on objects via the API [2], so isn't relevant in this case. PaymentIntents are the way to go for a Billing integration as they're SCA ready [3].

[1] https://stripe.com/docs/billing/subscriptions/fixed-price

[2] https://stripe.com/docs/api/metadata

[3] https://stripe.com/docs/strong-customer-authentication

v3nkman
  • 1,011
  • 4
  • 3
  • I wasn't sure as the WooCommerce subscriptions plugin simply creates recurring payments in Stripe and doesn't actually use the Subscriptions API. If I'm understanding correctly, id need to use https://stripe.com/docs/api/setup_intents and then use https://stripe.com/docs/api/payment_intents/create? – zen_1991 Jan 28 '21 at 10:15
  • It could well be that WooCommerce has its own internal billing engine and create one off charges based on their own schedules. If my understanding is right and you would like to manage Subscriptions directly against the Stripe API then, the answer is no in this case. When creating Subscriptions, a PaymentIntent or SetupIntent is created automatically under the hood to support the processing of a Charge associated with an Invoice, the system would need to leverage those existing objects: https://stripe.com/docs/billing/subscriptions/fixed-price#manage-payment-authentication – v3nkman Jan 28 '21 at 11:03