#funkthis-default-pm
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. 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.
- funkthat, 1 hour ago, 6 messages
- funkthat, 16 hours ago, 17 messages
- funkthat-addresselement, 3 days ago, 22 messages
What Stripe method are you using to make the API call?
i am not making any apart from fetching a client secret, i am just using the create payment method element, which will handle the request, assuming it will use the paymentMethod create method to apply the new card details as a payment method
if you're using the Payment Element, then you should be able to step through your code and tell me which API calls are being made. Is that something you can do?
yes it is, there is no clear documentation on how to do this though, when i attempted to do this directly using the API it told me we'd have to verify PCI compliance, so now i am using thew payment method element instead.. tried finding documentation on this exact process but could not locate one
Are you the web developer for this product? If so, can't you just pull up the code and find the function that makes the API calls to accept payment method details?
yes i am, i am struggling to find how i attach the submit button for this element's form to pass onto the correct payment method api request
these stripe elements are pretty confusing to me
i've got it displaying the payment method form
but it's attaching it that i cannot locate documentation on
Ahhh, is this a mobile integration? (e.g. iOS/Android)
no, it's a js/php integration
Can you copy/paste the code you're using to create and display the Payment Element?
sure give me a moment
client secret php:
header('Content-Type: application/json'); $customer = get_customer_id_from_wp_user(); if(!$customer) { echo json_encode(array('redirect' => true, 'redirectUrl' => '/account/payment/')); exit; } $stripeSecretKey = getenv('STRIPE_TEST_SK'); $stripe = new \Stripe\StripeClient($stripeSecretKey); $paymentMethodConfig = [ 'customer' => $customer, 'payment_method_types' => [ 'card', ] ]; $paymentMethodSession = $stripe->setupIntents->create($paymentMethodConfig); echo json_encode(array('clientSecret' => $paymentMethodSession->client_secret));
mount element js:
const stripe = Stripe(stripe_pk); initialize() async function initialize() { const response = await fetch(/wp-json/v1/payment-method-session/, { method: "POST", }) const responseData = await response.json() if (responseData.redirect && responseData.redirectUrl) { window.location.href = responseData.redirectUrl return; } const { clientSecret } = responseData const options = { clientSecret: clientSecret, appearance: {}, } const elements = await stripe.elements(options) const paymentElement = elements.create('payment') paymentElement.mount('#payment-element') }
How are you displaying the radio button that allows you to set the default?
<form id="stripe-form" class="stripe-form">
<div id="payment-element">
</div>
<div id="default-method">
<input id="make_default_payment_method" name="make_default_payment_method" type="checkbox" checked="">
<label for="make_default_payment_method"><span>Use as default payment method</span></label>
</div>
<div class="stripe-actions">
<button id="submit" name="add">Add</button>
<button name="back">Go back</button>
</div>
<div id="error-message">
</div>
</form>
Also, I'm seeing wp-json in the code. Are you using Wordpress?
i am, correct
checkout worked a treat and the entire integration for the customer billing portal all works great, this is the last piece of the puzzle being able to create a new payment method and assigning it as the default payment method
i just struggled to find the the associated documentation, hence being here
Okay, so if the radio button is something that Wordpress is displaying for you (note: this isn't a feature that Stripe displays in a Payment Element by default so Wordpress is likely part of a beta with a custom workflow and custom documentation), then you will need to work with them to figure out how that is configured.
i created that checkbox in my page template, i am trying to emulate the default stripe billing portal - there is no middle man here, i am working directly on this using all your documentation, wordpress is the marketing and customer billing portal only.
Okay, so that radio button is in your own HTML. Are you using Invoices and/or Subscriptions?
for example: using this for the checkout https://stripe.com/docs/billing/quickstart works a treat, but i cannot locate a similar document for the payment method
subscriptions
Got it. Okay, and do you want to set the default on the Subscription level? Or at the Customer level?
i will do both, but when adding via new payment method, we will be doing at the customer level
Once you have created a Payment Method via the Payment Element, you have to make a separate API call to set it as the default. So you would have your customer finish submitting the Payment Element form, then grab the Payment Method ID and the Customer ID, then set it as the default on the Customer object via an Update Customer API call with this parameter --> https://stripe.com/docs/api/customers/update#update_customer-invoice_settings-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
yeah that's what i wanted to know, is this how the billing portal does this?
I believe so. I can't remember if it sets the default at the Customer level or the Subscription level though. If you decide to go the Subscription level route, then you'd want to make an Update Subscription API call with this parameter instead --> https://stripe.com/docs/api/subscriptions/update#update_subscription-default_payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
yeah that part i understand and get, it's simply the workflow of the process that I was unsure of how to proceed with - so your suggestions align with what I assumed. thank you!
sorry for the confusing messages
No worries! Took us a bit, but we got down to the heart of the issue. Are you all set?
yeah mate, appreciate all the assistance, if I have any more questions, i'll create a new query if it is unrelated. Thank you!
Sure thing!