flutter_stripe icon indicating copy to clipboard operation
flutter_stripe copied to clipboard

Checkout is not giving callback for payments success or failure

Open imofidul opened this issue 2 years ago • 2 comments

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 });
});

imofidul avatar Apr 20 '22 06:04 imofidul

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 ?

daoibrahim avatar Jun 23 '22 17:06 daoibrahim

@imofidul Found a solution? if yes, then please tell me how to work.

DipakSkywave avatar Nov 09 '22 08:11 DipakSkywave

we provide a future that returns a checkoutresponse object

remonh87 avatar Jun 26 '23 18:06 remonh87