Can't create charge on nodejs backend


#1

Hi there,

I am trying to learn how to integrate omise in React (frontend), Node and Express (backend) applicationI (use omise-node ). I finished testing the credit card payment with Omise pre-built payment form, it works just fine. I got token in frontend and sent token to create charge in backend, and I got transfer in my test dashboard.
However, when I tried the internet banking (pre-built form also), it didn’t work. I got source key (which start with “src_test_xxxxxxx” in frontend, I sent it to backend, but I got error " message: ‘token src_test_5eyypeposqoqezff28w was not found’"

Here is my code in node backend.

const omise = require('omise')({
  publicKey: process.env.OMISE_PUBLIC_KEY,
  secretKey: process.env.OMISE_SECRET_KEY
});
.....

app.post('/internet-banking', async (req, res, next) => {
  console.log(req);
  try {
    const { name, amount, source } = req.body;

    const customer = await omise.customers.create({
      email: 'test@test.com',
      description: `${name}, id (123)`,
      card: source
    });

    console.log('Customer -->', customer)

    const charge = await omise.charges.create({
      amount,
      source,
      currency: 'thb',
      return_uri: 'http://localhost:3000'
    });

    console.log('Charge -->', charge)

    res.send({
      charge: {
        status: charge.status,
        amount: `${charge.amount / 100} ${charge.currency}`
      }
    });
  } catch (err) {
    console.log(err);
  }
  next();
})
....

Here is the log from my console.

 body:
   { name: 'Autsada T',
     amount: 10000,
     source: 'src_test_5eyypeposqoqezff28w' },
  _body: true,
  length: undefined,
  route:
   Route {
     path: '/internet-banking',
     stack: [ [Layer] ],
     methods: { post: true } } }
{ object: 'error',
  location: 'https://www.omise.co/api-errors#not-found',
  code: 'not_found',
  message: 'token src_test_5eyypeposqoqezff28w was not found' }

In the post request body, you can see it has all I need to create charge - amount, source.
I tried to search around, but couldn’t find solution.
Could you please help?

Autsada


#2

Hi Autsada,

The Customer API can be used only for saved card, which means you can create a customer by using a token only.

Please kindly take a look the API description on how create a customer by this link. (https://www.omise.co/customers-api)

Thank you!


#3

Dear K. big,

Thank you krub for your quick reply, it works now.

Just to confirm my understanding, we can’t create customer in other payment methods except credit card, is that right? It is, by the way, not a big problem cuz I can create customer data by other way.


#4

Your understanding is correct krub :slight_smile:


#5

Thank you very much krub.


#6

Dear K.big,

One more question krub, how do I check internet banking payment transaction in dashboard, now the charge object shows status “pending” and I don’t see transaction in my dashboard.

Charge IB --> { object: 'charge',
  id: 'chrg_test_5ez0sfbv07lhb10uudb',
  livemode: false,
  location: '/charges/chrg_test_5ez0sfbv07lhb10uudb',
  amount: 25000,
  currency: 'thb',
  funding_amount: 25000,
  funding_currency: 'thb',
  description: null,
  metadata: {},
  status: 'pending',

I logged the charge data out in my console as shown above.

Thank you.


#7

Could you please share a screenshot of your dashboard krub?

Please follow my instruction by below…

  1. Log in to https://dashboard.omise.co with your Omise account.
  2. Click Charges menu on the left-hand side under Transactions topic. (https://dashboard.omise.co/test/charges)
  3. Capture your screen on this page.

#8

Ok krub.

I saw it already. thank you very much.


#9

You’re welcome :slight_smile: