Skip to content

Commit

Permalink
add example for the remittance operation
Browse files Browse the repository at this point in the history
  • Loading branch information
luigimorel committed Apr 15, 2022
1 parent 1fc148d commit fe5f872
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions examples/remittances.js
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);
});

0 comments on commit fe5f872

Please sign in to comment.