#UnrealPlayer

1 messages · Page 1 of 1 (latest)

thin pikeBOT
winged rose
#

what was the exact code you used and that resulted in that error message?

wooden pilot
#

Here is the code

console.log("cancel reader");
  let body = JSON.parse(req.body);
  console.log(`body: ${body}`);
  console.log(`serial: ${body["serial_number"]}`);
  console.log(`Cancel Reader Action with serial: ${body.serial_number}`);
  if (!body?.serial_number) {
    res.status(400).json({ message: "serial_number is required" });
    return;
  }
  try {
    const response = await fetch2.default(
      "https://api.stripe.com/v1/terminal/readers?limit=3",
      {
        headers: {
          Authorization:
            "Basic " +
            Buffer.from(
              `${process.env.STRIPE_SECRET_KEY}:`
            ).toString("base64"),
        },
      }
    );
    if (response.status == 200) {
      var readerObj;
      let b : any = await response.json();

      for (var i = 0; i < b.data?.length ?? 0; i++) {
        let e = b.data[i];
        if (e.serial_number == body.serial_number) {
          readerObj = e;
          break;
        }
      }
      if (readerObj) {
        try {
          let reader = stripe.terminal.readers.cancelAction(readerObj.id);
          res.send({ reader });
        } catch (e: any) {
          console.log(e);
          res.send({ error: { message: e.message } });
        }
      } else {
        res.status(404).json({
          message: `Couldn't find any reader with serial number: ${body.serial_number}`,
        });
        return;
      }
    } else {
      res.sendStatus(response.status);
      return;
    }
  } catch (ex) {
    console.log(ex);
    res.sendStatus(500);
  }
winged rose
#

thanks. I'll have a look, but probably the M2 just doesn't support this so there isn't really a workaround, it's just not a supported flow

wooden pilot
#

here it is req_yFzkMjzwSBPaye

winged rose
#

hmm, well was the reader actually doing something when you called this?

wooden pilot
#

waiting for the card

winged rose
#

in the code you are list listing all your readers and calling cancel on them , but as far as I can tell we would return this error message if there is "nothing to cancel"

wooden pilot
#

I am not calling on all readers

#

I am finding my reader and only calling cancel on that reader

winged rose
#

ah ok

#

are you sure it's processing a payment? Like I'm looking at your API logs and I don't see any calls to v1/terminal/readers/tmr_xxx/process_payment_intent ,but will look again

wooden pilot
#

it is not processing payment, it is waiting for the customer card swipe

#

I can only cancel before customer swipe his/her card

#

process payment is the next step, aint it?

winged rose
#

is the confusion that you're using our mobile SDKs with M2 for collecting payment info and processing payment, but the server-driven APIs for cancelling?

#

yeah that's the issue, sorry for the confusion from my colleague, you were shown the wrong docs

wooden pilot
#

Yeah, great!
Thanks

#

Also, Please add these things somewhere

#

I searched a lot for how to cancel the payment and wasted a lot of time.

#

Thanks for the quick support 🙂