#carboncopper_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1393160273397022751
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- carboncopper_api, 4 days ago, 25 messages
// Server side PHP
$paymentMethodId = $_REQUEST['payment_method_id'];
$product = \Stripe\Product::create([
'name' => $description
]);
$price = \Stripe\Price::create([
'unit_amount' => 1000,
'currency' => 'gbp',
'recurring' => [
'interval' => 'month',
'interval_count' => 1
],
'product' => $product->id,
]);
$customer = \Stripe\Customer::create([
'email' => 'john.doe@example.com',
'name' => 'John Doe',
'description' => 'Hello world',
'payment_method' => $paymentMethodId,
'address' => [
'city' => 'Beverly Hills',
'country' => 'US',
'line1' => '123 Main St',
'line2' => '',
'postal_code' => '90210',
'state' => 'CA',
]
]);
$customer->invoice_settings->default_payment_method = $paymentMethodId;
$customer->save();
$subscription = \Stripe\Subscription::create([
'customer' => $customer->id,
'description' => 'Hello world',
'items' => [
[ 'price' => $price->id ]
],
'default_payment_method' => $paymentMethodId,
'collection_method' => 'charge_automatically',
'payment_behavior' => 'default_incomplete',
'expand' => [ 'latest_invoice' ],
]);
Simply generating a pm_xxx object via createPaymentMethod isn;t sufficient. That just tokenises the banking data, it just generate a BACS mandate which is why it requires confirmation from the customer
Can you not just omit the paymentMethodCreation: 'manual'?
Then when you generate the subscription backend, return the client secret back to Elements and call confirmation method
Previously, I was able to do something similar for one-time payments. I used createConfirmationToken() in Stripe.js. And that token was enough to finalize a payment intent in PHP.
With subscriptions is there an equivalent workflow?
The confirmation part needs to happen client side so your customer can agree to the mandate terms
CTs actually hold mandate data though AFAIK, PMs do not
Ok, let's see if I understand correctly. For subscriptions, the customer always needs to click through twice. First time to confirm the account number, and then again to confirm the mandate.
No, not necessarily. I just tried this with a CT and then confirmed on the backend and it works:
- Init Payment Element as you are, remove
paymentMethodCreation - Call
createConfirmationTokenโ this will handle the mandate generation - Call your backend, passing the
ct_xxxjust generated - Create the subscription
- Call PI confirm endpoint, passing
confirmation_token: 'ct_xxx'
Can I use the Payment Intent to create a monthly subscription?
The subscription will generate the intent yes, assuming the initial invoice has a payment
Let's say I follow your steps 1-5. I will have a confirmed payment intent. Can I go from there to create a subscription? Or does the subscription create its own new payment intent?
No, you do the subscription first (step 4)
Then when you confirm the PI that will transition the sub to 'active'
expand: ['latest_invoice.payment_intent']
Okay, I think I get it now. Thank you.
Sure