Implementing omise-node in Ionic 2
Closed this issue · 3 comments
I'm creating a hybrid mobile app with payment feature using Ionic 2 framework. I tried omise.js via CDN which worked perfectly when serving in desktop browser (using ionic serve
command). However, when I run the app on actual device (in this case, iPhone) the Omise.createToken() gave request timeout error.
After some searching I found a hint in an omise.js issue that omise-node should work with hybrid mobile apps and can be installed via NPM. So I tried importing the module like following:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import Omise from 'omise';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController) {
var omise = new Omise({
'publicKey': MY_PUBLIC_KEY
});
}
}
This results in the following error:
ERROR Error: Uncaught (in promise): Error: Cannot find module "."
Error: Cannot find module "."
at d (polyfills.js:3)
at webpackMissingModule (main.js:136768)
at resourceName (main.js:136768)
at Object.module.exports.omiseResources (main.js:136799)
at new module.exports (main.js:136649)
at new HomePage (main.js:58694)
at createClass (main.js:11066)
at createDirectiveInstance (main.js:10905)
at createViewNodes (main.js:12255)
at createRootView (main.js:12160)
at callWithDebugContext (main.js:13291)
at Object.debugCreateRootView [as createRootView] (main.js:12752)
at ComponentFactory_.create (main.js:10096)
...
Since Omise
is not undefined, I think the problem is omise-node's index.js couldn't get reference from another file by require() function. I know it is not exactly this repo's issue but I hope someone who had done this successfully might be able to point out what did I do wrong here.
+1
I found the solutions. :)
In /node_modules/omise/lib/apiResources.js
change function resourceName like below
function resourceName(name) { return require('./resources/'+name)(omiseConfig); }
@tchinlapha Nice! Thanks for the solution.
I completely forgot about this issue after I ended up using basic POST request on my project.
Also, I've just found there're a pending pull request (#57) that resolves this exact issue long time ago. I hope the PR would be merged soon for the sake of people who would face this issue in the future.