Installation
GoPay Tokenization SDK is available via Gradle on Android.
// Android installation via gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
implementation "com.midtrans:gopay-checkout:1.0.5"
Initialization
To start using the SDK, you need to initialize the installed libraries. You can provide the following mandatory parameters:
Parameter Name | Explanation |
---|---|
merchant_id | This is your merchant ID. You can find this in your Midtrans dashboard |
callback_url | This is the callback URL that will redirect back after webview is invoked |
merchant_server_url | This is the address of the merchant server that you register to Midtrans |
You'll also need to pass the Android context
to initialize the client. Use the following script to initialize on Android.
For the callback_url
, this parameter is needed to let the SDK go back to close the webview automatically. For example, your app URL scheme should be something like myapp://app
, all lowercase.
//Android Initialization
GoPayCheckoutClient goPayCheckoutClient = new GoPayCheckoutClient(
CONTEXT,
MERCHANT_ID,
CALLBACK_URL,
MERCHANT_SERVER_URL,
false // to enable logging
);
The following script can be used as an example for account linking on Android :
// use the goPayCheckoutClient object from initialization
// Account linking on Android
goPayCheckoutClient.linkAccount(
ACTIVITY,
new GoPayPartnerDetails(
PHONE,
COUNTRY_CODE
),
new GoPayCheckoutCallback<AccountResponse>() {
@Override
public void onResponse(AccountResponse response) {
// Handle response of account linking
// For actual status merchant need to use get account status API
}
@Override
public void onFailure(GoPayCheckoutError error, AccountResponse errorResponse) {
// Handle error
}
},
METADATA // Map<String, String> optional,
"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="// authorization parameter, optional
);
Account Linking On Android
For account linking call GoPayCheckoutClient.linkAccount
with parameter explained below
Name | Type | Explanation | Required |
---|---|---|---|
activity | Object | Caller activity | Required |
goPayPartnerDetails | Object | Contains partner information | Required |
goPayCheckoutCallback | Object | Callback delivering response or error | Required |
metadata | Object | Map of String to String, put custom info for your usage | Optional |
authorization | String | String value for authorization header. Recommended to use at least Basic Auth. | Optional |
The GoPayPartnerDetails
object has the following properties that you need to fill up
Name | Type | Explanation | Required |
---|---|---|---|
phone | String | Phone number account to be linked | Required |
countryCode | String | Country code related to account | Required |
The GoPayCheckoutCallback
interface has methods that you need to implement
Name | Return Type | Explanation | Required |
---|---|---|---|
onResponse | Void | Called when linking receiving response | Required |
onFailure | Void | Called when linking process error | Required |
The AccountResponse
object has the following properties that you will require in other APIs
Name | Type | Explanation |
---|---|---|
accountId | String | Account ID to be used enquire account status, create a transaction and disable the account |
accountStatus | String | Current account linking status. Possible values are ENABLED, PENDING, and DISABLED |
The errorResponse object maps the error response from the Partner API. You can parse the message to identify the problem.
Account Status Enquiry On Android
The following script can be used as an example for account status enquiry on Android
//Account Status Enquiry On Android
goPayCheckoutClient.enquireAccount(
ACCOUNT_ID,
new GoPayCheckoutCallback<AccountResponse>() {
@Override
public void onResponse(AccountResponse response) {
// Handle response of account enquiry
}
@Override
public void onFailure(GoPayCheckoutError error, AccountResponse errorResponse) {
// Handle error
}
},
"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="// authorization parameter, optional
);
For account enquiring call GoPayCheckoutClient.enquireAccount
with parameter explained below.
Name | Type | Explanation | Required |
---|---|---|---|
accountId | String | GoPay account id | Required |
goPayCheckoutCallback | Object | Callback delivering response or error | Required |
authorization | String | String value for authorization header. Recommended to use at least Basic Auth. | Optional |
The GoPayCheckoutCallback
interface has methods that you need to implement
Name | Return Type | Explanation | Required |
---|---|---|---|
onResponse | Void | Called when enquiring account receiving response | Required |
onFailure | Void | Called when enquiring account process error | Required |
The AccountResponse
object has the following properties that you will require in other APIs
Name | Type | Explanation |
---|---|---|
accountId | String | Account ID to be used enquire account status, create a transaction and disable an account |
accountStatus | String | Current account linking status. Possible values are ENABLED, PENDING and DISABLED |
Metadata | AccountMetadata | List of available PaymentOption objects |
The PaymentOption
object has the following properties that you will require in other APIs
Name | Type | Explanation |
---|---|---|
name | String | Name of payment option |
active | Boolean | Payment option status. True indicates active |
token | String | Payment token to create transactions |
balance | Amount | An object consisting of amount and currency |
The errorResponse
object maps the error response from the Partner API. You can parse the message to identify the problem.
Create Transaction On Android
The following script can be used as an example for creating transactions on Android
//### Create Transaction On Android
List<ItemDetail> items = new ArrayList<>();
items.add(
new ItemDetail(
UUID.randomUUID().toString(),
"Beli barang bagus",
12000L,
1,
null
)
);
goPayCheckoutClient
.createTransaction(
Activity.this,
new GoPayDetails(
ACCOUNT_ID,
PAYMENT_OPTION_TOKEN
),
new TransactionDetails(
ORDER_ID,
GROSS_AMOUNT,
"IDR" //CURRENCY
),
PHONE_NUMBER,
items,
new GoPayCheckoutCallback<TransactionResponse>() {
@Override
public void onResponse(TransactionResponse response) {
// Handle transaction finished
// Result is available in the HTTP Notification not from SDK
}
@Override
public void onFailure(GoPayCheckoutError error, TransactionResponse errorResponse) {
// Handle error
}
},
METADATA // Map<String, String> optional,
"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="// authorization parameter, optional
);
For creating transaction call GoPayCheckoutClient.createTransaction
with parameter explained below.
Name | Type | Explanation | Required |
---|---|---|---|
goPayDetails | Object | Contains account_id, payment_option_token | Required |
transactionDetails | Object | Contains order_id, gross_amount, and currency | Required |
phoneNumber | String | Filled with phone number | Required |
itemDetails | Object | List of Items each contains id, name, price, quatity, category | Optional |
goPayCheckoutCallback | Object | Callback delivering response or error | Required |
metadata | Object | Map of String to String, put custom info for your usage | Optional |
authorization | String | String value for authorization header. Recommended to use at least Basic Auth. | Optional |
The GoPayDetails
object has the following properties
Name | Type | Explanation | Required |
---|---|---|---|
accountId | String | GoPay accound id | Required |
paymentOptionToken | String | Call enquire account to obtain | Required |
The TransactionDetails
object has the following properties
Name | Type | Explanation | Required |
---|---|---|---|
orderId | String | Order id of transaction | Required |
grossAmount | Long | Gross amount of transaction | Required |
currency | String | Currency of transaction | Required |
The GoPayCheckoutCallback
interface has methods that you need to implement
Name | Return Type | Explanation | Required |
---|---|---|---|
onResponse | Void | Called when creating transaction receiving response | Required |
onFailure | Void | Called when creating transaction process error | Required |
The TransactionResponse
object has the following properties
Name | Type | Explanation |
---|---|---|
transactionId | String | The transaction ID recorded in the system. |
transactionStatus | String | The transaction status. This will always return pending as the status is sent via HTTP Notification. |
orderID | String | The order ID set in the TransactionDetails passed into the create transaction API. |
grossAmount | String | The transaction amount. |
currency | String | The currency of the transaction. |
paymentType | String | The payment option type used in the transaction. |
transactionTime | String | The time of transaction. |
fraudStatus | String | This is the fraud checking Status. |
The errorResponse
object maps the error response from the Partner API. You can parse the message to identify
the problem.
Disable Account On Android
The following script can be used as an example for disabling account on Android.
//Disable Account On Android
goPayCheckoutClient.disableAccount(
ACCOUNT_ID,
new GoPayCheckoutCallback<AccountResponse>() {
@Override
public void onResponse(AccountResponse response) {
// Handle response of disable the account
}
@Override
public void onFailure(GoPayCheckoutError error, AccountResponse errorResponse) {
// Handle error
}
},
METADATA // Map<String, String> optional,
"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="// a new authorization parameter
);
For disabling account SDK will send following payload properties
Name | Type | Explanation | Required |
---|---|---|---|
accountId | String | Account id to be disabled | Required |
goPayCheckoutCallback | Object | Callback delivering response or error | Required |
metadata | Object | Map of String to String, put custom info for your usage | Optional |
authorization | String | String value for authorization header. Recommended to use at least Basic Auth. | Optional |
The GoPayCheckoutCallback
interface has methods that you need to implement
Name | Return Type | Explanation | Required |
---|---|---|---|
onResponse | Void | Called when disabling account receiving response | Required |
onFailure | Void | Called when disabling account process error | Required |
The AccountResponse
object has the following properties.
Name | Type | Explanation |
---|---|---|
accountId | String | Account ID similar to what you use to disable an account |
accountStatus | String | Current account linking status. The result will always return DISABLED |
The errorResponse
object maps the error response from the Partner API. You can parse the message to identify the problem.