flutter_stripe
flutter_stripe copied to clipboard
Checkout is not giving callback for payments success or failure
I am getting only redirect callback in results variable. Once payment is success its redirecting to success url but I need callback for success in flutter web so that I can process this payment in our server.Please help me how can I get callback for success and failure in results variable
Checkout code.
final result = await redirectToCheckout(
context: context,
sessionId: sessionId,
publishableKey: public_key,
successUrl: 'https://www.stage.in/$paymentId',
canceledUrl: 'https://checkout.stripe.dev/cancel',
);
if (mounted) {
final text = result.when(
success: () => 'Paid succesfully',
canceled: () => 'Checkout canceled',
error: (e) => 'Error $e',
redirected: () => 'Redirected succesfully',
);
}
server code
app.post('/create-checkout-session', async (req, res) => {
const {
port,
}: { port?: string; } = req.body;
var effectivePort = port ?? 8080;
const { secret_key } = getKeys();
const stripe = new Stripe(secret_key as string, {
apiVersion: '2020-08-27',
typescript: true,
});
//const customers = await stripe.customers.list();
//const customer = customers.data[0];
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
billing_address_collection:"required",
line_items: [
{
description:"Stage monthly subscription",
price_data: {
currency: 'inr',
product_data: {
name: 'stage',
images: ['https://i.imgur.com/EHyR2nP.png'],
},
unit_amount: 2000,
},
quantity: 1,
},
],
mode: 'payment',
success_url: `https://www.stage.in`,
cancel_url: `https://checkout.stripe.dev/cancel`,
});
//console.log(session);
res.json({ id: session.id,payment_intent:session.payment_intent,url:session.url });
});
Hi. Found a solution ? Facing same situation. How to get back to the app (not success url) after checkout so we can read the redirectToCheckout stream to know when the payment is successfully done or cancel or error occured ?
@imofidul Found a solution? if yes, then please tell me how to work.
we provide a future that returns a checkoutresponse object