Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Using npm:

```bash

$ npm i -s kkiapay
$ npm i -s kkiapay/nodejs-sdk

```

Expand All @@ -30,14 +30,18 @@ Using cdn:

## Example

Request to retrieve transactions

```js
kkiapay.transaction({ transactionId:"xxxxxx",privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx"}).
// 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
const k = kkiapay({privatekey:"xxxxxxx",publickey:"xxxxxxx",secretkey:"xxxxxxx",sandbox:true})
// Request to retrieve transactions
k.verify("transactionId").
then((response) => {
//handle response
}).
catch((error) => {
//handle error
})
```
```
Binary file added lib/.DS_Store
Binary file not shown.
4 changes: 0 additions & 4 deletions lib/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
{
Expand Down
7 changes: 5 additions & 2 deletions lib/http.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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'
}
})

module.exports = http
5 changes: 2 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
module.exports = {
transaction: require('./transaction'),
}
const transaction = require('./transaction')
module.exports = transaction
3 changes: 1 addition & 2 deletions lib/opts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
module.exports={
baseURL: "https://api.kkiapay.me",
transactionEndpoint: '/api/v1/transactions/status',
}
}
45 changes: 32 additions & 13 deletions lib/transaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,39 @@ 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;
http.defaults.baseURL = config.sandbox ? "https://api-sandbox.kkiapay.me" : "https://api.kkiapay.me"

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.status===4003)
{
throw new Error(error.response.data.reason)
}
else
{
throw new Error("Transaction Not Found")
}
})

}

}
12 changes: 8 additions & 4 deletions sample/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const kkiapay=require("../index")
const kkiapay=require("../lib")


let k=kkiapay({publickey:"f774e960812811e99cf7e73f32bcec42",privatekey:"process.env.privatekey",secretkey:"process.env.secretkey",sandbox:true})

k.verify("O_S9_rdlX").
then(e=>console.log(e)).
catch(err=>console.log(err))


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))

5 changes: 0 additions & 5 deletions tests/function.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion tests/transaction.test.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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()
})
Expand Down