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?
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
question from:
https://stackoverflow.com/questions/65933748/how-to-setup-charges-to-be-recurring 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…