-
Notifications
You must be signed in to change notification settings - Fork 54
GO PAY
GO-PAY is direct debit using GO-JEK account. It uses GO-JEK app to complete the payment, whether by using deeplink or QR code scan. This payment type is asynchronous.
We provide interface for transaction callback. You just need to implement TransactionCallback when make a transaction to get transaction response.
It contains three implemented methods onSuccess
, onFailure
and onError
.
public interface TransactionCallback {
//transaction response when success
public void onSuccess(TransactionResponse response);
//response when transaction failed
public void onFailure(TransactionResponse response, String reason);
//general error
public void onError(Throwable error);
}
To start payment, use paymentUsingGoPay
on MidtransSDK
instance. Please note if you want to use deeplink function of GO-JEK, you need to make sure GO-JEK app is already installed in user's device.
MidtransSDK.getInstance().paymentUsingGoPay(AUTHENTICATION_TOKEN, new TransactionCallback() {
@Override
public void onSuccess(TransactionResponse response) {
//action when transaction success
}
@Override
public void onFailure(TransactionResponse response, String reason) {
//action when transaction failure
}
@Override
public void onError(Throwable error) {
//action when error
}
}
);
Since this payment channel needs GO-JEK app, and GO-JEK app isn't officially supported in tablet, you may need to treat tablet users slightly different. We suggest using deeplink if payment happens in smartphone (less than 7 inch diagonal screen) and using QR code otherwise.
After successfully start the payment, you will get TransactionResponse
. From it, you can retrieve deeplink or QR code by using this code :
String deeplinkUrl = response.getDeeplinkUrl();
String qrCodeUrl = response.getQrCodeUrl();
For deeplink way, put deeplinkUrl
into your view OnClickListener
, so whenever user tap that view, it will redirect to GO-PAY page. To implement redirection, you can use this code :
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(deeplinkUrl));
startActivity(intent);
For QR code method, simply load QR code as image using your favorite library (or your own implementation). Make sure it has decent enough size so mobile phone camera can scan it in order to complete the transaction. Please note that user should use GO-JEK app to scan the QR code.
Result of transaction can receive by host app with 2 type of method, first method is with callback deeplink (to host-app) and the second is without callback deeplink.
First you need to implement deeplink in your app, please follow deeplink from google developers from this link. Then when you make transaction request, add GO-PAY object to transaction request like this :
TransactionRequest transactionRequest = new TransactionRequest();
// Setup your Transaction Request here then set your GO-PAY deeplink
transactionRequest.setGopay(new Gopay("demo://midtrans"));
That's all, after this when you make payment with GO-PAY from GO-JEK app it will call your app deeplink with payment status and order id. For example like this for success demo://midtrans?order_id=xxxx&result=success
and this for failure demo://midtrans?order_id=xxxx&result=failure
Note : This only work with latest GO-JEK app
For this method you not need set your application deeplink, so after making payment, just check your transaction with this method from sdk
String snapToken = getMidtransSDK().readAuthenticationToken();
MidtransSDK.getInstance().getTransactionStatus(snapToken, new GetTransactionStatusCallback() {
@Override
public void onSuccess(TransactionStatusResponse response) {
// do action for response
}
@Override
public void onFailure(TransactionStatusResponse response, String reason) {
// do nothing
}
@Override
public void onError(Throwable error) {
// do action if error
}
});