#CapitanRex - Subscriptions

1 messages ยท Page 1 of 1 (latest)

modest raft
wild halo
#

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: .

upper schooner
wild halo
#

The client_secret provided does not match the client_secret associated with the SetupIntent

upper schooner
#

I was wondering if you could share a code snippet of your client and server code please?

wild halo
#

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

upper schooner
#

You are not returning the client secret to your client?

wild halo
#

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;

upper schooner
#

Thank you for the confirmation and code

wild halo
#

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>

)}

#

...

upper schooner
#

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 ๐Ÿ™‚

latent marten
#

๐Ÿ‘‹ 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