-
Notifications
You must be signed in to change notification settings - Fork 54
UI Flow
In this flow SDK provides an UI to take required information from user to execute transaction.
To perform transaction using this, follow the steps given below:
- Setup SDK and customize it (optional). Also this includes finished callback.
- Set transaction request information to SDK.
- Start payment
Besides installation step uiflow theme customization can be done using MidtransSDK
instance
To initialize the UI flow SDK, you need to pass the following
- CLIENT_KEY: For making tokenization requests to Veritrans (Found in the MAP)
- BASE_URL: Base URL of the Merchant server.
SdkUIFlowBuilder.init(this, CLIENT_KEY, BASE_URL, new TransactionFinishedCallback() {
@Override
public void onTransactionFinished(TransactionResult result) {
// Handle finished transaction here.
}
})
.setExternalScanner(new ScanCard()) // initialization for using external scancard
.enableLog(true)
.setDefaultText("open_sans_regular.ttf") // optional to set custom font
.setSemiBoldText("open_sans_semibold.ttf") // optional to set custom font
.setBoldText("open_sans_bold.ttf") // optional to set custom font
.buildSDK();
To apply Custom fonts, you can use this code.
MidtransSDK midtransSDK = MidtransSDK.getInstance();
midtransSDK.setDefaultText("open_sans_regular.ttf");
midtransSDK.setSemiBoldText("open_sans_semibold.ttf");
midtransSDK.setBoldText("open_sans_bold.ttf");
Note: open_sans_regular.ttf, open_sans_semibold.ttf, open_sans_bold.ttf is path of the custom font on the assets directory.
Also you can set the color primary in your theme in styles.xml
.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorButtonNormal">@color/colorButton</item>
</style>
Then to ensure this replace library theme, please add these lines into your AndroidManifest.xml
application tag.
<application
...
android:theme="AppTheme"
tools:replace="android:theme">
Before using the SDK to pay, you must set the transaction details into the SDK instance.
TRANSACTION_ID
and TOTAL_AMOUNT
was required to create a transaction request.
TransactionRequest transactionRequest = new TransactionRequest(TRANSACTION_ID, TOTAL_AMOUNT);
Customer Details was optional when creating transaction request.
CustomerDetails customer = new CustomerDetails(FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER);
transactionRequest.setCustomerDetails(customer);
Note: This was assumed that you have created transactionRequest
object using required parameters.
ItemDetails class holds information about item purchased by user. TransactionRequest takes an array list of item details.
ItemDetails itemDetails1 = new ItemDetails(ITEM_ID_1, ITEM_PRICE_1, ITEM_QUANTITY_1, ITEM_NAME_1);
ItemDetails itemDetails2 = new ItemDetails(ITEM_ID_2, ITEM_PRICE_2, ITEM_QUANTITY_2, ITEM_NAME_2);
// Create array list and add above item details in it and then set it to transaction request.
ArrayList<ItemDetails> itemDetailsList = new ArrayList<>();
itemDetailsList.add(itemDetails1);
itemDetailsList.add(itemdetails2);
// Set item details into the transaction request.
transactionRequest.setItemDetails(itemDetailsList);
Note:
- This was assumed that you have created
transactionRequest
object using required parameters. -
ITEM_NAME
maximum character length is 50.
BillingAddress class holds information about billing. TransactionRequest takes an array list of billing details.
BillingAddress billingAddress1 = new BillingAddress(FIRST_NAME_1, LAST_NAME_1, ADDRESS_1, CITY_1, POSTAL_CODE_1, PHONE_NUMBER_1, COUNTRY_CODE_1);
BillingAddress billingAddress2 =new BillingAddress(FIRST_NAME_2, LAST_NAME_2, ADDRESS_2, CITY_2, POSTAL_CODE_2, PHONE_NUMBER_2, COUNTRY_CODE_2);
// Create array list and add above billing details in it and then set it to transaction request.
ArrayList<BillingAddress> billingAddressList = new ArrayList<>();
billingAddressList.add(billingAddress1);
billingAddressList.add(billingAddress2);
// Set billing address list into transaction request
transactionRequest.setBillingAddressArrayList(billingAddressList);
Note: This was assumed that you have created transactionRequest
object using required parameters.
ShippingAddress class holds information about shipping address. TransactionRequest takes an array list of shipping details.
ShippingAddress shippingAddress1 = new ShippingAddress(FIRST_NAME_1, LAST_NAME_1, ADDRESS_1, CITY_1, POSTAL_CODE_1, PHONE_NUMBER_1, COUNTRY_CODE_1);
ShippingAddress shippingAddress2 =new ShippingAddress(FIRST_NAME_2, LAST_NAME_2, ADDRESS_2, CITY_2, POSTAL_CODE_2, PHONE_NUMBER_2, COUNTRY_CODE_2);
// Create array list and add above shipping details in it and then set it to transaction request.
ArrayList<BillingAddress> shippingAddressList = new ArrayList<>();
shippingAddressList.add(shippingAddress1);
shippingAddressList.add(shippingAddress1);
// Set shipping address list into transaction request.
transactionRequest.setShippingAddressArrayList(shippingAddressList);
BillInfoModel class holds information about billing information that will be shown at billing details.
BillInfoModel billInfoModel = new BillInfoModel(BILL_INFO_KEY, BILL_INFO_VALUE);
// Set the bill info on transaction details
transactionRequest.setBillInfoModel(billInfoModel);
After creating transaction request, you must set it into SDK instance.
MidtransSDK.getInstance().setTransactionRequest(transactionRequest);
Note: transactionRequest
is TransactionRequest
object created in previous step.
UIKitCustomSetting uiKitCustomSetting = new UIKitCustomSetting();
uiKitCustomSetting.setSaveCardChecked(true);
MidtransSDK.getInstance().setUIKitCustomSetting(uiKitCustomSetting);
UIKitCustomSetting uiKitCustomSetting = new UIKitCustomSetting();
uiKitCustomSetting.setShowPaymentStatus(false);
MidtransSDK.getInstance().setUIKitCustomSetting(uiKitCustomSetting);
This is optional feature if you want to skip customer details screen.
// Set user details
UserDetail userDetail = new UserDetail();
userDetail.setUserFullName(FULL_NAME);
userDetail.setEmail(EMAIL);
userDetail.setPhoneNumber(PHONE_NUMBER);
userDetail.setUserId(USER_ID);
// Initiate address list
ArrayList<UserAddress> userAddresses = new ArrayList<>();
// Initiate and add shipping address
UserAddress shippingUserAddress = new UserAddress();
shippingUserAddress.setAddress(shippingAddress);
shippingUserAddress.setCity(shippingCity);
shippingUserAddress.setCountry(shippingCountry);
shippingUserAddress.setZipcode(shippingZipcode);
shippingUserAddress.setAddressType(Constants.ADDRESS_TYPE_SHIPPING);
userAddresses.add(shippingUserAddress);
// Initiate and add billing address
UserAddress billingUserAddress = new UserAddress();
billingUserAddress.setAddress(billingAddress);
billingUserAddress.setCity(billingCity);
billingUserAddress.setCountry(country);
billingUserAddress.setZipcode(zipcode);
billingUserAddress.setAddressType(Constants.ADDRESS_TYPE_BILLING);
userAddresses.add(billingUserAddress);
// if shipping address is same billing address
// you can user type Constants.ADDRESS_TYPE_BOTH
// NOTE: if you use this, skip initiate shipping and billing address above
UserAddress userAddress = new UserAddress();
userAddress.setAddress(billingAddress);
userAddress.setCity(billingCity);
userAddress.setCountry(country);
userAddress.setZipcode(zipcode);
userAddress.setAddressType(Constants.ADDRESS_TYPE_BOTH);
userAddresses.add(userAddress);
// Set user address to user detail object
userDetail.setUserAddresses(userAddresses);
// Save the user detail. It will skip the user detail screen
LocalDataHandler.saveObject("user_details", userDetail);
Note:
- All user details is required to make transactions.
- Minimum one address is required to make transactions.
-
USER_ID
is required to enable save card and one-click/two-clicks.
If you support credit card payment, you must select one of three card click types.
CreditCard creditCardOptions = new CreditCard();
// Set to true if you want to save card to Snap
creditCardOptions.setSaveCard(true);
// Set to true to save card token as `one click` token
creditCardOptions.setSecure(true);
// Set acquiring bank
creditCardOptions.setBank(BankType.BANK_NAME);
// Set MIGS channel (Required for BCA, MAYBANK, and BRI acquiring bank)
creditCardOptions.setChannel(CreditCard.MIGS);
// Set Credit Card Options
transactionRequest.setCreditCard(creditCardOptions);
// Set card payment info
transactionRequest.setCardPaymentInfo(CARD_CLICK_TYPE, IS_SECURE);
// Set transaction request into SDK instance
MidtransSDK.getInstance().setTransactionRequest(transactionRequest);
Note:
-
CARD_CLICK_TYPE - type of card use these resource strings:
- R.string.card_click_type_one_click - for one click
- R.string.card_click_type_two_click - for two click
- R.string.card_click_type_none - for normal transaction
-
IS_SECURE - set to true if using 3D secure
For more information about transaction request please read this wiki.
MidtransSDK.getInstance().startPaymentUiFlow(ACTIVITY_CONTEXT);
Users can directly go to payment screen by using these methods.
MidtransSDK.getInstance().startCreditCardUIFlow(ACTIVITY_CONTEXT);
General Bank Transfer
MidtransSDK.getInstance().startBankTransferUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startPermataBankTransferUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startBCABankTransferUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startMandiriBankTransferUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startOtherBankTransferUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startKlikBCAUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startBCAKlikPayUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startMandiriClickpayUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startMandiriECashUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startCIMBClicksUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startBRIEpayUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startTelkomselCashUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startIndosatDompetkuUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startXlTunaiUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startIndomaretUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startKiosonUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startGiftCardUIFlow(ACTIVITY_CONTEXT);
MidtransSDK.getInstance().startAkulakuUIFlow(ACTIVITY_CONTEXT);
TransactionResult
is wrapper for UI flow finished transaction object.
It contains:
-
status
: eitherpending
,success
,failed
orinvalid
based on payment API. -
transactionResponse
: contains payment response from Payment API. -
transactionCanceled
: this will be set to true only if transaction was canceled from inside SDK. For example when selecting payment method users click back.
Here the step:
- First one to check is
transactionCanceled
. If this was set to true then you don't have to check other field. - You can check based on status:
pending
will be only use on asynchronous transaction like bank transfer or internet banking. You can use API to get transaction status or wait for notification comes to your backend to ensure the latest status of the transaction.success
/failed
: For synchronous transaction you can immediately know the status of the transaction.invalid
: There are unknown error happened. -
transactionResponse
for detailed transaction response from Payment API.