#Stripe test mode does not work with customer twice
44 messages · Page 1 of 1 (latest)
No, it doesn't cause problems. And you'll need to post some logs, errors.
@oak moat there are no errors, all went fine, also the payment i can see in the stripe dashboard, but it's not captured and i think the webhook is not triggered because in my medusa backend i can't see any order
You need to show the whole cart response.
i checked the stripe logs again and there is no email in the response body of /customer
@oak moat sry what do you mean with the whole cart response?
The whole affected cart
I mean the whole cart in json. Please don't ping.
Yes, you need to take care of the email. It's not there and the customer_id is null
There's not even a payment_session on that cart
alright ... but what's not clear for me is why it is there when i update the cart with that email for the first time?
I don't know, you need to check how you're updating the cart.
sry i sent the wrong json yesterday, this is my actual response:
and this is the response of the cart completion:
there the email is set, but type is "cart" and not "order"
It's a different cart
yes i know sry it is, because i did it twice, but nevertheless the response show that there is an email in it
i always get two payments in stripe, if i get the card + email it works and i get an order in the medusa backend but if it is the card + customerID it does not work
I still don't understand
You need to show the cart that fails
And the payment in stripe that you think went for this cart
Because you're posting multiple things and I don't know what to look at
Also how are you confirming the payment? Show the handler
you're totally right, i'm communicating completely confusing - sry for this!
this is the payment in stripe and the response of the cart completion - this failed and i never got any order in my medusa backend
this is my code in the frontend:
const processPayment = async () => {
const {error, paymentIntent} = await stripe.value.confirmCardPayment(clientSecret.value, {
payment_method: {
card: paymentElement.value,
billing_details: {
name: 'felix h',
email: '[email protected]',
phone: '',
address: {
city: 'address',
country: 'at',
line1: 'some address',
line2: '',
postal_code: '1234'
}
}
}
});
console.log(error, 'there is some stripe error');
console.log(paymentIntent, 'this is the stripe payment ident');
const client = useMedusaClient();
const backendData = useBackendDataStore();
if (!backendData.cart) {
return;
}
console.log(backendData.cart, 'cart');
const completeResponse = await client.carts.complete(backendData.cart.id);
console.log(completeResponse, 'response of cart complete');
console.log('payment done');
```
here: #1210220060791283732 message
is the whole code of the payment component
So this is not React?
nop, it's nuxt
sry for the poor coding style - just my code for testing, want to refactor it afterwards
First thing I would sugguest is using PaymentElement from stripe instead of the legacy Elements. But this isn't the issue.
Where does clientSecret.value come from?
onMounted(async () => {
await setUpStripe();
});
const setUpStripe = async () => {
// if (!process.env.STRIPE_PUBLISHABLE_KEY) {
// return;
// }
stripe.value = await loadStripe('pk_test_***');
if (!stripe) {
return;
}
const client = useMedusaClient();
const backendData = useBackendDataStore();
if (!backendData.cart) {
console.warn('no cart therefore no payment possible');
return;
}
const newCart = await client.carts.createPaymentSessions(backendData.cart.id);
const isStripeAvailable = newCart.cart.payment_sessions?.some(
(session) => (
session.provider_id === "stripe"
)
);
if (!isStripeAvailable) {
return;
}
var secondCart = await client.carts.setPaymentSession(newCart.cart.id, {
provider_id: "stripe"
});
clientSecret.value = secondCart.cart.payment_session?.data.client_secret as string;
const elements = stripe.value.elements({clientSecret: clientSecret.value});
paymentElement.value = elements.create('card');
if (!paymentElement.value) {
return;
}
paymentElement.value.mount('#payment-element');
// just add a sample customer REFACTOR NEEDED!!
const thirdCart = await client.carts.update(backendData.cart.id, {email: '[email protected]'});
console.log(thirdCart, 'cart when init');
};
i get it in my stripe set up function
Wow, why there are two, three carts
as i said really sorry for my coding style here ... but nevertheless this shouldn't be the problem
i just tried around a few things, that's why i have multiple variables for the cart
How am I supposed to debug this? 🙂
How are you sure that backendData.cart.id === newCart.cart.id
yes that's completely stupid from my side an i really have to refactor it - but this i already have debugged it and it's the same cart.id
I don't know, is there some strict mode like in React that runs code twice?
no not really
maybe i should first refactor it, right?
i always get 2 payments, one with the email and one with the customer id - this shouldn't be the case right?
Create payment sessions after setting email