-
Notifications
You must be signed in to change notification settings - Fork 54
Core Flow
This flow assumes that the App Developer implements the User interface necessary for receiving user inputs to and library only provides the payments infrastructure.
To perform transaction using core, follow the steps given below:
- Set transaction request information to SDK.
- Setup event bus handler to catch the transaction results.
- Call the implemented method of the desired payment mode.
The main difference between the core and UI flow is that
-
Get payment response -
- In Core Flow - Use TransactionCallback.
- In UI Flow - Use Broadcast Receiver.
-
Payment Selection Method -
- In Core Flow - Call paymentUsingXXX().
- In UI Flow - Call startPaymentUiFlow() to see all specified payment methods.
This SDK using Event Bus implementation which don't require activity as a parameter. Instead, you need to register your subscribed class using Event Bus
.
For default implementation of the core flow
please add this code blocks into onCreate
and onDestroy
method on your Activity/Fragment that needs to implement this SDK. This to ensure only one event bus registered for each shown activity.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(!VeritransBusProvider.getInstance().isRegistered(this)) {
VeritransBusProvider.getInstance().register(this);
}
}
@Override
public void onDestroy() {
super.onDestroy();
if(VeritransBusProvider.getInstance().isRegistered(this)) {
VeritransBusProvider.getInstance().unregister(this);
}
}
Each API usage has its own onEvent
interface to capture finished API access. Please implement one of this Event interface on Activity or Fragment that accessing the SDK.
TokenBusCallback
GetCardBusCallback
SaveCardBusCallback
DeleteCardBusCallback
GetOfferBusCallback
TransactionBusCallback
CardRegistrationBusCallback
GetAuthenticationBusCallback
This interface will implement 2 general error handler, success event and failed event.
For example, TransactionBusCallback
will have to implement these methods.
// Need to attach @Subscribe annotation to enable Event Bus registration
@Subscribe
@Override
public void onEvent(NetworkUnavailableEvent event) {
//Network unavailable event implementation
}
@Subscribe
@Override
public void onEvent(GeneralErrorEvent event) {
//Generic error event implementation
}
@Subscribe
@Override
public void onEvent(TransactionSuccessEvent event) {
//Success event implementation
}
@Subscribe
@Override
public void onEvent(TransactionFailedEvent event) {
//Failed event implementation
}
Note: Need to add @Subscribe
annotation on implemented methods above.
These are common parameters which are required in all types of transaction.
CustomerDetails class holds information about customer. To set information about customer in TransactionRequest use following code -
CustomerDetails customer = new CustomerDetails(String firstName, String lastName, String email, String phone);
// Set customer details on
transactionRequest.setCustomerDetails(customer);
ItemDetails class holds information about item purchased by user. TransactionRequest takes an array list of item details. To set this in TransactionRequest use following code -
ItemDetails itemDetails1 = new CustomerDetailsItemDetails(String id, double price, double quantity, String name);
ItemDetails itemDetails2 = new CustomerDetailsItemDetails(String id, double price, double quantity, String name);
// 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);
BillingAddress class holds information about billing. TransactionRequest takes an array list of billing details. To set this in TransactionRequest use following code -
BillingAddress billingAddress1 = new BillingAddress(String firstName, String lastName, String address, String city, String postalCode, String phone, String countryCode);
BillingAddress billingAddress2 =new BillingAddress(String firstName, String lastName, String address, String city, String postalCode, String phone, String countryCode);
// 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);
ShippingAddress class holds information about billing. TransactionRequest takes an array list of shipping details. To set this in TransactionRequest use following code -
ShippingAddress shippingAddress1 = new ShippingAddress(String firstName, String lastName, String address, String city, String postalCode, String phone, String countryCode);
ShippingAddress shippingAddress2 =new ShippingAddress(String firstName, String lastName, String address, String city, String postalCode, String phone, String countryCode);
// 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);
Set required transaction information to sdk instance.
TransactionRequest contains following information
- Order Id - unique order id to identify this transaction.
- Amount - amount to charge.
- Customer details - holds an information about customer like name , email and phone.
- Item details - _ holds an information about purchased item, like item id, price etc_.
- Billing Address - holds an address information like city , country, zip code etc.
- Shipping Address - holds an address information like city , country, zip code etc.
- Bill information - _contains custom details in key-value that you want to display on bill print.
All of the above parameters are not nesseccessary to set, It depends on which type of payment method you want to execute. To get more information about required paramter see http://docs.veritrans.co.id/en/api/methods.html#Charge . Sdk will throw error message in case you missed some information right before starting an payment flow.
Create instance of TransactionRequest class.
TransactionRequest transactionRequest = new TransactionRequest(TRANSACTION_ID, TOTAL_AMOUNT);
// Optional Parameters
transactionRequest.setCustomerDetails(CUSTOMER_DETAILS);
transactionRequest.setItemDetails(ITEM_DETAIL_LIST);
transactionRequest.setBillInfoModel(BILL_INFO);
transactionRequest.setBillingAddressArrayList(BILLING_ADDRESS_LIST);
transactionRequest.setShippingAddressArrayList(SHIPPING_ADDRESS_LIST);
There are several payment methods supported by this SDK.
To implement credit card payment read this wiki.
To implement offers or promos for credit card read this wiki.