Skip to main content
Version: 1.0

Library Usage — Collection

Collection APIs let you request payments from customers, check transaction status, send delivery notifications, manage invoices, and handle pre-approvals.

All flows require a valid Bearer access token and OAuth2 token stored in CredentialStorage. The SDK's TokenAuthenticator refreshes expired tokens automatically on 401 responses.


Request to Pay

Initiates a debit request against a customer's Mobile Money account.

val transactionUuid = UUID.randomUUID().toString()

val result = defaultRepository.requestToPay(
accessToken = credentialStorage.getAccessToken(),
momoTransaction = MomoTransaction(
amount = "500",
currency = "EUR",
externalId = UUID.randomUUID().toString(),
payer = AccountHolder(partyIdType = "MSISDN", partyId = "256770000000"),
payerMessage = "Payment for order #42",
payeeNote = "Order #42"
),
apiVersion = "v1_0",
productSubscriptionKey = collectionPrimaryKey,
uuid = transactionUuid
)
// result is a Retrofit Response<Unit>; check result.isSuccessful
ParameterTypeDescription
accessTokenStringBearer access token from CredentialStorage
momoTransactionMomoTransactionPayment details (amount, currency, payer, messages)
apiVersionStringAPI version, e.g. "v1_0"
productSubscriptionKeyStringCollection primary subscription key
uuidStringUnique reference ID — save this to poll for status

Request to Pay — Transaction Status

Polls the status of a previously initiated requestToPay call.

val response = defaultRepository.requestToPayTransactionStatus(
referenceId = transactionUuid,
apiVersion = "v1_0",
productSubscriptionKey = collectionPrimaryKey,
accessToken = credentialStorage.getAccessToken()
)
ParameterTypeDescription
referenceIdStringUUID used when calling requestToPay
apiVersionStringAPI version, e.g. "v1_0"
productSubscriptionKeyStringCollection primary subscription key
accessTokenStringBearer access token

Request to Withdraw

Initiates a credit request to a customer's Mobile Money account.

val transactionUuid = UUID.randomUUID().toString()

val result = defaultRepository.requestToWithdraw(
accessToken = credentialStorage.getAccessToken(),
momoTransaction = MomoTransaction(
amount = "200",
currency = "EUR",
externalId = UUID.randomUUID().toString(),
payee = AccountHolder(partyIdType = "MSISDN", partyId = "256770000000"),
payerMessage = "Withdrawal request",
payeeNote = "Withdrawal"
),
apiVersion = "v2_0",
productSubscriptionKey = collectionPrimaryKey,
uuid = transactionUuid
)
ParameterTypeDescription
accessTokenStringBearer access token
momoTransactionMomoTransactionTransaction details
apiVersionStringAPI version, e.g. "v2_0"
productSubscriptionKeyStringCollection primary subscription key
uuidStringUnique reference ID

Request to Withdraw — Transaction Status

val response = defaultRepository.requestToWithdrawTransactionStatus(
referenceId = transactionUuid,
apiVersion = "v2_0",
productSubscriptionKey = collectionPrimaryKey,
accessToken = credentialStorage.getAccessToken()
)
ParameterTypeDescription
referenceIdStringUUID used when calling requestToWithdraw
apiVersionStringAPI version, e.g. "v2_0"
productSubscriptionKeyStringCollection primary subscription key
accessTokenStringBearer access token

Request to Pay Delivery Notification

Sends a delivery notification to the payer after a successful requestToPay.

defaultRepository.requestToPayDeliveryNotification(
apiVersion = "v1_0",
referenceId = transactionUuid,
momoNotification = MomoNotification(notificationMessage = "Your payment was received."),
productSubscriptionKey = collectionPrimaryKey,
environment = "sandbox"
).collect { result ->
when (result) {
is NetworkResult.Success -> { /* notification sent */ }
is NetworkResult.Error -> { /* failed */ }
is NetworkResult.Loading -> { /* in progress */ }
}
}
ParameterTypeDescription
apiVersionStringAPI version, e.g. "v1_0"
referenceIdStringUUID of the original requestToPay
momoNotificationMomoNotificationNotification message body
productSubscriptionKeyStringCollection primary subscription key
environmentString"sandbox" or "production"

Create Invoice

Creates a payment invoice that a customer can pay via the USSD menu or MoMo app.

defaultRepository.createInvoice(
apiVersion = "v1_0",
invoice = Invoice(
externalId = UUID.randomUUID().toString(),
amount = "1000",
currency = "EUR",
validityDuration = "3600",
intendedPayer = AccountHolder(partyIdType = "MSISDN", partyId = "256770000000"),
payee = AccountHolder(partyIdType = "MSISDN", partyId = "256770000001"),
description = "Invoice for service #99"
),
uuid = UUID.randomUUID().toString(),
productSubscriptionKey = collectionPrimaryKey,
environment = "sandbox"
).collect { result ->
when (result) {
is NetworkResult.Success -> { /* invoice created */ }
is NetworkResult.Error -> { /* failed */ }
is NetworkResult.Loading -> { /* in progress */ }
}
}
ParameterTypeDescription
apiVersionStringAPI version, e.g. "v1_0"
invoiceInvoiceInvoice details including amount, currency, payer, and payee
uuidStringUnique reference ID for the invoice
productSubscriptionKeyStringCollection primary subscription key
environmentString"sandbox" or "production"

Get Invoice Status

Retrieves the current status of an invoice.

defaultRepository.getInvoiceStatus(
apiVersion = "v1_0",
referenceId = invoiceUuid,
productSubscriptionKey = collectionPrimaryKey,
environment = "sandbox"
).collect { result ->
when (result) {
is NetworkResult.Success -> { /* parse result.response */ }
is NetworkResult.Error -> { /* failed */ }
is NetworkResult.Loading -> { /* in progress */ }
}
}
ParameterTypeDescription
apiVersionStringAPI version
referenceIdStringUUID used when calling createInvoice
productSubscriptionKeyStringCollection primary subscription key
environmentString"sandbox" or "production"

Cancel Invoice

Cancels an active invoice.

defaultRepository.cancelInvoice(
apiVersion = "v1_0",
referenceId = invoiceUuid,
productSubscriptionKey = collectionPrimaryKey,
environment = "sandbox"
).collect { result ->
when (result) {
is NetworkResult.Success -> { /* invoice cancelled */ }
is NetworkResult.Error -> { /* failed */ }
is NetworkResult.Loading -> { /* in progress */ }
}
}
ParameterTypeDescription
apiVersionStringAPI version
referenceIdStringUUID of the invoice to cancel
productSubscriptionKeyStringCollection primary subscription key
environmentString"sandbox" or "production"

Create Pre-Approval

Creates a pre-approval that allows future debits without further subscriber interaction.

defaultRepository.createPreApproval(
apiVersion = "v1_0",
preApproval = PreApproval(
payer = AccountHolder(partyIdType = "MSISDN", partyId = "256770000000"),
payerCurrency = "EUR",
payerMessage = "Authorize monthly subscription",
validityTime = 3600
),
uuid = UUID.randomUUID().toString(),
productSubscriptionKey = collectionPrimaryKey,
environment = "sandbox"
).collect { result ->
when (result) {
is NetworkResult.Success -> { /* pre-approval created */ }
is NetworkResult.Error -> { /* failed */ }
is NetworkResult.Loading -> { /* in progress */ }
}
}
ParameterTypeDescription
apiVersionStringAPI version
preApprovalPreApprovalPayer details, currency, message, and validity duration in seconds
uuidStringUnique reference ID
productSubscriptionKeyStringCollection primary subscription key
environmentString"sandbox" or "production"

Get Pre-Approval Status

Checks the status of a pre-approval.

defaultRepository.getPreApprovalStatus(
apiVersion = "v1_0",
referenceId = preApprovalUuid,
productSubscriptionKey = collectionPrimaryKey,
environment = "sandbox"
).collect { result -> /* ... */ }
ParameterTypeDescription
apiVersionStringAPI version
referenceIdStringUUID used when calling createPreApproval
productSubscriptionKeyStringCollection primary subscription key
environmentString"sandbox" or "production"

Cancel Pre-Approval

Cancels an active pre-approval.

defaultRepository.cancelPreApproval(
apiVersion = "v1_0",
referenceId = preApprovalUuid,
productSubscriptionKey = collectionPrimaryKey,
environment = "sandbox"
).collect { result -> /* ... */ }
ParameterTypeDescription
apiVersionStringAPI version
referenceIdStringUUID of the pre-approval to cancel
productSubscriptionKeyStringCollection primary subscription key
environmentString"sandbox" or "production"