Skip to content

Commit b5e89d9

Browse files
committed
feat: update readme.md
1 parent c951a52 commit b5e89d9

File tree

8 files changed

+114
-73
lines changed

8 files changed

+114
-73
lines changed

README.MD

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
# Payment library #
1+
# Chip NodeJS library
22

3-
## Installing ##
3+
## Prerequisite
4+
Before you start, make sure you already have created `Brand ID` and `API Key` from your developer dashboard by logging-in into [merchant portal](https://gate.chip-in.asia/login).
45

5-
## npm ##
6+
## Installation
67

8+
### npm
79
```bash
810
npm install git+ssh://git@github.com/CHIPAsia/chip-nodejs-sdk.git#v1.0.0
911
```
1012

11-
## Getting Started ##
13+
### yarn
14+
```bash
15+
yarn add git+ssh://git@github.com/CHIPAsia/chip-nodejs-sdk.git#v1.0.0
16+
```
17+
18+
## Getting Started
1219

1320
Simple usage looks like:
1421

@@ -34,12 +41,11 @@ let callback = (error, data, response) => {
3441
apiInstance.paymentMethods(brandId, "EUR", {}, callback);
3542
```
3643

37-
## Examples ##
38-
39-
See `example.js` for more examples
40-
41-
## Testing ##
44+
## Testing
4245

4346
```bash
4447
npm run test
45-
```
48+
```
49+
50+
## Example
51+
Check our examples [here](./examples).

examples/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# misc
2+
.DS_STORE
3+
4+
# nodes
5+
node_modules/
6+
package-lock.json
7+
yarn.lock
8+
yarn-error.log

examples/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<div align="center">
2+
<a href="https://nodejs.org">
3+
<img
4+
alt="NodeJS"
5+
src="https://nodejs.org/static/images/logo.svg"
6+
width="150"
7+
style="background-color:black;padding:15px;border-radius:5px">
8+
</a>
9+
</div>
10+
11+
---
12+
13+
## Requirements
14+
* It is required `Node` version >= 14
15+
* `yarn` or `npm` to run scripts/install dependencies
16+
17+
## Prerequisite
18+
You will need to replace the value on file [config.js](./config.js) with the configuration on your Developer section by logging-in to Merchant Portal with your account.
19+
20+
```javascript
21+
// config.js
22+
const config = {
23+
brandId: '<<BRAND_ID>>',
24+
apiKey: '<<API_KEY>>',
25+
endpoint: 'https://gate.chip-in.asia/api/v1',
26+
basedUrl: '<<DOMAIN_URL>>',
27+
webhookPublicKey: '<<WEBHOOK_PUBLIC_KEY>>'
28+
}
29+
30+
module.exports = config
31+
```
32+
33+
**BRAND_ID**
34+
35+
Obtain your BRAND_ID from Developer section.
36+
37+
---
38+
**API_KEY**
39+
40+
Obtain your API_KEY from Developer section.
41+
42+
---
43+
44+
**WEBHOOK_PUBLIC_KEY**
45+
46+
Obtain your `WEBHOOK_PUBLIC_KEY` from Developer section. You can register the URL from [API](https://developer.chip-in.asia/api) or from Merchant Portal on Developer section.
47+
48+
---
49+
50+
**DOMAIN_URL**
51+
52+
It is your domain URL
53+
54+
## Run Example
55+
1. Install dependencies:
56+
```bash
57+
npm i
58+
59+
# OR
60+
61+
yarn
62+
```
63+
64+
2. Run application locally:
65+
```bash
66+
node run start
67+
68+
# OR
69+
70+
yarn start
71+
```
72+
73+
and visit [localhost:7001](http://localhost:7001) on your browser.
74+
To test `/api/callback` & `/api/webhook` to be called from our server, make sure it is connected to internet (exposed to outside).
75+
76+
We recommend to use [ngrok](https://ngrok.com/) if you want to run locally for debugging. Then You can replace `DOMAIN_URL` with generated URL by `ngrok`.
77+
78+
`NB: Use it at your own risk. Make sure do not expose your critical port.`

examples/app.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ app.get('/', async (req, res) => {
4949
})
5050
})
5151

52-
app.get('/payment_methods', async (req, res) => {
52+
app.get('/api/payment_methods', async (req, res) => {
5353
apiInstance.paymentMethods(brandId, "MYR", {}, function(error, data, response) {
5454
if (error) {
5555
console.log('API call failed. Error:', error)
@@ -61,7 +61,7 @@ app.get('/payment_methods', async (req, res) => {
6161
})
6262
})
6363

64-
app.get('/create_purchase', async (req, res) => {
64+
app.get('/api/create_purchase', async (req, res) => {
6565
const client = { email: 'test@test.com' }
6666
const product = { name: 'Test', price: 100 }
6767
const details = { products: [ product ] }
@@ -71,7 +71,7 @@ app.get('/create_purchase', async (req, res) => {
7171
purchase: details,
7272
success_redirect: `${basedUrl}/redirect.php?success=1`,
7373
failure_redirect: `${basedUrl}/redirect.php?success=0`,
74-
success_callback: `${basedUrl}/callback`
74+
success_callback: `${basedUrl}/api/callback`
7575
}
7676

7777
apiInstance.purchasesCreate(purchase, function(error, data, response) {
@@ -86,7 +86,7 @@ app.get('/create_purchase', async (req, res) => {
8686
})
8787
})
8888

89-
app.post('/callback', async (req, res) => {
89+
app.post('/api/callback', async (req, res) => {
9090
const { rawBody, headers } = req
9191
const xsignature = headers['x-signature']
9292
const publicKey = JSON.parse(await getPublicKey())
@@ -96,7 +96,7 @@ app.post('/callback', async (req, res) => {
9696
res.end()
9797
})
9898

99-
app.post('/webhook/payment', async (req, res) => {
99+
app.post('/api/webhook/payment', async (req, res) => {
100100
const { rawBody, headers } = req
101101
const parsed = JSON.parse(rawBody)
102102
const xsignature = headers['x-signature']
@@ -108,9 +108,9 @@ app.post('/webhook/payment', async (req, res) => {
108108
res.end("WEBHOOK OK!")
109109
})
110110

111-
app.get('/public_key', async (req, res) => {
111+
app.get('/api/public_key', async (req, res) => {
112112
const data = await getPublicKey()
113-
res.end(data)
113+
res.setHeader('Content-Type', 'application/json').end(JSON.parse(data))
114114
})
115115

116116
const getPublicKey = () => {

examples/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const config = {
22
brandId: '<<BRAND_ID>>',
33
apiKey: '<<API_KEY>>',
44
endpoint: 'https://gate.chip-in.asia/api/v1',
5-
basedUrl: '<<YOU_DOMAIN_URL>>',
5+
basedUrl: '<<DOMAIN_URL>>',
66
webhookPublicKey: '<<WEBHOOK_PUBLIC_KEY>>'
77
}
88

examples/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ <h1>Demo Merchant</h1>
55
<span>Sample Actions:</span>
66
<ul>
77
<li>
8-
<a href="/payment_methods" target="_blank">Get Payment Methods</a>
8+
<a href="/api/payment_methods" target="_blank">Get Payment Methods</a>
99
</li>
1010
<li>
11-
<a href="/create_purchase" target="_blank">Create Checkout</a>
11+
<a href="/api/create_purchase" target="_blank">Create Checkout</a>
1212
</li>
1313
<li>
14-
<a href="/public_key" target="_blank">Get Public Key</a>
14+
<a href="/api/public_key" target="_blank">Get Public Key</a>
1515
</li>
1616
</ul>
1717
</body>

examples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"author": "",
1212
"license": "ISC",
1313
"dependencies": {
14+
"Chip": "git+ssh://git@github.com/CHIPAsia/chip-nodejs-sdk.git#v1.0.0",
1415
"body-parser": "^1.20.1",
15-
"Chip": "github:CHIPAsia/chip-nodejs-sdk",
1616
"express": "^4.18.2"
1717
},
1818
"devDependencies": {

examples/yarn-error.log

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)