#binod-elements-help

1 messages · Page 1 of 1 (latest)

silent ravine
#

@frozen heath let's chat here

frozen heath
#

sure

#

I am using @stripe/react-stripe-js library to load PaymentElement

#

but it doesnt render

#

Getting this error

#

you there?

silent ravine
#

Yes I am there, there are many other people to help not just you please be patient it's been a few minutes and I am looking

#

Looks like the first error message is pretty clear/specific and says you didn't pass a client secret, or not a valid one at least. So that's the part you need to debug: log that client secret and make sure it's correct

frozen heath
#

I have a client_secrete

#

in console

#

it's working with CardElement

#

but not with PaymentElement

silent ravine
#

The error message is clear though. It says you don't have a valid client secret

#

Maybe you get the client secret back too late? Can you try hardcoding it in your code? Does it work?

frozen heath
#

` try {
const subscription = await stripe.subscriptions.create({
customer: customerId,
items: [
{
price: priceId,
},
],
payment_behavior: "default_incomplete",
expand: ["latest_invoice.payment_intent"],
});

console.log("Sbus===>", subscription);

res.send({
  subscriptionId: subscription.id,
  clientSecret: subscription.latest_invoice.payment_intent.client_secret,
});

} catch (error) {
return res.status(400).send({ error: { message: error.message } });
}`

#

This is how im sending client_secret to frontend, am I missing anything here?

#

even hard code doesnt work

#

??

silent ravine
#

I mean hardcoding would 100% work if you put the right client secret

#

If it doesn't then you aren't running the code you think you are

#

what's your client-side code?

frozen heath
#

`import React, { useState } from "react";
import {
useStripe,
useElements,
PaymentElement,
} from "@stripe/react-stripe-js";
import { withRouter } from "react-router-dom";

const CheckoutForm = ({ location }) => {
const stripe = useStripe();
const elements = useElements();

const [errorMessage, setErrorMessage] = useState(null);
// const [clientSecret] = useState(location.state.clientSecret);

const clientSecret =
"pi_3L0T8iHsW9ET26Jg1kbbVMB2_secret_TzPc2HysuLe1nYx54JYavDREa";

const handleSubmit = async (event) => {
// We don't want to let default form submission happen here,
// which would refresh the page.
event.preventDefault();

if (!stripe || !elements) {
  // Stripe.js has not yet loaded.
  // Make sure to disable form submission until Stripe.js has loaded.
  return;
}

const { error } = await stripe.confirmPayment({
  //`Elements` instance that was used to create the Payment Element
  clientSecret,
  elements,
  confirmParams: {
    return_url: "https://example.com/order/123/complete",
  },
});

if (error) {
  // This point will only be reached if there is an immediate error when
  // confirming the payment. Show error to your customer (for example, payment
  // details incomplete)
  setErrorMessage(error.message);
} else {
  // Your customer will be redirected to your `return_url`. For some payment
  // methods like iDEAL, your customer will be redirected to an intermediate
  // site first to authorize the payment, then redirected to the `return_url`.
}

};

console.log({ clientSecret });

return (
<form onSubmit={handleSubmit}>
<PaymentElement />
<button disabled={!stripe}>Submit</button>
{/* Show error message to your customers */}
{errorMessage && <div>{errorMessage}</div>}
</form>
);
};

export default withRouter(CheckoutForm);
`

#

am I missing something here?

silent ravine
#

I don't see you set the client secret anywhere in the React element

#
  const options = {
    // passing the client secret obtained in step 2
    clientSecret: '{{CLIENT_SECRET}}',
    // Fully customizable with appearance API.
    appearance: {/*...*/},
  };

  return (
    <Elements stripe={stripePromise} options={options}>
      <CheckoutForm />
    </Elements>
  );
}```
frozen heath
#

I have it in src/index.js

silent ravine
#

sure and my guess is that the clientSecret is not set properly on page load

#

try hardcoding it there

frozen heath
#

yeah, hardcoded client_secret worked. But, client_secret is dynamic right? it changes on every intent?

silent ravine
#

correct, but that's a good way to understand the issue

#

basically you are not initializing the client secret at the right time and you were looking at the wrong code

#

you need to figure out a way to get the client secret ready/available before the code in src/index.js runs

frozen heath
#

oh okay, also how do I enable Ideal payment?

silent ravine
frozen heath
#

not working, My intent is subscription creation

silent ravine
#

iDEAL doesn't work with Subscriptions for now

frozen heath
#

But, it's mentioned here in payment_settings

silent ravine
#

it only works for the collection_method: 'send_invoice' flow which is different

frozen heath
#

does it support Apple pay?

silent ravine
#

yes

frozen heath
#

how?

silent ravine
frozen heath
#

Can I have a custom text above that Submit button?

#

is it possible?

silent ravine
#

the Submit button is your own code right?

frozen heath
#

No, that's basically PaymentElement

#

the whole box

#

Only button code is mine

silent ravine
#

the submit button is yours right? return ( <form onSubmit={handleSubmit}> <PaymentElement /> <button disabled={!stripe}>Submit</button> {/* Show error message to your customers */} {errorMessage && <div>{errorMessage}</div>} </form> )

#

like there's a <button> here and it's your code controlling it. You can add text before it if you want

frozen heath
#

I mean to replace that text above Submit button

#

that 'Nova Automotive' part, specifically

silent ravine
#

that is specific to your account name

#

I have to run but @muted bear is going to take over

muted bear
#

👋

frozen heath
#

Hi Karbi

#

thanks @silent ravine for the help

#

Karbi, you there?

muted bear
#

yup!

frozen heath
muted bear
#

does what koopajah said make sense? You can either disable the whole text box, but you can't have that text box with your own custom text entirely

frozen heath
#

oh okay, so how do I disable whole text box?

muted bear
frozen heath
#

`const stripe = useStripe();
const elements = useElements();

var paymentElement = elements.getElement("payment");
paymentElement.update({ terms: "never" });`

#

like this?

muted bear
#

No, It's be more like
paymentElement.update({ terms: {card: "never"} });

frozen heath
#

it doesnt work

muted bear
#

Hmmm. That's strange that it's not working with the update, but try passing it in during creation instead:
var paymentElement = elements.create("payment",{ terms: {card: "never"} });

frozen heath
#

im useing react useElements

#

so its just const elements = useElements();

muted bear
#

Gotcha - give me a second to check how to do this in react

frozen heath
#

sure

#

also confirmParams: { return_url: "https://example.com/order/123/complete", },

#

is that a success_page_url?

#

inside strip.confirmPayment()

#

??

muted bear
#

Yes, that's the success page URL

frozen heath
#

okay, did you see the react element?

muted bear
#

Still looking - sorry, I'm not a react expert and it's busy in the channel so it's just taking a bit longer

frozen heath
#

No worries. Please let me know if you find a. Solution

muted bear
#

I think you want something like this:
`const OPTIONS = {
terms: {
card: 'never'
},
};

return (
<PaymentElement options={OPTIONS} />
);`

#

Yup, just tried that out on my end and I see it working

#

@frozen heath I need to head out, but @deft moss is here if you have any followups