#carboncopper_api

1 messages ยท Page 1 of 1 (latest)

fading pelicanBOT
#

๐Ÿ‘‹ 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.

polar bone
#
// 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' ],
]);
grizzled urchin
#

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

polar bone
#

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?

grizzled urchin
#

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

polar bone
#

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.

grizzled urchin
#

No, not necessarily. I just tried this with a CT and then confirmed on the backend and it works:

  1. Init Payment Element as you are, remove paymentMethodCreation
  2. Call createConfirmationToken โ€“ this will handle the mandate generation
  3. Call your backend, passing the ct_xxx just generated
  4. Create the subscription
  5. Call PI confirm endpoint, passing confirmation_token: 'ct_xxx'
polar bone
#

Can I use the Payment Intent to create a monthly subscription?

grizzled urchin
#

The subscription will generate the intent yes, assuming the initial invoice has a payment

polar bone
#

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?

grizzled urchin
#

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']

polar bone
#

Okay, I think I get it now. Thank you.

grizzled urchin
#

Sure