From 3c2f179f7947800b8ea89d3d37b5026d92ca3c5b Mon Sep 17 00:00:00 2001 From: Latif Boussari Date: Fri, 5 Apr 2019 09:08:24 +0100 Subject: [PATCH 01/14] initialize api with object --- .DS_Store | Bin 6148 -> 8196 bytes lib/.DS_Store | Bin 0 -> 6148 bytes lib/http.js | 5 ++++- lib/index.js | 5 ++--- lib/opts.js | 2 +- lib/transaction/index.js | 44 +++++++++++++++++++++++++++----------- sample/index.js | 14 ++++++++---- tests/transaction.test.js | 9 +++++++- 8 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 lib/.DS_Store diff --git a/.DS_Store b/.DS_Store index e2f14eac3115710f7beebc7fdd768b320c08baa1..29907bb45002629a0baa7a27e760207e45100e50 100644 GIT binary patch delta 720 zcmc(d&r1S96vyBGP)D;;k@9FkH>+J@u?|5P9Xur%6;#-6yVTaUWA2)inI1fLk)fb& z75xDrbm=eX)UiLMOHglh>(D(KnE8I+%$vu|hu48La#dXh@GQaUX>6c#G}4(G z;}VaBXQ7)WAHsczkWNeF5-ciigoj`s3~<0@QgEE-RkkiFO#v)0LDOnZS+l5ybzZcx zWjd}Ty>YxC27*{4LL!5at>PZ76Iytqn;Y9`2-P3%(LaFuRRc+NYYNc3mk=m|m z+D4^!+0+e8*<3Sioz`-+YU@p>SE$%OAtX$~rC6$7pUEnjv@FYwOu9a&%x2PAMQJp` zWOPEF&u<@|oYv18=hygJ930nI820sBZqWGuJ1$mii`u)m<7G#|1`0YD>`I)Ti9;Dw z*ntCFcM;JfGNHYA3XwVJ?Yu>Id_FM%{*^t64{SOx*!(YWKDXwdfeYftRX9X678t+q z1;Fih5_FBg9sk(6;Nn7`dTIc5$?L{$oV*KcIGJb5Q9_Wq*Qmfs(aR9|?2X$a;S07I Bx1#_6 delta 120 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jGxXU^g=(&tx8f=*f!()F$r} zw3uumG;Q)vVeZYhgcmX`X6N7#WCrR00s(Fy;R@2cvG6kWmaw5Mx0$F>H?K HnZpbKolO>_ diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5b1d078a5eb153d2e62dc67170d4593362b80fde GIT binary patch literal 6148 zcmeHK-D(p-6h6~NGf5D0A+(osQ}7~47YS8FSYo~Cov_kgsIxRi{G^zlf_Nbk=D?Zn?96v&Io~ofJ4D1f!`LHg5)p?htklsgF*UAy z!Paa~70C1)1tlaYqbKxvf$ch+0#1SdO#!ub8}yNeShdIW`})oIQh6MuG6F+w4=>=4 zueBi}s!|X9g8F*3&$BP)*c>}UMlp5ibQzy*%<-$(NBWpOU&=n4V>iGYP>46=Xm9J7 zt$$mau$&YiC24mQUwLP>rg`WuS5a}csWU0(P zficaVW;tAG1?=bMjg_v_73UOi3jB=%YJU)Lg}%kopx!#r=qmuQf^Kby)z5;;5f*)m zr9q6qm`MeiRA#Rj%%r1VSe|dOG-%R^*~$380jI!9DZnbb!EOg7*|T+_ICa(v_z_&0;*|z<3L1MH>p&gFn{aIy Y6Dk1u7E6QZfw><6ErV;E0{>Kj8;E?EBLDyZ literal 0 HcmV?d00001 diff --git a/lib/http.js b/lib/http.js index 21feb09..9a6570c 100644 --- a/lib/http.js +++ b/lib/http.js @@ -2,7 +2,10 @@ const axios = require('axios'); const opts = require('./opts') const http = axios.create({ - baseURL: opts.baseURL + baseURL: opts.baseURL, + headers: { + 'Content-Type': 'application/json' + } }) module.exports = http \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index d6489a8..22a520d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,3 +1,2 @@ -module.exports = { - transaction: require('./transaction'), -} \ No newline at end of file +const transaction = require('./transaction') +module.exports = transaction \ No newline at end of file diff --git a/lib/opts.js b/lib/opts.js index d8d91a7..699be6c 100644 --- a/lib/opts.js +++ b/lib/opts.js @@ -1,4 +1,4 @@ module.exports={ - baseURL: "https://api.kkiapay.me", + baseURL: "https://api-dev.kkiapay.me", transactionEndpoint: '/api/v1/transactions/status', } \ No newline at end of file diff --git a/lib/transaction/index.js b/lib/transaction/index.js index eea1f80..1327382 100644 --- a/lib/transaction/index.js +++ b/lib/transaction/index.js @@ -3,20 +3,38 @@ const opts = require('../opts') const { validateOptions }=require("../function") -module.exports = async function(options){ - const { transactionId,publickey,privatekey,secretkey } = validateOptions(options); - const headers = { - "Content-Type": "application/json", - "x-api-key": publickey // todo doit être change après que la police de contrôle soit activé - }; - return http.post(opts.transactionEndpoint, - {transactionId}, - {headers}) +module.exports = function (config) { + validateOptions(config) + http.defaults.headers.common['x-api-key'] = config.publickey; + http.defaults.headers.common['x-secret-api-key'] = config.secretkey; + http.defaults.headers.common['x-private-api-key'] = config.privatekey; + + return features +} - .then((response) => { - return response.data - }).catch((error) => { - throw new Error("Transaction Not Found"); + +const features={ + + verify: async (transactionId) => { + + return http.post(opts.transactionEndpoint, + {transactionId}) + + .then((response) => { + return response.data + }).catch((error) => { + console.log(error.response.data) + + if(error.response.data===4003) + { + throw new Error(error.response.data.reason) + } + else + { + throw new Error("Transaction Not Found") + } }) + + } } \ No newline at end of file diff --git a/sample/index.js b/sample/index.js index 1890489..d77f66c 100644 --- a/sample/index.js +++ b/sample/index.js @@ -1,7 +1,13 @@ -const kkiapay=require("../index") +const kkiapay=require("../lib") -kkiapay.transaction({ transactionId:"RUYnpqsSQ1",privatekey:process.env.privatekey,publickey:process.env.publickey,secretkey:process.env.secretkey}). -then(response => console.log(response)). -catch(err => console.log(err)) +let k=kkiapay({ publickey:"42051160403a11e98f723752f967fed2",privatekey:"hjk",secretkey:"gvhjb"}) + +k.verify("JkgWE6DO2C"). +then(e=>console.log(e)). +catch(err=>console.log(err)) + +// kkiapay.transaction({ transactionId:"JkgWE6DO2C",privatekey:"",publickey:"42051160403a11e98f723752f967fed2",secretkey:""}). +// then(response => console.log(response)). +// catch(err => console.log(err)) diff --git a/tests/transaction.test.js b/tests/transaction.test.js index 6e1602d..67d74f5 100644 --- a/tests/transaction.test.js +++ b/tests/transaction.test.js @@ -1,5 +1,11 @@ require ("babel-polyfill"); -const transaction = require('../lib/transaction'); +const options = { + privatekey:"12345", + publickey:"1234", + secretkey:"1234", + transactionId:"123456" +}; +const transaction = require('../lib/transaction')(options).verify; const changeStatus = require('./__Mock__/http') @@ -9,6 +15,7 @@ describe("transaction verify test",() => { changeStatus(true); transaction({ transactionId:"RUYnpqsSQ1",privatekey:process.env.privatekey,publickey:process.env.publickey,secretkey:process.env.secretkey}) .then((data) => { + console.log(data) expect(data).toMatchObject({}) done() }) From 6272cde7db9034aab4ef8c2916ea0a9e106199f3 Mon Sep 17 00:00:00 2001 From: Latif Boussari Date: Fri, 5 Apr 2019 09:10:39 +0100 Subject: [PATCH 02/14] add sample file --- sample/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sample/index.js b/sample/index.js index d77f66c..8bcc97a 100644 --- a/sample/index.js +++ b/sample/index.js @@ -7,7 +7,5 @@ k.verify("JkgWE6DO2C"). then(e=>console.log(e)). catch(err=>console.log(err)) -// kkiapay.transaction({ transactionId:"JkgWE6DO2C",privatekey:"",publickey:"42051160403a11e98f723752f967fed2",secretkey:""}). -// then(response => console.log(response)). -// catch(err => console.log(err)) + From 3d3c241a48b42e1a94f4cc13180d90ccf84f8511 Mon Sep 17 00:00:00 2001 From: Latif Boussari Date: Fri, 5 Apr 2019 09:14:55 +0100 Subject: [PATCH 03/14] update readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18f1b42..c9105ab 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,9 @@ Using cdn: Request to retrieve transactions ```js -kkiapay.transaction({ transactionId:"xxxxxx",privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}). +// setup your api key (find one at https://www.kkiapay.me) +const k = kkiapay("") +k.verify({ transactionId:"xxxxxx",privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}). then((response) => { //handle response }). From b4c707d31a623e827818653351f0e56a1a0f0fbc Mon Sep 17 00:00:00 2001 From: lephenix1234 <38128001+lephenix1234@users.noreply.github.com> Date: Fri, 5 Apr 2019 09:15:54 +0100 Subject: [PATCH 04/14] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c9105ab..1251251 100644 --- a/README.md +++ b/README.md @@ -35,11 +35,11 @@ Request to retrieve transactions ```js // setup your api key (find one at https://www.kkiapay.me) const k = kkiapay("") -k.verify({ transactionId:"xxxxxx",privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}). +k.verify({ privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}). then((response) => { //handle response }). catch((error) => { //handle error }) -``` \ No newline at end of file +``` From 0776efa4b1b1752ca3eff55bee30bf58499dfdd8 Mon Sep 17 00:00:00 2001 From: lephenix1234 <38128001+lephenix1234@users.noreply.github.com> Date: Fri, 5 Apr 2019 09:24:36 +0100 Subject: [PATCH 05/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1251251..aebc8f7 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Using npm: ```bash -$ npm i -s kkiapay +$ npm i -s kkiapay/nodejs-sdk ``` From e65d6dc676eb4f128896d3e304222490744d2093 Mon Sep 17 00:00:00 2001 From: lephenix1234 <38128001+lephenix1234@users.noreply.github.com> Date: Fri, 5 Apr 2019 09:26:12 +0100 Subject: [PATCH 06/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aebc8f7..db6dca8 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Using cdn: Request to retrieve transactions ```js -// setup your api key (find one at https://www.kkiapay.me) +// setup your api key (https://www.kkiapay.me) const k = kkiapay("") k.verify({ privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}). then((response) => { From 632f5e633e270b6922143f2ccf45b42f99469fae Mon Sep 17 00:00:00 2001 From: lephenix1234 <38128001+lephenix1234@users.noreply.github.com> Date: Wed, 17 Apr 2019 17:19:10 +0100 Subject: [PATCH 07/14] Update index.js --- sample/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/index.js b/sample/index.js index 8bcc97a..381fa6c 100644 --- a/sample/index.js +++ b/sample/index.js @@ -1,9 +1,9 @@ const kkiapay=require("../lib") -let k=kkiapay({ publickey:"42051160403a11e98f723752f967fed2",privatekey:"hjk",secretkey:"gvhjb"}) +let k=kkiapay({ publickey:"process.env.publickey",privatekey:"process.env.privatekey",secretkey:"process.env.secretkey"}) -k.verify("JkgWE6DO2C"). +k.verify("xxxxxx"). then(e=>console.log(e)). catch(err=>console.log(err)) From 3eb59cf3a9868744d71743b63f8a9abb07690cb3 Mon Sep 17 00:00:00 2001 From: lephenix1234 <38128001+lephenix1234@users.noreply.github.com> Date: Wed, 17 Apr 2019 17:21:26 +0100 Subject: [PATCH 08/14] Update opts.js --- lib/opts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/opts.js b/lib/opts.js index 699be6c..c314e3d 100644 --- a/lib/opts.js +++ b/lib/opts.js @@ -1,4 +1,4 @@ module.exports={ - baseURL: "https://api-dev.kkiapay.me", + baseURL: "https://api.kkiapay.me", transactionEndpoint: '/api/v1/transactions/status', -} \ No newline at end of file +} From 997e3d6c89df643c6ad071a3a8537b9f6dd6be5c Mon Sep 17 00:00:00 2001 From: lephenix1234 <38128001+lephenix1234@users.noreply.github.com> Date: Wed, 17 Apr 2019 17:25:09 +0100 Subject: [PATCH 09/14] Update index.js --- sample/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample/index.js b/sample/index.js index 381fa6c..c6bfa6d 100644 --- a/sample/index.js +++ b/sample/index.js @@ -3,7 +3,7 @@ const kkiapay=require("../lib") let k=kkiapay({ publickey:"process.env.publickey",privatekey:"process.env.privatekey",secretkey:"process.env.secretkey"}) -k.verify("xxxxxx"). +k.verify("AN5uUl574Z"). then(e=>console.log(e)). catch(err=>console.log(err)) From 1d154243f4e11437f78311b195de122aeea5a389 Mon Sep 17 00:00:00 2001 From: Boussari Latif Date: Thu, 27 Jun 2019 12:26:15 +0100 Subject: [PATCH 10/14] add sandbox environnement --- sample/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/index.js b/sample/index.js index c6bfa6d..0ea5279 100644 --- a/sample/index.js +++ b/sample/index.js @@ -1,9 +1,9 @@ const kkiapay=require("../lib") -let k=kkiapay({ publickey:"process.env.publickey",privatekey:"process.env.privatekey",secretkey:"process.env.secretkey"}) +let k=kkiapay({publickey:"f774e960812811e99cf7e73f32bcec42",privatekey:"process.env.privatekey",secretkey:"process.env.secretkey",sandbox:true}) -k.verify("AN5uUl574Z"). +k.verify("O_S9_rdlX"). then(e=>console.log(e)). catch(err=>console.log(err)) From aee27df31d1bbd6b83764a313735c1f7173ea685 Mon Sep 17 00:00:00 2001 From: Boussari Latif Date: Thu, 27 Jun 2019 12:33:01 +0100 Subject: [PATCH 11/14] add sandbox url --- README.md | 19 ++++++++++++++++--- lib/function.js | 4 ---- lib/http.js | 4 ++-- lib/opts.js | 1 - lib/transaction/index.js | 5 +++-- tests/function.test.js | 5 ----- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index db6dca8..a4f76dd 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,25 @@ Using cdn: ## Example -Request to retrieve transactions +Request to retrieve transactions in production ```js // setup your api key (https://www.kkiapay.me) -const k = kkiapay("") -k.verify({ privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}). +const k = kkiapay({privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}) +k.verify("transactionId"). +then((response) => { + //handle response +}). +catch((error) => { + //handle error +}) +``` + +Request to retrieve transactions in sandbox + +```js +const k = kkiapay({privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx",sandbox:true}) +k.verify("transactionId"). then((response) => { //handle response }). diff --git a/lib/function.js b/lib/function.js index 144d9a8..59719b2 100644 --- a/lib/function.js +++ b/lib/function.js @@ -6,10 +6,6 @@ const validateOptions=(options)=>{ throw new Error("parameter must be a object"); } - if(!(options.hasOwnProperty("transactionId"))) - { - throw new Error("transactionId is required"); - } if(!(options.hasOwnProperty("privatekey"))) { diff --git a/lib/http.js b/lib/http.js index 9a6570c..16936eb 100644 --- a/lib/http.js +++ b/lib/http.js @@ -1,8 +1,8 @@ const axios = require('axios'); -const opts = require('./opts') +// const opts = require('./opts') const http = axios.create({ - baseURL: opts.baseURL, + // baseURL: opts.baseURL, headers: { 'Content-Type': 'application/json' } diff --git a/lib/opts.js b/lib/opts.js index c314e3d..0ed1d12 100644 --- a/lib/opts.js +++ b/lib/opts.js @@ -1,4 +1,3 @@ module.exports={ - baseURL: "https://api.kkiapay.me", transactionEndpoint: '/api/v1/transactions/status', } diff --git a/lib/transaction/index.js b/lib/transaction/index.js index 1327382..4f5e85e 100644 --- a/lib/transaction/index.js +++ b/lib/transaction/index.js @@ -8,7 +8,8 @@ module.exports = function (config) { http.defaults.headers.common['x-api-key'] = config.publickey; http.defaults.headers.common['x-secret-api-key'] = config.secretkey; http.defaults.headers.common['x-private-api-key'] = config.privatekey; - + http.defaults.baseURL = config.sandbox ? "https://api-sandbox.kkiapay.me" : "https://api.kkiapay.me" + return features } @@ -25,7 +26,7 @@ const features={ }).catch((error) => { console.log(error.response.data) - if(error.response.data===4003) + if(error.response.status===4003) { throw new Error(error.response.data.reason) } diff --git a/tests/function.test.js b/tests/function.test.js index 806ad90..28c16f0 100644 --- a/tests/function.test.js +++ b/tests/function.test.js @@ -37,11 +37,6 @@ describe('Validation of transaction parameters',() => { ).toThrow(); }); - it('must trow exception when transactionId is not specify', () => { - expect(() => - validateOptions(omit('transactionId')) - ).toThrow(); - }); it('must trow exception when transactionId is not specify', () => { expect(validateOptions(omit(''))).toMatchObject(options) From 1cb3f3bb72418b9bae0f7c6a198c374b1fafaccc Mon Sep 17 00:00:00 2001 From: Boussari Latif Date: Thu, 27 Jun 2019 12:45:10 +0100 Subject: [PATCH 12/14] update readme --- README.md | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a4f76dd..8f23169 100644 --- a/README.md +++ b/README.md @@ -34,19 +34,10 @@ Request to retrieve transactions in production ```js // setup your api key (https://www.kkiapay.me) +//initialize kkiapay in production environnment const k = kkiapay({privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}) -k.verify("transactionId"). -then((response) => { - //handle response -}). -catch((error) => { - //handle error -}) -``` +//initialize kkiapay in sandbox environnment -Request to retrieve transactions in sandbox - -```js const k = kkiapay({privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx",sandbox:true}) k.verify("transactionId"). then((response) => { From 9b8a536feda1738865ec745dfc1a282d1e89f793 Mon Sep 17 00:00:00 2001 From: Boussari Latif Date: Thu, 27 Jun 2019 12:46:16 +0100 Subject: [PATCH 13/14] update readme --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 8f23169..0c6de4f 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,12 @@ Using cdn: ## Example -Request to retrieve transactions in production - ```js // setup your api key (https://www.kkiapay.me) //initialize kkiapay in production environnment const k = kkiapay({privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}) //initialize kkiapay in sandbox environnment - +// Request to retrieve transactions const k = kkiapay({privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx",sandbox:true}) k.verify("transactionId"). then((response) => { From 7e7fdb352a5d32f24c17528700d09fed3c436109 Mon Sep 17 00:00:00 2001 From: Boussari Latif Date: Thu, 27 Jun 2019 12:47:05 +0100 Subject: [PATCH 14/14] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c6de4f..bd53ee5 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ Using cdn: //initialize kkiapay in production environnment const k = kkiapay({privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}) //initialize kkiapay in sandbox environnment -// Request to retrieve transactions const k = kkiapay({privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx",sandbox:true}) +// Request to retrieve transactions k.verify("transactionId"). then((response) => { //handle response