omise / omise-node

Omise Node.js Library
https://docs.opn.ooo
102 stars 53 forks source link

When trying to create resource omise.sources.create(source) giving me authentication failure error #97

Closed umerbaig closed 6 years ago

umerbaig commented 6 years ago

Hi, When i try to create internet banking resource omise.sources.create(source) then it is giving me authentication error rest of the API is working fine for example omise.charges.create() etc it is giving me authentication failure only when i use omise.sources.create(source)

omise: ^0.5.4 node: v8.11.3

my code is

const omise = require('omise')({
  'secretKey': 'my_secret_key',
  'omiseVersion': '2017-11-02'
});

let service = {};

service.createSource = function(type, amount, orderID) {
  const promise = new Promise((resolve, reject) => {
    const source = {
      type, 
      amount,
      currency: 'thb'
    };
    omise.sources.create(source, function(err, resSource) {
      if (err) {  
        return reject(err);
      }
      omise.charges.create({
        'description': `Charge for Order ID: ${orderID}`,
        'amount': amount, 
        'currency': 'thb',
        'source': resSource.id,
        'return_uri': 'http://www.example.com/orders/3947/complete'
      }, function(err, resp) {
        if (err) {
          return reject(err);
        }
        return resolve(resp);
      });
    });
  });
  return promise;
};
umerbaig commented 6 years ago
{ object: 'error',
  location: 'https://www.omise.co/api-errors#authentication-failure',
  code: 'authentication_failure',
  message: 'authentication failed' }
varshard commented 6 years ago

With source api, you have to use public key ie: pub_ as your secret key.

umerbaig commented 6 years ago

yes, it works with publicKey. Thank you!

varshard commented 6 years ago

@umerbaig Your welcome.