Accept payments in your own Android application thanks to the HiPay Android SDK.
This integration allows you to accept payments in your Android app very quickly. In this scenario, your customers are presented with a built-in native payment screen. Yet, you won’t be able to do much customization of the payment workflow.
Advantages of this integration: Simplicity and speed.
Before going through this part, make sure you have followed the SDK configuration.
Example
In this example, we assume that you will test the integration in an activity named DemoActivity, but it can be anywhere in your code base. Please find below the full code example. Details can be found in comments as well.
/* This is an activity example,
* the place where you put this code
* is really up to you. */
public class DemoActivity extends AppCompatActivity {
...
private String mSignature;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
}
/* We assume that you have defined a button in the
* associated layout activity with
* the method "onClickPayButton" as touch callback. */
public void onClickPayButton(View view) {
/* Create a payment page request which
* contains information about your order */
PaymentPageRequest request = new PaymentPageRequest();
request.setAmount(155.50f);
request.setCurrency("EUR");
request.setOrderId("TEST5987");
request.setShortDescription("Outstanding shirt");
/* Below, optional properties are defined as well.
* Check the PaymentPageRequest documentation
* for the full list of parameters */
request.getCustomer().setCountry("FR");
request.getCustomer().setFirstname("John");
request.getCustomer().setLastname("Doe");
request.getCustomer().setEmail("[email protected]");
// Tells HiPay to bypass 3-D Secure
request.setAuthenticationIndicator(CardTokenPaymentMethodRequest.AuthenticationIndicator.Bypass);
CustomTheme customTheme = new CustomTheme(
android.R.color.holo_blue_light,
android.R.color.holo_blue_dark,
android.R.color.white);
/* Now, we instantiate and present the payment
* screen, using the payment page request, the signature
* and the above custom theme,
* assuming that the signature is not null */
PaymentScreenActivity.start(this, request, mSignature, customTheme);
}
}
Implementation note
The signature parameter is required for security purposes. Please refer to the signature section for details.
Transaction callback
onClickPayButton
method is called (you may add a button targeting this method upon a touch).
Once the payment workflow finishes, the result is called in the activity through your onActivityResult(int, int, Intent)
method.
You may copy and paste all or part of the example above. Please find below some additional details. public class DemoActivity extends AppCompatActivity {
...
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PaymentPageRequest.REQUEST_ORDER) {
if (resultCode == R.id.transaction_succeed) {
Bundle transactionBundle = data.getBundleExtra(Transaction.TAG);
Transaction transaction = Transaction.fromBundle(transactionBundle);
// Transaction object received, check its "state" property to know if the transaction was completed
} else if (resultCode == R.id.transaction_failed) {
Bundle exceptionBundle = data.getBundleExtra(Errors.TAG);
ApiException exception = ApiException.fromBundle(exceptionBundle);
// Payment workflow did fail, check the exception object for more info
}
}
}
}
Payment Page Request
As mentioned in the comments, some parameters are optional. However, we strongly encourage you to provide some parameters such as the name of your customers if you have it. By doing so, the card holder’s name will be filled in automatically.
Not all the parameters have been set in the example of the payment page request definition above. There are many properties that you can use in order to provide more details about the order, for instance:
multiUse
to tell the Secure Vault that you may re-use the credit card token in the future for recurring payments;paymentProductCategoryList
to tell which categories of payment products should appear on the payment screen;paymentProductList
to configure precisely the payment methods which should appear on the payment screen;customData
to send additional data alongside the transaction which you can get back later.
Check out the PaymentPageRequest
class documentation for more information about all the properties you can set.
Callback method
onActivityResult(int, int, Intent)
method in order to end your check-out process, present a confirmation message to your users, etc.