#Emile
1 messages ยท Page 1 of 1 (latest)
Hello ๐
The code you've shared only creates a payment method
Are there any specific docs/guides you're referring to?
Unfortunately my payment process is overly convoluted as i'm integrating with an existing implementation. So the client is a flutter app which uses flutter_pay package, to process the apple/google pay implementation.
I've setup the flutter_pay configuration and this is now returning the information such as below.
I/flutter (16155): "id": "tok_1LmJ1CCuNoDIHgnqNZ7gzI4S",
I/flutter (16155): "object": "token",
I/flutter (16155): "card": {
I/flutter (16155): "id": "card_1LmJ1CCuNoDIHgnqYCt13RwC",
I/flutter (16155): "object": "card",
this gets passed to our backend where we then interact with stripe.
i've been told that i need to pash the token Id, into createPaymentMethod
id: "tok_1LmJ1CCuNoDIHgnqNZ7gzI4S"
But i've not really seen anywhere a clear explanation of how to then actually process the payment immediately.
Ah gotcha. I'm not sure about the flutter integration as it is a third-party implementation.
But ideally, you create a payment method by accepting the payment method details and then confirm the PaymentIntent in order to successfully complete the payment.
You'd likely want to reach out to flutter_stripe package maintainer on Github
In generall, whats the flow?
because i've seen the createPaymentintent() and examples where that just defines what you intend to pay, and then thats passed into createPaymenMethod()
But i think i've also seen it explained the other way round. and well, its not clear to me whats supposed to happen.
So lets say for example in react native or any of our mobile SDKs
If you're accepting a payment
1/ Create a PaymentIntent
2/ Render PaymentSheet or elements on client-side using PaymentIntent client-secret
3/ Collect PaymentMethod details
4/ PaymentSheet will then try to confirm the PaymentIntent using the payment method details that have been collected
Are you charging the payment method immediately or are you trying to set it up for future use?
one off payment with google or apple pay.
i'm not using any of the SDKs, because i'm having to swap out parts of an existing system.
SO i'm able to successfully create a stripe token from google pay.
I then pass that to the backend, where i implement the payment part into stripe using the nodejs striped sdk.
export const putStripePayment = function (amount: string, token:string): Promise<Stripe.PaymentMethod> {
return new Promise<Stripe.PaymentMethod>(async (resolve, reject) => {
try {
const Stripe_clientID = await getSecret1(`projects/${process.env.GCLOUD_PROJECT}/secrets/stripe_api_key/versions/latest`);
const stripe = new Stripe(Stripe_clientID, {
apiVersion: "2022-08-01",
});
logger.info(`putStripePayment(${amount}). `);
const paymentMethod = await stripe.paymentMethods.create({type:"card",card:{token:token.toString()}});
resolve(paymentMethod);
} catch (error) {
reject(error);
}
});
};
where token is
tok_1LmIe6CuNoDIHgnqyCGzw1sa
which is generated by google pay
{
"id": "tok_blahblaj",
"object": "token",
"card": {
"id": "card_blahblaj",
"object": "card",
"address_city": "Mountain View",
"address_country": "US",
"address_line1": "1600 Amphitheatre Parkway",
"address_line1_check": "unchecked",
"address_line2": null,
"address_state": "CA",
"address_zip": "94043",
"address_zip_check": "unchecked",
"brand": "Visa",
"country": "US",
"cvc_check": null,
"dynamic_last4": "4242",
"exp_month": 12,
"exp_year": 2024,
"funding": "credit",
"last4": "1111",
"metadata": {},
"name": null,
"tokenization_method": "android_pay"
},
"client_ip": "blahblaj",
"created": 1664203858,
"livemode": false,
"type": "card",
"used": false
}
Gotcha. So you want your server to process the payment in this case?
I.e. create a payment intent and confirm all on server-side?
yes.
I didn't realise paymentIntents was the part that actually did the processing. I guess i've met a lot of people that intend to pay something and then don't :-p So didn't think this was how you actually trigger a payment.
Hi ๐ I'm stepping in for @willow rampart . The Payment Intent starts out as your intent to collect payment but it also serves as a state machine that captures the process of attempting to collect the payment.
Ok that makes sense.
Alright so are there any parts of your integration that you have additional questions on at this time?
so if i've called paymentMethod, what/how do i pass the output of that into payment intent?
const paymentMethod = await stripe.paymentMethods.create({type:"card",card:{token:token.toString()}});```
if i want to process the result of that, its not clear what to pass into paymentIntent?
Okay so you are creating the Payment Method on your server, correct?
In that scenario you would include the Payment Method ID in the .confirm() call to confirm the Payment Intent:
https://stripe.com/docs/api/payment_intents/confirm#confirm_payment_intent-payment_method
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
ok, so it looks like i can pass 'confirm:true' in the create method, or i can call each method in turn, create() then confirm().
This is great, thanks.