Skip to content

Commit

Permalink
Upgrade omise-node api to v2019 (#220)
Browse files Browse the repository at this point in the history
## Description
- Upgrade library to support API version 2019-05-29

### More information (if any) 

- Added setup to run the typescript examples
- Refactored example scripts
- Updated resource fields according to api v 2019-05-29

### Documentation (if any)

<!-- Link to the updated documentation, if any. Else, remove this
section. -->

### Related links:

<!-- Provide links, related issues, and PRs, if any. Else, remove this
section. -->

- Issue ID: <github-issue-id>

## Decision(s)

<!-- Describe any decisions you made in this PR using the following
template -->
<!-- E.g. In the context of Super New Feature, facing how to load the
required data,
we decided to use raw SQL, to achieve fastest performance, accepting
this is
       more code than if we had used the ORM.  -->

In the context of < use case / user story >, facing < concern > we
decided for < option > to achieve < quality / goal >, accepting <
downside >.

***NOTE: If the change introduces a new feature flag, please mention:
***
  - ***When / Conditions to remove feature flag***
  - ***Please add label "FeatureFlag" to feature flag removal story***
 
## Business impact (if any)

<!-- Describe the business impact if any. For example, rolling out the
change will involve a short downtime of an hour. Else, remove this
section -->
  
## Pre- or post-deployment steps (if any)

<!-- Describe the manual steps, if any, that need to be done before or
after the deployment. Else, remove this section. -->
 
## Rollback procedure

<!-- Describe the Rollback procedure. If none/default, update with
`default rollback procedure` -->
  • Loading branch information
gaurab13 authored Sep 17, 2024
1 parent ba666a1 commit a223a90
Show file tree
Hide file tree
Showing 125 changed files with 1,290 additions and 783 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OMISE_PUBLIC_KEY=""
OMISE_SECRET_KEY=""
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ yarn.lock
pids
*.pid
*.seed
.env

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
Expand Down
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@ From NPM
$ npm install omise
```

The library has been tested with Node version 4.4.6.

## Code Status

[![Node.js CI](https://github.com/omise/omise-node/actions/workflows/ci.yml/badge.svg)](https://github.com/omise/omise-node/actions/workflows/ci.yml)
[![Code Climate](https://codeclimate.com/github/omise/omise-node/badges/gpa.svg)](https://codeclimate.com/github/omise/omise-node)

## Version Guidance

This library offers maintenance support for 0.x and active development for 1.x. Please refer to the table for specific version compatibility and requirements.

| Version | Support | Omise API Version |
| --------| ----------------------- | ------------------|
| 0.x | Maintenance Mode | <= 2017-11-02 |
| 1.x | Active | &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2019-05-29 |

This library is designed to work with Node.js versions that are actively maintained by the Node.js project. We recommend following the official [Node.js Releases](https://nodejs.org/en/about/releases/) for selecting a Node.js version.

<sup><b>*Maintenance mode means bug fixes and security patches only.</b></sup>

## Usage

### Flow
Expand Down Expand Up @@ -75,6 +86,12 @@ For both methods, the client will directly send the card information to the Opn

## Examples

You can find example usage of this library inside the examples folder located at the root of the repository.
- **JavaScript Examples**: See the [examples/javascript](./examples/javascript) directory for examples written in JavaScript.
- **TypeScript Examples**: See the [examples/typescript](./examples/typescript) directory for examples written in TypeScript.

Some examples of library usage are also listed as follows:

### Create a customer with card associated to it

Creating a customer can be done by using `omise.customers.create` that accepts an optional `card` argument. When you pass in a `tokenId` retrieved from omise.js, the card associated to that token will be associated to the customer.
Expand Down
10 changes: 0 additions & 10 deletions examples/destroy_customer.js

This file was deleted.

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
12 changes: 12 additions & 0 deletions examples/javascript/capture_charge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

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

const chargeId = 'chrg_611rj6nuzljvtrudfks'
omise.charges.capture(chargeId, function(err, response) {
if (err) {
console.log('error', err);
return;
}
console.log(response)
});
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);
});
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
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
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
'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: {
'name': 'JOHN DOE',
'city': 'Bangkok',
'postal_code': 10160,
'number': '4532156433142865',
'expiration_month': 8,
'expiration_year': 2022,
name: "Gaurav",
number: "4242424242424242",
expiration_month: 2,
expiration_year: 2025,
security_code: "123",
},
};

Expand All @@ -23,13 +19,11 @@ omise.tokens.create(cardDetails, function(err, token) {
}

omise.charges.create({
amount: 10000,
amount: 900000,
currency: 'thb',
return_uir: 'http://example.com',
card: token.id,
metadata: {
note: 'test card',
},
capture: false,
}, function(err, charge) {
if (err) {
console.log('error', err);
Expand Down
20 changes: 20 additions & 0 deletions examples/javascript/create_recipient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

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

const recipientBody = {
name: 'Recipient name',
email: '[email protected]',
type: 'individual',
bank_account: {
bank_code: 'bbl',
number: '123456789',
name: 'Reci Pient',
},
};
omise.recipients.create(recipientBody, (err, resp) => {
if (err) {
console.log(err)
}
console.log(resp);
});
11 changes: 11 additions & 0 deletions examples/javascript/create_refund.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

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

const chargeId = 'chrg_611ra3ab9wmcrm5wmue';
omise.charges.createRefund(chargeId, { amount: 200000 }, function(err, resp) {
if(err) {
console.log(err)
}
console.log(resp);
});
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
34 changes: 34 additions & 0 deletions examples/javascript/create_token_charge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

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

let cardDetails = {
card: {
name: "Gaurav",
number: "4242424242424242",
expiration_month: 2,
expiration_year: 2025,
security_code: "123",
},
};

omise.tokens.create(cardDetails, function(err, token) {
if (err) {
console.log('error', err);
return;
}

omise.charges.create({
amount: 900000,
currency: 'thb',
return_uir: 'http://example.com',
card: token.id,
}, function(err, charge) {
if (err) {
console.log('error', err);
return;
}

console.log('charge', charge);
});
});
16 changes: 16 additions & 0 deletions examples/javascript/create_transfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

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

const reqBody = {
amount: 40000,
recipient: 'recp_60w95drhxsfzbkr89c4',
fail_fast: true
};

omise.transfers.create(reqBody, (err, resp) => {
if (err) {
console.log(err)
}
console.log(resp);
});
10 changes: 10 additions & 0 deletions examples/javascript/destroy_customer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

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

omise.customers.destroy('cust_60458v5p9fhyx3z4yp7', function(err, resp) {
if (err) {
console.log(err);
}
console.log(resp);
});
11 changes: 11 additions & 0 deletions examples/javascript/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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,
vaultHost: process.env.OMISE_VAULT_HOST,
});

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

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

omise.customers.listCards(
"cust_60dw2h7vc8pwuiy9hag",
{ order: "reverse_chronological" },
function (err, resp) {
if (err) {
console.log(err);
}
console.log(resp);
}
);
7 changes: 7 additions & 0 deletions examples/javascript/list_charges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

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

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

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

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

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

omise.schedules.retrieve((err, resp) => {
if (err) {
console.log('error', err);
return;
}
console.log(resp);
});
10 changes: 10 additions & 0 deletions examples/javascript/retrieve_balance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

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

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

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

omise.customers.retrieve('cust_60dw2h7vc8pwuiy9hag', function(err, resp) {
console.log(resp);
});
12 changes: 12 additions & 0 deletions examples/javascript/reverse_charge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

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

const chargeId = 'chrg_611rkd55yyxy6a8vs3c'
omise.charges.reverse(chargeId, function(err, response) {
if (err) {
console.log('error', err);
return;
}
console.log(response)
});
13 changes: 13 additions & 0 deletions examples/javascript/update_customer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"use strict";

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

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

omise.customers.update(
"cust_60dw2h7vc8pwuiy9hag",
updateParams,
function (err, resp) {
console.log(resp);
}
);
Loading

0 comments on commit a223a90

Please sign in to comment.