-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example for the remittance operation
- Loading branch information
1 parent
1fc148d
commit fe5f872
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const momo = require("../lib"); | ||
|
||
const { Remittances } = momo.create({ callbackHost: process.env.CALLBACK_HOST }); | ||
|
||
// initialise collections | ||
const remittances = Remittances({ | ||
userSecret: process.env.REMITTANCES_USER_SECRET, | ||
userId: process.env.REMITTANCES_USER_ID, | ||
primaryKey: process.env.REMITTANCES_PRIMARY_KEY | ||
}); | ||
|
||
const partyId = "256776564739"; | ||
const partyIdType = momo.PayerType.MSISDN; | ||
// Transfer | ||
remittances | ||
.isPayerActive(partyId, partyIdType) | ||
.then((isActive) => { | ||
console.log("Is Active ? ", isActive); | ||
if (!isActive) { | ||
return Promise.reject("Party not active"); | ||
} | ||
return remittances.remit({ | ||
amount: "100", | ||
currency: "EUR", | ||
externalId: "947354", | ||
payee: { | ||
partyIdType, | ||
partyId | ||
}, | ||
payerMessage: "testing", | ||
payeeNote: "hello", | ||
callbackUrl: process.env.CALLBACK_URL ? process.env.CALLBACK_URL : "https://75f59b50.ngrok.io" | ||
}); | ||
}) | ||
|
||
.then(transactionId => { | ||
console.log({ transactionId }); | ||
|
||
// Get transaction status | ||
return remittances.getTransaction(transactionId); | ||
}) | ||
.then(transaction => { | ||
console.log({ transaction }); | ||
|
||
// Get account balance | ||
return remittances.getBalance(); | ||
}) | ||
.then(accountBalance => console.log({ accountBalance })) | ||
.catch(error => { | ||
console.log(error); | ||
}); |