#peter-payment-methods
1 messages ยท Page 1 of 1 (latest)
for reference, here is the code I'm using to make the request:
const hasPaymentMethod = Boolean(cashSender.stripePaymentMethodId);
const returnUrlProps = hasPaymentMethod
? {}
: { return_url: `${process.env.WEB_CLIENT_URL}/offers` };
const paymentMethodProps = hasPaymentMethod
? { payment_method: cashSender.stripePaymentMethodId }
: {};
const paymentIntent = await stripe.paymentIntents.create({
customer: cashSender.stripeCustomerId,
amount: totalAmount,
currency: 'usd',
application_fee_amount: feeAmount,
confirm: true,
transfer_data: {
destination: cashRecipient.stripeAccountId,
},
automatic_payment_methods: {
enabled: true,
},
metadata: {
offer_id: offer.id
},
...returnUrlProps,
...paymentMethodProps
});
yeah
So you would want to create a card Element and mount it, then passs in the client secret from your Payment Intent to stripe.confrimCardPayment()
https://stripe.com/docs/js/payment_intents/confirm_card_payment
This guide is really good for getting from A->B if you need a good jumping-off-point: https://stripe.com/docs/payments/quickstart
so I have elements already up and working
I use "setup_intent" to add their payment method for future use in previous flows
but if they haven't gone through those flows, we create the payment_intent and then want to use the client-secret from they payment_intent to start the PaymentElement
I'm using confirmCardPayment after they complete the payment method flow
but the problem I'm seeing is that I can't get the client secret cuz the PaymentIntent is failing with the errors I mentioned above
So you should try creating the Payment Intent without passing a return_url and then call confirmCardPayment()
Is there a reason that this doesn't work?
ah I just wanted to confirm it right away once the payment method is added
cuz they've technically already confirmed the payment
Hi ๐ I'm stepping in for @hidden ocean. Are you good here or can you explain clearly what you are trying and what's not working?
hey, I think my solution is to wait for the payment method to be added after the payment intent succeeds, then update the payment intent with confirm: true
is that right?
What is is you are trying to achieve in that case?
Can you share request IDs for one request where the customer has an attached payment method already and one where they don't?
My initial approach would be to split the Payment Intent creation into 2 separate functions that each create an intent for the specific case. E.g. if (hasPaymentMethod){ createIntentWithPaymentMethod()} else {createIntentAndMethod()}
Sorry it's all on one line like that ๐
user buys an item
-- if payment method exists
-> create PaymentIntent and charge card
-- if does not exist
-> create PaymentIntent and use client-secret to add payment method, then charge card
Yup, I'm thinking that you might want to use the approach of creating the PM with the Payment Intent we outline here: https://stripe.com/docs/payments/save-during-payment
In the second case
This will do both parts together (create the Payment Method, attach it to the Customer, charge the Payment Method to complete the Payment Intent)
But in that flow you'll need to collect the payment details which is I think where you're at right now.
yeah I'm doing that now I believe
the trouble is having the payment confirm once the payment method is attached
So you are creating the Payment Intent successfully? Can you share a request ID?
Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
pi_3KqQLPJYMOMTx4nT0ZpztkKz
Okay that's a Payment Element ID but I can try and work with that.
oh I see
Okay so this request isn't configured for off-session usage so you'd collect payment method details but it'd be a one-off
Here's the creation request FYI: https://dashboard.stripe.com/test/logs/req_i0dYg4yqQbppWC
These logs are really useful to find failed API requests. I make plenty of bad API calls and reviewing these help me out
thats awesome, thanks
Okay so you make the Payment Intent, get it back and pass the client secret to your front-end. Where is the point of failure?
I was doing that before, but it wasn't completing the payment afterward
but it might work now, let me check
also it seems difficult to test these things in dev
is there a default bank account to use for Stripe Connect that always works in dev?
we're using Plaid + Stripe to connect bank accounts
Oh, well shucks. Yeah we have test bank accounts for all kinds of different scenario testing
nice
ok so I'm seeing this issue when submitting the payment method
code: "resource_missing"
doc_url: "https://stripe.com/docs/error-codes/resource-missing"
message: "No such setupintent: 'pi_3KqQXuJYMOMTx4nT081fJ3kQ'"
param: "intent"
type: "invalid_request_error"
this is my code for submitting as given in the tutorial
event.preventDefault();
setIsLoading(true);
if (!stripe || !elements) {
return;
}
const result = await stripe.confirmSetup({
elements,
confirmParams: {
return_url: `${process.env.NEXT_PUBLIC_BASE_URL}/${asPath}`,
}
});
if (result.error) {
logError(result.error);
}
};```
Yeah, you need to use stripe.confirmPayment when you use a Payment Intent:
https://stripe.com/docs/js/payment_intents/confirm_payment
oh damn one sec
Are you using the Payment Element or the Card Element to collect payment method details?
Payment Element
Okay, then that's the right function
got it, thanks
Let me know if you have any questions or trouble getting it running