#CapitanRex - Subscriptions
1 messages ยท Page 1 of 1 (latest)
Hello! We have documentation about saving a card for later use here: https://stripe.com/docs/payments/save-and-reuse
im getting this error
Uncaught (in promise) IntegrationError: Invalid value for elements(): clientSecret should be a client secret of the form ${id}secret${secret}. You specified: .
Hi there, the clientSecret required here is provided by PaymentIntent [0] or SetupIntent [1]
[0] https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret
[1] https://stripe.com/docs/api/setup_intents/object#setup_intent_object-client_secret
The client_secret provided does not match the client_secret associated with the SetupIntent
I was wondering if you could share a code snippet of your client and server code please?
var createCustomer = new CreateCustomer();
var options = new CustomerCreateOptions
{
Email = customer.Email,
Name = customer.Email,
Phone = customer.Phone
};
createCustomer.CustomerCreateOptions = options;
var serviceCustomer = new CustomerService();
var customerCreated = serviceCustomer.Create(createCustomer.CustomerCreateOptions);
var optionsSetup = new SetupIntentCreateOptions
{
Customer = customerCreated.Id,
PaymentMethodTypes = new List<string> { "card" },
};
var service = new SetupIntentService();
var intent = service.Create(optionsSetup);
var c = new CustomerCreated
{
CustomerId = customerCreated.Id,
ClientSecret = intent.ClientSecret
};
return Ok(c);
that is my create token in .net
You are not returning the client secret to your client?
yeah im returning c
c has client secret
in the client my partner have this code
import ModalPayment from '../components/subscriptions/ModalPayment';import { loadStripe } from '@stripe/stripe-js';import { Elements } from '@stripe/react-stripe-js';
const stripeKey = process.env.REACT_APP_STRIPE_KEY;const stripeAccount = process.env.REACT_APP_STRIPE_ACCOUNT;const stripePromise = loadStripe(stripeKey, { stripeAccount });const post = new APIClient().post;
Thank you for the confirmation and code
import ModalPayment from '../components/subscriptions/ModalPayment';
import { loadStripe } from '@stripe/stripe-js';
import { Elements } from '@stripe/react-stripe-js'
const stripeKey = process.env.REACT_APP_STRIPE_KEY;
const stripeAccount = process.env.REACT_APP_STRIPE_ACCOUNT;
const stripePromise = loadStripe(stripeKey, { stripeAccount });
const post = new APIClient().post;
const Subscriptions = ({ user }) => {
const [clientSecret, setClientSecret] = React.useState('');
React.useEffect(() => {
if (user) {
setServices(user.services);
setSubscriptionsReadyToCheckout(
user.services.filter((item) => item.status === 1)
);
getClientSecret({
name: ${user.name} ${user.lastName},
email: user.email,
phone: user.phoneNumber,
});
}
}, [user]);
const getClientSecret = async (data) => {
const response = await post({
url: '/Subscription/CreateToken',
data,
json: true,
});
console.log(response.json);
setClientSecret(response.json.clientSecret);
setCustomerId(response.json.customerId);
};
const options = {
// passing the client secret obtained in step 2
clientSecret,
// Fully customizable with appearance API.
appearance: {
/.../
},
};
return (
{clientSecret && (
<Elements stripe={stripePromise} options={options}>
<ModalPayment
open={openCheckoutPayment}
close={_handleCloseModal}
services={subscriptionsReadyToCheckout}
customerId={clientSecret.customerId}
/>
</Elements>
)}
...
Sorry for the wait, please give me some time to look at the code ๐
Just wanted to confirm, is /Subscription/CreateToken calling the server code you have provided?
Could you please log what response.json.clientSecret is returning in the getClientSecret function please?
I was wondering if you could clarify where the clientSecret variable is set within
// passing the client secret obtained in step 2
clientSecret,```
Maybe some logs would be helpful as well, thank you ๐
๐ Stepping in. It's a long code and before looking into detail, I would suggest to confirm the value of client_secret passing from server to client