Examples
Befor proceeding to these actions, you should have your setup ready.
Generally, you can perform actions by calling the onSendMessage
function.
const uniqueReference = ChuttApp.buildActionName(product_to_pay_for.id);
const data = {
uniqueAction: uniqueReference // optional
};
const onDoSomething = () => {
// const uniqueReference = ChuttApp.buildActionName(some_reference);
const data = {
action: ACTION_NAME // required!,
// uniqueAction: uniqueReference
}
ChuttApp.onSendMessage(data, (status, err, data) => {
console.log(status, err, data)
})
}
The following examples would use their built-in methods unless onSendMessage
is needed.
Request Payment
// const uniqueReference = ChuttApp.buildActionName(product_to_pay_for.id);
const data = {
amount: 10,
currency: 'GHS',
// uniqueAction: uniqueReference // optional
};
const onPay = () => {
ChuttApp.Transfer.onAcceptTransfer(data, (status, err) => {
console.log(status, err)
})
}
Passing
amount
would disable amount field for the user.
Handle Request-Payment response
Use this if you want to handle unique responses.
Make sure you pass the
uniqueReference
to theuniqueAction
property when sending the action.
const uniqueReference = ChuttApp.buildActionName(product_to_pay_for.id);
ChuttApp.onReceiveMessage(uniqueReference, (status, err, data) => {
console.log(status, err, data)
})
You can listen to general Transfer error or action too.
// 1. using the onAcceptTransferError method.
ChuttApp.onAcceptTransferError((status, err, data) => {
console.log(status, err, data)
})
// 2. using the ACCEPT_TRANSFER_RESPONSE action for onReceiveMessage.
ChuttApp.onReceiveMessage('ACCEPT_TRANSFER_RESPONSE', (status, err, data) => {
console.log(status, err, data)
})
Send Payment
// const uniqueReference = ChuttApp.buildActionName(your_transaction_id);
const data = {
amount: 10,
currency: 'GHS',
receiverId: 'current_authenticated_user_id',
// uniqueAction: uniqueReference // optional
};
const onSendTransfer = () => {
ChuttApp.Transfer.onSendTransfer(data, (status, err) => {
console.log(status, err)
})
}
Handle Send-Payment response
// 1. using the onSendTransferError method.
ChuttApp.onSendTransferError((status, err, data) => {
console.log(status, err, data)
})
// 2. using the SENSEND_TRANSFER_RESPONSED_TRANSFER action for onReceiveMessage.
ChuttApp.onReceiveMessage('SEND_TRANSFER_RESPONSE', (status, err, data) => {
console.log(status, err, data)
})
Open QRCode
User profile QRCode
const onOpenUserProfileQRCode = () => {
ChuttApp.Qrcode.onOpenUserProfileQRCode((status, err) => {
console.log(status, err)
})
}
Pay/Send Transfer QRCode
const onOpenPayQRCode = () => {
ChuttApp.Qrcode.onOpenPayQRCode((status, err) => {
console.log(status, err)
})
}
Receive Transfer QRCode
const onOpenReceiveTranferQRCode = () => {
ChuttApp.Qrcode.onOpenReceiveTranferQRCode((status, err) => {
console.log(status, err)
})
}
Open Scanner
const onOpenScanner = () => {
ChuttApp.Scanner.onOpenScanner((status, err) => {
console.log(status, err)
})
}