Skip to content

Commit

Permalink
Fix example imports and types
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurab13 committed Sep 2, 2024
1 parent d407ded commit 7db87a3
Show file tree
Hide file tree
Showing 35 changed files with 239 additions and 263 deletions.
5 changes: 1 addition & 4 deletions examples/as_promises.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

let cardDetails = {
card: {
Expand Down
10 changes: 3 additions & 7 deletions examples/charge_schedule.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict';

// More information: https://www.omise.co/charge-schedules-api
let omise = require('../index')({
'publicKey': 'pkey_test_1234',
'secretKey': 'skey_test_1234',
});
const omise = require('./index');

// Charge every 2 days
let chargeEvery2Days = {
Expand All @@ -27,7 +23,7 @@ omise.schedules.create(chargeEvery2Days, function(err, schedule) {
}

// Print out schedules
console.log(schedule.next_occurrence_dates);
console.log(schedule.next_occurrences_on);
});

// Charge on eery Monday and Friday
Expand All @@ -54,5 +50,5 @@ omise.schedules.create(monthlyCharge, function(err, schedule) {
}

// Print out schedules
console.log(schedule.next_occurrence_dates);
console.log(schedule.next_occurrences_on);
});
5 changes: 1 addition & 4 deletions examples/create_customer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

let customer = {
email: '[email protected]',
Expand Down
5 changes: 1 addition & 4 deletions examples/create_link.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

let link = {
'amount': 19000,
Expand Down
5 changes: 1 addition & 4 deletions examples/create_recipient.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

const recipientBody = {
name: 'Recipient name',
Expand Down
8 changes: 2 additions & 6 deletions examples/create_source_charge.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
'use strict';

exports.__esModule = true;
const omise = require('./index');

let amount = 500000;
let currency = 'thb';
let omise = require('../index')({
'publicKey': process.env.OMISE_PUBLIC_KEY,
'secretKey': process.env.OMISE_SECRET_KEY,
});

let source = {
'type': 'internet_banking_bbl',
'amount': 500000,
Expand Down
5 changes: 1 addition & 4 deletions examples/create_token_charge.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

let cardDetails = {
card: {
Expand Down
6 changes: 1 addition & 5 deletions examples/create_transfer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict';

let omise = require('../index')({
'publicKey': 'pkey_test_1234',
'secretKey': 'skey_test_1234',
});

const omise = require('./index');

const reqBody = {
amount: 40000,
Expand Down
10 changes: 5 additions & 5 deletions examples/destroy_customer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

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

omise.customers.destroy('cust_test_4yxn6vblxh83h605oxz', function(err, resp) {
omise.customers.destroy('cust_60458v5p9fhyx3z4yp7', function(err, resp) {
if (err) {
console.log(err);
}
console.log(resp);
});
10 changes: 10 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const dotenv = require("dotenv");
dotenv.config();

const omise = require("../index")({
publicKey: process.env.OMISE_PUBLIC_KEY,
secretKey: process.env.OMISE_SECRET_KEY,
host: process.env.OMISE_NODE_HOST,
});

module.exports = omise;
20 changes: 11 additions & 9 deletions examples/list_cards.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';
"use strict";

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

omise.customers.listCards('cust_test_53reuowpjglur236wm7',
{'order': 'reverse_chronological'},
function(e, resp) {
omise.customers.listCards(
"cust_60dw2h7vc8pwuiy9hag",
{ order: "reverse_chronological" },
function (err, resp) {
if (err) {
console.log(err);
}
console.log(resp);
});
}
);
5 changes: 1 addition & 4 deletions examples/list_charges.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict';

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

omise.charges.list({limit: 2}, function(err, resp) {
console.log(resp);
Expand Down
7 changes: 2 additions & 5 deletions examples/list_customers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict';

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

omise.customers.list(function(err, resp) {
omise.customers.list({limit: 2}, function(err, resp) {
console.log(resp);
});
7 changes: 7 additions & 0 deletions examples/list_recipients.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const omise = require('./index');

omise.recipients.list({limit: 2}, function(err, resp) {
console.log(resp);
});
7 changes: 2 additions & 5 deletions examples/retrieve_balance.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
'use strict';

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

omise.balance.retrieve((err, resp) => {
if (err) {
console.log(err)
console.log(err);
}
console.log(resp);
});
7 changes: 2 additions & 5 deletions examples/retrieve_customer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
'use strict';

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

omise.customers.retrieve('cust_test_4z33o46lqreryhqua8w', function(err, resp) {
omise.customers.retrieve('cust_60dw2h7vc8pwuiy9hag', function(err, resp) {
console.log(resp);
});
18 changes: 9 additions & 9 deletions examples/update_customer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';
"use strict";

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

let updateParams = {description: 'the other description'};
let updateParams = { description: "the other description" };

omise.customers.update('cust_test_4z2owmajzsb3c527wj7', updateParams,
function(err, resp) {
omise.customers.update(
"cust_60dw2h7vc8pwuiy9hag",
updateParams,
function (err, resp) {
console.log(resp);
});
}
);
25 changes: 10 additions & 15 deletions types/examples/as_promises.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
import omise = require('../index');
import { Charges, Customers, Tokens } from "../index";
import omise from "./index";

let cardDetails: omise.Tokens.IRequest;
cardDetails = {
const cardDetails:Tokens.IRequest = {
card: {
city: 'Bangkok',
expiration_month: 2,
expiration_year: 2017,
expiration_year: 2027,
name: 'JOHN DOE',
number: '4242424242424242',
postal_code: '10320',
security_code: '130',
},
};

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

omiseStatic.tokens.create(cardDetails).then((token) => {
return omiseStatic.customers.create({
omise.tokens.create(cardDetails).then((token: Tokens.IToken) => {
return omise.customers.create({
card: token.id,
description: 'John Doe (id: 30)',
email: '[email protected]',
});
}).then((customer) => {
return omiseStatic.charges.create({
}).then((customer: Customers.ICustomer) => {
return omise.charges.create({
amount: 10000,
currency: 'thb',
customer: customer.id,
});
}).then((charge) => {
}).then((charge: Charges.ICharge) => {
console.log(charge);
}).catch((err) => {
}).catch((err: Error | null) => {
console.log(err);
});
44 changes: 21 additions & 23 deletions types/examples/charge_schedule.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import omise = require('../index');
import { Schedules } from "../index";
import omise from "./index";

const chargeEvery2Days = {
every: 2,
const chargeEvery2Days: Schedules.ICreateSchedule = {
every: 5,
period: 'day',
start_date: '2018-01-01',
end_date: '2018-12-01',
start_date: '2024-11-01',
end_date: '2024-12-24',
charge: {
customer: 'cust_test_57m2wcnfx96k634rkqq',
card: 'card_test_57m2w8iemdovs4f92m2',
amount: 1000000,
description: 'Membership fee',
customer: 'cust_60dw2h7vc8pwuiy9hag',
card: 'card_60dw2h37jxtw38wk355',
amount: 100000,
description: 'Membership fee 2',
},
};

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

omiseStatic.schedules.create(chargeEvery2Days, (err, resp) => {
console.log(resp.next_occurrence_dates);
omise.schedules.create(chargeEvery2Days, (err: Error | null, resp: Schedules.ISchedule) => {
if (err) {
console.log('error', err);
return;
}
console.log(resp.next_occurrences_on);
});

const monthlyCharge = {
const monthlyCharge: Schedules.ICreateSchedule = {
every: 1,
period: 'month',
start_date: '2018-01-01',
end_date: '2018-12-01',
start_date: '2024-11-01',
end_date: '2025-06-24',
on: {
days_of_month: [1],
},
Expand All @@ -38,12 +38,10 @@ const monthlyCharge = {
},
};

omiseStatic.schedules.create(monthlyCharge, (err, schedule) => {
omise.schedules.create(monthlyCharge, (err: Error | null, schedule: Schedules.ISchedule) => {
if (err) {
console.log('error', err);
return;
}

// Print out schedules
console.log(schedule.next_occurrence_dates);
console.log(schedule.next_occurrences_on);
});
13 changes: 6 additions & 7 deletions types/examples/create_customer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import omiseNode = require('../index');

const omise = omiseNode({
publicKey: process.env.OMISE_PUBLIC_KEY,
secretKey: process.env.OMISE_SECRET_KEY,
});
import omise from "./index";
import { Customers } from "../index";

const customer = {
description: 'John Doe (id: 30)',
email: '[email protected]',
};

omise.customers.create(customer, (err, resp) => {
omise.customers.create(customer, (err: Error | null, resp: Customers.ICustomerList) => {
if (err) {
console.log(err);
}
console.log(resp);
});
Loading

0 comments on commit 7db87a3

Please sign in to comment.