#joel-subscription-sepadebit

1 messages · Page 1 of 1 (latest)

rancid monolithBOT
delicate ocean
#

joel-subscription-sepadebit

#

Hey @topaz orchid ! A Secret API key look like sk_test_123456. This is extremely sensitive and should always be stored securely on your own server where you server-side code runs (like in PHP or Node.js and such). This should never be visible client-side in a browser.

As the developer, you want to integrate the API in a way where you create the Subscription first and then client-side you collect their payment method details (card, SEPA Debit, etc.) so that they can pay the first Invoice.

topaz orchid
#

Sry, didn't mean to say "secret key".

I mean Client_Secret.
<button id="submit-button" data-secret="{CLIENT_SECRET}">

#

The Docs refers to create a setup intent before introducing his payment information.

rancid monolithBOT
delicate ocean
#

So yes you should create the SetupIntent first/upfront and then render the PaymentElement to collect their payment method details like SEPA Debit details

topaz orchid
#

But, should I create this Setup Intent when he registers? Or when he proceed to open the form?

#

I guess when he registers... so it's not making duplicated Client Secrets?

sleek wren
#

Hello! Typically you would create a Setup Intent immediately before you're ready to collect the payment details you want to set up for future use.

topaz orchid
#

But, if I create that setup intent, let's say, when he opens the form. And he close it, update the website, and open it again. That would create another Client Secret right? Or if it's the same $customer ID, it reuses?

Wouldn't be better to just create one Client Secret ID when he registers?

sleek wren
#

You can do it either way; having an extra Setup Intent isn't a big deal. Whatever works best for your system and integration.

topaz orchid
#

Ok, and one last question. If I make the setup intent with 'payment_method_types' => ['sepa_debit'],

And, one month, payment fails. I would ask he to confirm he's IBAN number account and pay for the failed payment via debit/credit card. Should I add "card" payment method to that setup intent, or that's a diferent story?

sleek wren
#

At that point you wouldn't be using a Setup Intent, you'd be using a Payment Intent (because you're collecting a payment, not just setting up for future use). You could set the payment_method_types so both sepa_debit and card were included on that Payment Intent and give them the option for either, sure.

topaz orchid
#

Ok, got it!

#

thanks

topaz orchid
#

Hi again, can I reopen this?

So I'm on the Step 5
When user submits the form, after this, what is Step 5 and 6 want me to do exactly?

$stripe = new \Stripe\StripeClient('sk_test_XXXXXX');

$stripe->customers->update(
  'cus_XXXXXX',
  ['invoice_settings' => ['default_payment_method' => 'pm_XXXXXX']]
);

Do I need to use fetch on the submit to this new php file? what "cus_" do I need to use or "pm_" ??

sleek wren
#

Not sure I understand; step 5 of which guide specifically? Step 5 of the guide I linked you to above doesn't seem to have anything to do with what you're asking about?

topaz orchid
sleek wren
#

Ah, gotcha. So step 5 is about setting the default payment method for future Invoices on the Customer. You update the Customer and set invoice_settings.default_payment_method to the Payment Method ID.

#

Step 6 is where you create the Subscription for the Customer for the Price(s) you want to Subscribe them to.

#

Typically all of this would happen immediately after your payment form submission.

topaz orchid
#

but where do I get the customer and payment ID?

#

'customer' => $customer->id,

I guess that's the customer ID

#

but payment ID?

sleek wren
#

You mean the Payment Method ID?

topaz orchid
#

Yes, I guess it's using the "collected at the top level of the Customer object"

How do I get that info

sleek wren
topaz orchid
#

I'm trying too see how to access this object when it's created...

$setup_intent = \Stripe\SetupIntent::create([
'payment_method_types' => ['sepa_debit'],
'customer' => $customer->id,
]);

So, when I make the Setup Intent, I do that.

Just to make sure... $customer is the unique ID of the user that I need to give right?

So, then, when it's created, how do I access this object info via PHP?

sleek wren
#

After that code runs $setup_intent will be the Setup Intent object, and you can then access its properties. Note, however, that the Payment Method won't be there yet; you've only created the Setup Intent here, you haven't confirmed it yet (that happens client-side). After confirmation you can retrieve the Setup Intent and access its updated properties: https://stripe.com/docs/api/setup_intents/retrieve

#

However, the normal flow here is to have your client-side code pass you the Payment Method ID and other relevant info.

topaz orchid
#

Sorry, but I'm not understanding it correctly.

After Step 4,

const form = document.getElementById('payment-form');
const accountholderName = document.getElementById('accountholder-name');
const email = document.getElementById('email');
const submitButton = document.getElementById('submit-button');
const clientSecret = submitButton.dataset.secret;

form.addEventListener('submit', (event) => {
  event.preventDefault();
  stripe.confirmSepaDebitSetup(
    clientSecret,
    {
      payment_method: {
        sepa_debit: iban,
        billing_details: {
          name: accountholderName.value,
          email: email.value,
        },
      },
    }
  );
});

When client submits the form and execute stripe.confirmSepaDebitSetup, afther this I need to set default payment:
You do this by setting the payment method you just collected at the top level of the Customer object

But when and where do I get customer ID and payment ID?

#

Where's the Customer Object?

sleek wren
#

The Customer is the one you set on the Setup Intent back in Step 2.

topaz orchid
#

Ok, and how do I get the data via PHP?
For creating one, I use \Stripe\SetupIntent::create

But for getting the info?

sleek wren
#

Are you using an exsting Customer or creating a new one?

topaz orchid
#

$setup_intent = \Stripe\SetupIntent::create([
'payment_method_types' => ['sepa_debit'],
'customer' => $customer->id,
]);

When making the setup_intent, $customer

I use $customer = $id

I get this ID from the login of an existing user

sleek wren
#

If you're using an existing one you would likely get the Customer ID from your own database.

#

Yeah, okay, so you're getting it from your own database?

topaz orchid
#

Own database, yeah

#

I guess it's different right

sleek wren
#

What's different?

topaz orchid
#

So I can use my own ID? Or do I need ot create one before via Stripe?

sleek wren
#

Let's back up.

#

What is $id?

#

Where did it come from, what does it look like?

topaz orchid
#

When an user creates an account on my website, an ID is created and saved on a database. Then I retrieve this ID from the database and use it on the PHP.

$id = 1

sleek wren
#

Okay, so that's not the Stripe Customer ID. That's your own customer ID.

topaz orchid
#

Yes

sleek wren
#

You need to create a Stripe Customer and use the ID of that object.

#

Typically you would create the Stripe Customer at the same time you create your own customer record, then store the Stripe Customer ID alongisde your own internal ID for that customer.

topaz orchid
#

Ok, I got it

#

So, it would be:

  1. $stripe->customers->create
  2. $setup_intent = \Stripe\SetupIntent::create([
    'customer' => $customer->id,
    ]);
  3. $stripe->customers->retrieve
#

Ok. Thanks!