#joel-subscription-sepadebit
1 messages · Page 1 of 1 (latest)
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.
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.
So yes you should create the SetupIntent first/upfront and then render the PaymentElement to collect their payment method details like SEPA Debit details
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?
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.
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?
You can do it either way; having an extra Setup Intent isn't a big deal. Whatever works best for your system and integration.
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?
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.
You could also use automatic payment methods, which allows you to configure available payment methods from the Dashboard: https://stripe.com/docs/api/payment_intents/create#create_payment_intent-automatic_payment_methods
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_" ??
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?
I mean the first doc I send https://stripe.com/docs/billing/subscriptions/sepa-debit
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.
but where do I get the customer and payment ID?
'customer' => $customer->id,
I guess that's the customer ID
but payment ID?
You mean the Payment Method ID?
Yes, I guess it's using the "collected at the top level of the Customer object"
How do I get that info
The Payment Method will be attached to the Setup Intent at this point in the flow: https://stripe.com/docs/api/setup_intents/object#setup_intent_object-payment_method
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?
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
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
However, the normal flow here is to have your client-side code pass you the Payment Method ID and other relevant info.
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?
The Customer is the one you set on the Setup Intent back in Step 2.
Ok, and how do I get the data via PHP?
For creating one, I use \Stripe\SetupIntent::create
But for getting the info?
Are you using an exsting Customer or creating a new one?
If you're creating a new one you would use this API: https://stripe.com/docs/api/customers/create
$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
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?
What's different?
So I can use my own ID? Or do I need ot create one before via Stripe?
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
Okay, so that's not the Stripe Customer ID. That's your own customer ID.
Yes