Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Note

→ Updated version will be provided end of 2023


Table of Contents

1. Overview


This is the documentation for the Axepta Android SDK, which describes how to integrate payments in your Android app.

...

Add jCenter in the main build.gradle:

allprojects {

repositories {

jcenter()

}

}


Then add the following line to your app build.gradle:

implementation 'com.axepta.sdk:lib:<current_version>'


and sync gradle.


4.How to implement

...

Set the provided parameters in the file strings.xml


<resources>

<string name="axepta_merchant_id">XXX</string>

<string name="axepta_auth_url">XXX</string>

</resources>


4.2. Authentication


One requirement for the Mobile SDK is to insert the respective Merchant’s URL in order to be able to receive the auth token. The SDK is responsible for retrieving the token and use it appropriately when executing payment requests.

For more information, see the Axepta documentation.


<resources>

<string name="axepta_merchant_id">XXX</string>

<string name="axepta_auth_url">XXX</string>

</resources>


4.3. Making a payment


Assume your app user inserted some products into the basket, typed the shipping address and now wants to make the payment - that means you want to offer the user different payment options he can choose from.

...

First, initialize an instance of the SDK, activity should be instance of FragmentActivity.


Axepta axepta = Axepta.with(getActivity())


4.3.1. Available payment methods


To get all the available payment methods you need to call:


axepta.requestPaymentMethods()

.subscribeOn(Schedulers.io())

.observeOn(AndroidSchedulers.mainThread())

.subscribe((paymentMethods, throwable) -> {

if (throwable != null) {

// manage error

Log.e(TAG, "PaymentMethods error: ", throwable);

return;

}

// manage the paymentMethods list (List<PaymentMethod>)

});


You receive a payment icon and localized description foreach payment method.


4.3.2. Payment data


The next step is to select a payment method, then fill payment data with the proper key and values based on the documentation for your payment method (more details on Payment can be found in the Axepta documentation). You need to set valid parameters for your payment or the transaction will not work.


Payment getPayment(@NonNull PaymentMethod paymentMethod) {

Payment payment = paymentMethod.getPayment();

payment.setParamWithKey("TransID", "********");

payment.setParamWithKey("Amount", "100");

payment.setParamWithKey("Currency", "EUR");

payment.setParamWithKey("URLSuccess", "http://*****/api/success");

payment.setParamWithKey("URLNotify", "https://*****/axepta/index.php");

payment.setParamWithKey("URLFailure", "http://*****/api/failure");

payment.setParamWithKey("RefNr", "******");

payment.setParamWithKey("OrderDesc", "Tests");

payment.setParamWithKey("AddrCity", "Berlin");

payment.setParamWithKey("FirstName", "Lorem");

payment.setParamWithKey("LastName", "Ipsum");

payment.setParamWithKey("AddrZip", "10000");

payment.setParamWithKey("AddrStreet", "Berlin");

payment.setParamWithKey("AddrState", "AL");

payment.setParamWithKey("AddrCountryCode", "DE");

payment.setParamWithKey("Phone", "01777777124");

payment.setParamWithKey("LandingPage", "Login");

payment.setParamWithKey("eMail", "******-accounts@****.com");

payment.setParamWithKey("ShopID", "1");

7

payment.setParamWithKey("Subject", "******-accounts@****.com");

payment.setParamWithKey("Language", "en");

payment.setParamWithKey("Channel", "APP");

payment.setParamWithKey("MerchantID", "****");

return payment;

}


The method setParamWithKey() returns true if the value will be set successfully for the specified key.

...

Now you know the available payment methods and you have configured them. It’s time to show the payment methods to the user.


4.3.2.1. WeChat Pay


When using WeChat Pay as a payment method you also have to add the class WXPayEntryActivity which extends from WeChatPayEntryActivity.


public class WXPayEntryActivity extends WeChatPayEntryActivity {

}


This class needs to be placed inside a package called com.mypackage.wxapi, where com.mypackage is your applicationId defined in your app build.gradle.

...

Besides that, you have to define the following Strings in your string.xml.


<string name="axepta_wechat_app_id" translatable="false">your wechat app id</string>

<string name=" axepta_wechat_mch_id" translatable="false">your wechat merchant id</string>

<string name=" axepta_wechat_key" translatable="false">your wechat key</string>


4.3.2.1. PayPal


For this payment method, the Chrome Custom Tab is used. To get back from the Chrome Custom Tab to your app after payment is done (or canceled), you have to redirect to a custom uri from your merchant backend.

...


Following the example above, you must define the two Strings as follows:


<string name="axepta_paypal_intent_uri_host"

translatable="false">com.shop.demo.PayPalReturn</string>

<string name="axepta_paypal_intent_uri_scheme" translatable="false">merchant</string>


Optional: You can define the color of the Chrome Custom Tab toolbar in your colors.xml as follows:


<color name="colorCctToolbar">#3F51B5</color>



4.3.3. Make the checkout


Now that you have configured the SDK, selected the payment method and filled the values for your payment data, you are ready to make a payment.

...

Start the checkout by instantiating subscription object (Observable). The Axepta class is a toplevel class that facilitates the payment procedure. It is responsible for validating payment data and instantiating a WebView when a new payment is triggered by passing the respective payment and paymentMethod.


Disposable disposable = axepta

.withPaymentMethod(method)

.setWebViewListener(() -> {

Log.i(TAG, "[WebViewClient] onPageFinishedLoading");

})

.checkout()

.subscribeOn(Schedulers.io())

.observeOn(AndroidSchedulers.mainThread())

.subscribe(o ->

{

Log.v(TAG, "Payment received");

}, throwable -> {

if (throwable instanceof AxeptaError) {

Log.e(TAG, "Axepta Error " + (throwable));

showErrorAlert((AxeptaError) throwable);

} else if (throwable instanceof InternalError) {

Log.e(TAG, "Internal Error boolean isPaymentCanceled(): " + ((InternalError)

throwable).isPaymentCanceled());

} else {

Log.e(TAG, "Payment error: ", throwable);

}

});


Observable<T> subscribeOn(Schedulers.io()) will execute the operation on the background thread. When you subscribe to this observable you can show a loading indicator to the user. To get notified when the Webview is loaded you can set the listener OnWebViewLoadedListener and hide the loading indicator.

...

To do this you have to add this flag in your AndroidManifest.xml file:


<activity android:name=".MyActivity"

android:configChanges="orientation|screenSize"

android:label="@string/app_name">


In this case you will have to handle the configuration changes for your activity.

...