#costia-error
1 messages · Page 1 of 1 (latest)
@dapper plinth hi! do you have a request ID req_xxx (https://support.stripe.com/questions/finding-the-id-for-an-api-request) for that error?
nope there is no request id i will show you the full error :
at Function.generate (/var/www/html/back_end/API/node_modules/stripe/lib/Error.js:40:16)
at res.toJSON.then.StripeAPIError.message (/var/www/html/back_end/API/node_modules/stripe/lib/StripeResource.js:220:35)
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
requestId: 'req_aUk3DtXnqtcoRi'
},
rawType: 'invalid_request_error',
code: undefined,
doc_url: undefined,
param: 'payment_method',
detail: undefined,
headers: {
server: 'nginx',
date: 'Wed, 05 Jan 2022 11:24:01 GMT',
'content-type': 'application/json',
'content-length': '980',
connection: 'keep-alive',
'access-control-allow-credentials': 'true',
'access-control-allow-methods': 'GET, POST, HEAD, OPTIONS, DELETE',
'access-control-allow-origin': '*',
'access-control-expose-headers': 'Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required',
'access-control-max-age': '300',
'cache-control': 'no-cache, no-store',
'idempotency-key': '1c908c92-d73f-4dad-a613-62baeee5e7f0',
'original-request': 'req_aUk3DtXnqtcoRi',
'request-id': 'req_aUk3DtXnqtcoRi',
'stripe-version': '2020-08-27',
'strict-transport-security': 'max-age=31556926; includeSubDomains; preload'
},
requestId: 'req_aUk3DtXnqtcoRi',
statusCode: 400,
charge: undefined,
decline_code: undefined,
payment_intent: undefined,
payment_method: undefined,
payment_method_type: undefined,
setup_intent: undefined,
source: undefined
}
api code (Node.js):
app.post("/api/charge", async (req, res) => {
const { amount, paymentMethod, merchnatId } = req.body
try {
const payment = await stripe.paymentIntents.create({
amount: Math.floor(amount),
currency: "EUR",
description: 'Thats just a test',
payment_method: paymentMethod,
confirm: true
})
if (payment) {
const transfer = await stripe.transfers.create({
amount: Math.floor(amount * 85 / 100),
currency: 'eur',
destination: merchnatId,
});
if (transfer) {
res.status(200).send([transfer, payment])
}
}
} catch(error){
console.log(error)
res.json({
message: "The fake payments dosen't work !!!",
success: false,
})
}
})
you want payment_method: paymentMethod.id, instead
in the backend call to stripe.paymentIntents.create
so i need to transform :
const handleSubmit = async(event)=>{
event.preventDefault();
const {error, paymentMethod } = await stripe.createPaymentMethod({
type: "card",
card: elements.getElement(CardElement),
});
if(!error){
console.log("Token gen :", paymentMethod)
dispatch(charges(amount, paymentMethod, merchantId))
}else {
console.log("Soucis a l'envoie", error.message)
}}
to this:
const handleSubmit = async(event)=>{
event.preventDefault();
const {error, paymentMethod } = await stripe.createPaymentMethod({
type: "card",
card: elements.getElement(CardElement),
});
if(!error){
console.log("Token gen :", paymentMethod)
dispatch(charges(amount, paymentMethod.id, merchantId))
}else {
console.log("Soucis a l'envoie", error.message)
}}
that could work too yes
thanksssssss
either approach works, you can change the frontend to send the ID, or have the backend read the ID from the JSON
also you should be using a Destination charge instead of creating a transfer separately : https://stripe.com/docs/connect/destination-charges#create-a-charge
and you should also be confirming the PaymentIntent client side, not server side like this(instead of creating the PaymentMethod on the frontend and sending it to the backend, you should be creating the PaymentIntent first, then confirming it on the frontend to complete the payment there).
The guide you want to work with is https://stripe.com/docs/connect/collect-then-transfer-guide overall
I will check but I still have an error :
tripeInvalidRequestError: No such PaymentMethod: 'pm_1KEXp1B7qDrgtCRmnjt34Z3C'
at Function.generate (/var/www/html/back_end/API/node_modules/stripe/lib/Error.js:40:16)
at res.toJSON.then.StripeAPIError.message (/var/www/html/back_end/API/node_modules/stripe/lib/StripeResource.js:220:35)
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
type: 'StripeInvalidRequestError',
raw: {
code: 'resource_missing',
doc_url: 'https://stripe.com/docs/error-codes/resource-missing',
message: "No such PaymentMethod: 'pm_1KEXp1B7qDrgtCRmnjt34Z3C'",
param: 'payment_method',
type: 'invalid_request_error',
headers: {
server: 'nginx',
date: 'Wed, 05 Jan 2022 11:38:28 GMT',
'content-type': 'application/json',
'content-length': '262',
connection: 'keep-alive',
'access-control-allow-credentials': 'true',
'access-control-allow-methods': 'GET, POST, HEAD, OPTIONS, DELETE',
'access-control-allow-origin': '*',
'access-control-expose-headers': 'Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required',
'access-control-max-age': '300',
'cache-control': 'no-cache, no-store',
'idempotency-key': '9ce86da3-14e2-4498-9b1d-5707dbaaee11',
'original-request': 'req_SEdkivyMHVm4Yz',
'request-id': 'req_SEdkivyMHVm4Yz',
'stripe-version': '2020-08-27',
'strict-transport-security': 'max-age=31556926; includeSubDomains; preload'
},
statusCode: 400,
requestId: 'req_SEdkivyMHVm4Yz'
},
rawType: 'invalid_request_error',
code: 'resource_missing',
doc_url: 'https://stripe.com/docs/error-codes/resource-missing',
param: 'payment_method',
detail: undefined,
headers: {
server: 'nginx',
date: 'Wed, 05 Jan 2022 11:38:28 GMT',
'content-type': 'application/json',
'content-length': '262',
connection: 'keep-alive',
'access-control-allow-credentials': 'true',
'access-control-allow-methods': 'GET, POST, HEAD, OPTIONS, DELETE',
'access-control-allow-origin': '*',
'access-control-expose-headers': 'Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required',
'access-control-max-age': '300',
'cache-control': 'no-cache, no-store',
'idempotency-key': '9ce86da3-14e2-4498-9b1d-5707dbaaee11',
'original-request': 'req_SEdkivyMHVm4Yz',
'request-id': 'req_SEdkivyMHVm4Yz',
'stripe-version': '2020-08-27',
'strict-transport-security': 'max-age=31556926; includeSubDomains; preload'
},
requestId: 'req_SEdkivyMHVm4Yz',
statusCode: 400,
charge: undefined,
decline_code: undefined,
payment_intent: undefined,
payment_method: undefined,
payment_method_type: undefined,
setup_intent: undefined,
source: undefined
}
that error usually means you have your API keys mixed up
looks like you have two Stripe accounts and the publishable key pk_test_xxx you use on the frontend is for one account, but the secret key sk_test_xxx you use on the backend is for the other. You need to change them to be from the same account.
ah yes my baddddd
cool cool. When you get that working your next error is going to most likely be an 'insufficient balance' error from creating the transfer(which is why you should use a Destination Charge instead).