Skip to main content

Handle payments

Following a request to accept or make payments, a response from the server is received.

This response contains details about the transaction you just initiated. Either it is the reasons for which we could not initiate a transaction (there is therefore an error) or it is the data on the initiated transaction.

In all cases, the response of a transaction must be handled.


Handling a payment request

Below is an example of payment initiation and response received in return.

collection.js
const momo = require("@chipdeals/momo-api");momo.setApiKey("test_FOdigzgSopV8GZggZa89");momo  .collect()  .amount(100)  .currency("XOF")  .from("22951010200")  .firstName("Iyam")  .lastName("EVERICH")  .create()  .onSuccess((paymentData) => handlePyamentSuccess(paymentData))  .onError((paymentData) => handlePaymentFails(paymentData));function handlePyamentSuccess(paymentData) {  console.log("payment succeeded");  console.log("payment data: ", paymentData);}function handlePyamentSuccess(paymentData) {  console.log("payment failed");}
Console
dev@Chipdeals:~/Chipdeals/projects/nodejs-doc$ node collection.js2022-11-13 08:03:32:527 Collection request2022-11-13 08:03:36:126 TEST [202] Transaction is pending2022-11-13 08:03:39:287 TEST [201] Data in validation2022-11-13 08:03:46:138 TEST [203] Data are validated, server is working2022-11-13 08:03:51:125 TEST [204] Waiting for ussd push validation2022-11-13 08:03:54:898 TEST [200] Successfully processed transaction2022-11-13 08:03:54:898 TEST [OK] 100 XOF received form customerpayment succeededpayment data:  {  reference: 'f1d87806-72c0-4a46-8560-89c3fb6f7070',  senderPhoneNumber: '22951010200',  senderOperator: 'MTN',  senderFirstName: 'Iyam',  senderLastName: 'EVERICH',  currency: 'XOF',  amount: 100,  status: 'success',  statusMessage: 'Successfully processed transaction',  startTimestampInSecond: 1668326614,  endTimestampInSecond: 0,  senderCountryCode: 'BJ',  originalCurrency: 'XOF',  statusMessageCode: 200,  originalAmount: 100,  transactionType: 'payment'}
See more example


Details of the Response object to a payment

The response format is the same as the one presented in the introduction

If the request is validated, a payment property that replaces anyObjet is added. The payment object contains details of the transaction. It is structured as follows:

PropertyExampleDescription
reference"aca59aa9-830b-4bf7-bb0a-74cd438130ee"Transaction reference
senderPhoneNumber"22951945200"Phone number of paying user
senderCountryCode"BJ"Phone number of paying user
senderOperator"MTN"Phone number of paying user
senderFirstName"iyam"First name of paying user
senderLastName"EVERICH"Paying User Name
originalCurrency"XOF"Payment currency you indicated in your request
currency"XOF"Local currency of the user's phone number
status"pending"Transaction status (pending or success or error)
statusMessage"pending"Message explaining what exactly happens for the transaction
statusMessageCode202Specific code of the exact state of the transaction. See more
startTimestampInSecond1655968250Timestamp in seconds when you initiated the payment
endTimestampInSecond0Timestamp in seconds when a transaction is completed
amount10Amount in local currency that the user pays
originalAmount10Amount you specified for the user to pay in your request
transactionType"payment"Transaction Type. Always payment in the case of a payment request


Handling a deposit request

Below is an example of the initiation of a deposit and the response received in return.

deposit.js
const momo = require("@chipdeals/momo-api");momo.setApiKey("test_FOdigzgSopV8GZggZa89");momo  .deposit()  .amount(100)  .currency("XOF")  .to("22951010200")  .create()  .onSuccess((paymentData) => handlePaymentSuccess(paymentData))  .onError((paymentData) => handlePaymentFailed(paymentData));function handlePaymentSuccess(paymentData) {  console.log("deposit succeeded");  console.log("deposit data: ", paymentData);}function handlePaymentFailed(paymentData) {  console.log("deposit failed");}
Console
dev@Chipdeals:~/Chipdeals/projects/nodejs-doc$ node deposit.js2022-11-13 11:36:26:129 Disbursement request2022-11-13 11:36:27:765 TEST [202] Transaction is pending2022-11-13 11:36:34:304 TEST [201] Data in validation2022-11-13 11:36:38:938 TEST [203] Data are validated, server is working2022-11-13 11:36:42:374 TEST [200] Successfully processed transaction2022-11-13 11:36:42:375 TEST [OK] 100 XOF sent to customerdeposit succeededdeposit data:  {  reference: '4c732c68-0bfe-428f-a95e-ae14cc815505',  recipientPhoneNumber: '22951010200',  recipientOperator: 'MTN',  currency: 'XOF',  amount: 100,  status: 'success',  statusMessage: 'Successfully processed transaction',  startTimestampInSecond: 1668339387,  endTimestampInSecond: 0,  recipientCountryCode: 'BJ',  originalCurrency: 'XOF',  statusMessageCode: 200,  originalAmount: 100,  transactionType: 'deposit'}
See more example


Details of the Response object of a deposit

The response format is the same as the one presented in the introduction

If the request is validated, a deposit property which replaces anyObjet is added. The deposit object contains details of the transaction. It is structured as follows:

PropertyExampleDescription
reference"f46efbee-1aca-4be7-934f-08ec0f25b726"Transaction reference
recipientPhoneNumber"22951945200"Beneficiary phone number
recipientCountryCode"BJ"Beneficiary country code
recipientOperator"MTN"Beneficiary operator
originalCurrency"XOF"Payment currency you indicated in your application
currency"XOF"Local Currency of Recipient Phone Number
status"pending"Transaction status (pending or success or error)
statusMessage"pending"Message explaining what exactly happens for the transaction
statusMessageCode202Specific code of the exact state of the transaction. See more
startTimestampInSecond1655968250Timestamp in seconds when you initiated the payment
endTimestampInSecond0Timestamp in seconds when a transaction is completed
amount10Amount in local currency that the user receives
originalAmount10Amount you specified the user will receive in your request
transactionType"deposit"Transaction Type. Always deposit in the case of a deposit