Skip to content

Instantly share code, notes, and snippets.

@tomykaira
Created July 14, 2016 03:19
Show Gist options
  • Save tomykaira/462a20ccb9b530ee3a79e9a96b2778d4 to your computer and use it in GitHub Desktop.
Save tomykaira/462a20ccb9b530ee3a79e9a96b2778d4 to your computer and use it in GitHub Desktop.
How to use webpay node module from typescript.
npm install -g typescript
mkdir test
npm install webpay
tsc test.ts
node test.js
/// <reference path="./typings/webpay/webpay.d.ts" />
import * as WebPay from "webpay";
var webpay = new WebPay('test_secret_eHn4TTgsGguBcW764a2KA8Yd');
webpay.charge.create({
amount: 400,
currency: "jpy",
card: "tok_SampleCardToken",
description: ""
}, function(err, res) {
console.log(err, res);
});
// place as typings/webpay/webpay.d.ts
declare interface WebPay {
charge: Charge;
}
declare interface Charge {
create: (params: any, callback: (err: any, res: any) => void) => void;
}
declare var WebPay: {
new (token: string): WebPay;
}
declare module 'webpay' {
export = WebPay;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment