Android Developers Manual
Android Developers Manual
for Android
Developer's Manual
Datatrans AG
Swiss E-Payment Competence
Kreuzbühlstrasse 26, 8008 Zürich, Switzerland
Tel. +41 44 256 81 91, Fax +41 44 256 81 98
[Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 2/27
Revisions
Version Date Author Comment
0.1 2011-02-08 Basil Achermann First draft
ieffects ag
1.0 2011-02-15 Basil Achermann 1.0
1.1 2011-12-15 Basil Achermann 1.1 (PostFinance support)
1.2 2013-01-15 Basil Achermann 1.2 (Maintenance release)
1.3 2013-10-29 Basil Achermann MyOne added
1.4 2014-02-13 Basil Achermann Payment options, Android 4.4 fixes
1.5 2014-04-17 Basil Achermann Alias generation in standard mode;
PayPal, PostFinance Card recurring payments
1.5.1 2014-07-03 Basil Achermann Certificate pinning option
1.5.2 2014-08-13 Basil Achermann Swisscom Easypay added
1.6.0 2014-09-12 Basil Achermann Alias generation in hidden mode
1.6.1 2014-11-27 Basil Achermann PostFinance Card registration
1.6.2 2015-01-09 Basil Achermann Target SDK 21 support (Android 5)
1.7.0 2015-03-16 Basil Achermann Easypay Alias support, Lastschrift (ELV) method added,
context abstraction (DisplayContext)
1.7.1 2015-04-02 Basil Achermann ELV aliases with bankrouting
1.7.2 2015-04-16 Basil Achermann Language fix
1.8.0 2015-07-17 Basil Achermann SwissBilling added
1.9.0 2015-10-16 Basil Achermann JCB added
2.0.0 2015-10-29 Basil Achermann TWINT added
2.0.1 2016-06-29 Basil Achermann TWINT with new payment pages
2.1.0 2016-07-14 Patrick Schmid TWINT alias support
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 3/27
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 4/27
Table of Contents
1 Introduction 6
2 Overview 8
3 Key Concepts 10
3.1 PaymentProcessAndroid 10
3.2 Library Invocation 10
3.3 State Notification 12
3.4 Recurring payments 13
3.4.1 (De-)Serialization to/from JSON of recurring payment method 13
3.5 Payment method registration (alias request) 14
3.5.1 Payment method selection/input by library (standard mode) 14
3.5.2 Payment method preselected by app, input by library 14
3.5.3 Credit card selection/input by app (hidden mode) 15
3.6 Deferred Authorization 15
3.7 Merchant Notification 16
3.8 Error Handling 17
3.8.1 Technical Errors 17
3.8.2 Business Errors 17
3.8.3 SSL Errors 17
3.9 New JSON API Flow 17
3.9.1 Credit card selection/input by app (hidden mode) 18
4 Mandatory settings 19
4.1 TWINT 19
4.1.1 TWINT not installed error 19
4.2 PayPal 19
4.3 SwissBilling 20
4.4 Byjuno 20
4.5 SwissPass 20
4.6 POWERPAY 21
4.7 Paysafecard 21
4.8 Samsung Pay 21
4.8.1 Configure apps 21
4.8.2 Supported Networks (Cards) 21
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 5/27
5 API 24
6 Library Integration 25
7 Appendix 27
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 6/27
1 Introduction
Datatrans AG, leading Swiss payment service provider, developed Datatrans iOS
Payment Library, allowing application developers to easily integrate Datatrans AG’s
payment services natively on the iPhone and iPad. Following its success, a version for
Android-based devices has been developed.
This manual provides guidance on library installation, invocation, and other issues of
importance to developers wishing to integrate Datatrans Payment Library (DTPL) for
Android into their mobile applications.
Chapter 1 – Introduction
Explains this document’s structure and content.
Chapter 2 – Overview
Gives an overview of the Datatrans Payment Library for Android.
Chapter 4 – API
Gives an overview over the library’s classes.
Chapter 5 – Integration
Explains library installation and integration into Eclipse/ADT.
1.2 Scope
This document provides information on using DTPL to create mobile commerce apps on
Android devices. As such, it is primarily aimed at developers.
It is assumed that the reader is already familiar with Datatrans AG’s products and
services. Also, knowledge of the Java programming language, Android SDK, as well as
basic understanding of Eclipse and the ADT plugin are required.
Detailed description of the library’s API is not part of this document. Javadoc
documentation is provided in a separate directory.
1.3 Conventions
Throughout this document, the following styles are used:
Name
Emphasized technical terms, organization/product names
Path
File system paths, file names etc.
Class
Class and method names
void codeSample() {
code(); // sample code
}
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 7/27
Code listings
<replaceable>
Text meant to be replaced with data by the developer
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 8/27
2 Overview
2.1 Payment Methods
The library currently supports the following credit cards: VISA, MasterCard, Diners Club,
American Express, JCB, UATP, Manor MyOne, Discover, Coop Supercard and Boncard
(Lunch-Check). Additionally, PayPal, PostFinance Card/E-finance, Swisscom Easypay,
Lastschrift (ELV), SwissBilling, Samsung Pay, Byjuno, Google Pay, TWINT, Reka, SwissPass,
POWERPAY as well as Paysafecard are supported.
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 9/27
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 10/27
3 Key Concepts
3.1 PaymentProcessAndroid
The library’s core component is the PaymentProcessAndroid class. The process can be
started with or without prior selection of a payment method. If no payment method is
supplied, the process starts with a selection web page in full screen format. The user can
cancel the process by pressing the back button present on all Android devices.
If payment method is selected by the app, the web view can be displayed either full
screen or in an Android ViewGroup. In the latter case, the application carries the
responsibility for screen design, controls (e.g. cancel button, hardware back button) or
other UI elements. The library just plugs its web view into the view group.
Listing 3-1: Payment process invocation with several payment methods (Standard mode)
Some notes:
• The process in this example is started in test mode. No actual payments can be
made. Test mode is off by default.
• context is the Android app context
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 11/27
[Link](true);
[Link](myListener);
[Link]();
Table 3-1 lists all payment methods that can be used in this mode.
PaymentMethodType PaymentMethod Class Description
VISA, MASTERCARD, PaymentMethod Credit card (standard mode)
DINERS, AMEX, JCB, UATP,
MYONE, DISCOVER,
SUPERCARD
VISA, MASTERCARD, PaymentMethodCreditCard Credit card (hidden mode)
DINERS, AMEX, JCB, UATP,
MYONE, DISCOVER,
SUPERCARD
VISA, MASTERCARD, AliasPaymentMethodCreditCard Credit card (alias/recurring
DINERS, AMEX, JCB, UATP,
payment)
MYONE, DISCOVER,
SUPERCARD
BONCARD PaymentMethod Boncard (Lunch-Check)
PFEFINANCE PaymentMethod PostFinance E-finance
PFCARD PaymentMethod PostFinance Card
PAYPAL PaymentMethod PayPal
EASYPAY PaymentMethod Swisscom Easypay
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 12/27
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 13/27
@Override
public void paymentProcessStateChanged(PaymentProcessAndroid process) {
switch ([Link]()) {
case COMPLETED:
AliasPaymentMethod pm = [Link]();
if (pm != null) {
// serialize and securely store pm for reuse
}
break;
case CANCELED:
// ignore, abort checkout, whatever...
break;
case ERROR:
Exception e = [Link]();
if (e instanceof BusinessException) {
BusinessException be = (BusinessException)e;
int errorCode = [Link](); // Datatrans error code if needed
// display some error message
} else {
// unexpected technical exception, either fatal TechnicalException or
// [Link] (certificate error)
}
break;
}
}
Please note that notifications are synchronously performed on the thread responsible
for the state change. This is not necessarily the UI-thread. UI-actions should therefore be
posted to the UI-thread using [Link].
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 14/27
Important: Even if an app has its own credit card input dialog it must never store the
original credit card number or CVV.
[Link](true);
[Link]([Link]);
[Link]();
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 15/27
[Link](true);
[Link]([Link]);
[Link]();
[Link]();
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 16/27
// -----
// -----
// Check-out:
// use transaction id, refno and final amount for the actual authorization
// (server-to-server, or
PaymentProcessAndroid(DisplayContext, PaymentAuthorizationRequest))
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 17/27
// if available
aliasCC=70323122544331174
expy=21
expm=12
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 18/27
[Link](true);
[Link](myListener);
[Link]();
Listing 3-10: Invoking the library using the new API flow
Moreover, various parameters from the PaymentOptions object can be added to the initial
request to the Datatrans backend. Refer to the online documentation to see which ones are
supported.
3.9.1 Credit card selection/input by app (hidden mode)
If the credit card selection and input is handled by the merchant app, the details must
not be sent in the initial request to the Datatrans backend. Instead, the credit card
information should be passed to the PaymentProcessAndroid.
String mobileToken = initializePaymentInBackend();
[Link](true);
[Link](myListener);
[Link]();
Listing 3-11: Hidden mode credit card payment using the new API flow
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 19/27
4 Mandatory settings
4.1 TWINT
DE Auf diesem Gerät ist keine oder eine veraltete Version von
TWINT installiert. Bitte aktualisieren oder installieren Sie die
TWINT App.
EN No or an outdated version of TWINT is installed on this device.
Please update or install the TWINT app.
FR TWINT n’est pas installée ou une version obsolète de TWINT est
installée sur cet appareil. Veuillez mettre à jour ou installer
l’app TWINT.
IT Su questo dispositivo non è installato TWINT, oppure è
installata una versione obsoleta. La preghiamo di aggiornare o
installare l'App TWINT.
4.2 PayPal
For PayPal payments an external web process is used. After this web process has
finished, a callback to your app is issued. In order to receive this callback, you need to
define the Datatrans relay activity with an intent filter in your app manifest for a
defined scheme as shown in Listing 4-12, and configure the setAppCallbackScheme()
option (Listing 4-13).
Keep in mind that the URI scheme must be unique to the shopping app and the activity.
Do not use actual protocols or file types such as “http”, “mailto”, “pdf” etc., generic names
like “ticket”. An example would be the package name extended by an identifier dtpl.
<activity
android:name="[Link]"
android:launchMode="singleTask"
android:enabled="false"
android:theme="@android:style/[Link]">
<intent-filter>
<action android:name="[Link]" />
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 20/27
[Link]()
.setAppCallbackScheme("[Link]");
4.3 SwissBilling
For SwissBilling transactions, a Customer object has to be created and configured via
the setCustomer() option. In addition, an optional SwissBillingPaymentInfo can be
initialized and set via the setSwissBillingPaymentInfo() option (Listing 4-15). An example
of both configurations can be seen in the Javadoc of the SwissBillingPaymentInfo class.
[Link]().setCustomer(customer);
[Link]()
.setSwissBillingPaymentInfo(swissBillingInfo); // optional
4.4 Byjuno
For Byjuno transactions, a Customer object has to be created and configured via the
setCustomer() option. In addition, an optional ByjunoPaymentInfo can be initialized and
set via the setByjunoPaymentInfo() option (Listing 4-16). An example of both
configurations can be seen in the Javadoc of the ByjunoPaymentInfo class.
[Link]().setCustomer(customer);
[Link]()
.setByjunoPaymentInfo(byjunoInfo); // optional
4.5 SwissPass
For SwissPass transactions, there are four possible ways to configure the library:
• Doing nothing
• Provide a Customer object
• Provide a SwissPassPaymentInfo object
• Provide both objects
The Customer and SwissPassPaymentInfo can be set via the setCustomer() or
setSwissPassPaymentInfo() option respectively (Listing 4-17). Keep in mind that the user
needs to put in the information that are not already provided.
If a Customer is given, then the contents of the object must match the details stored in
the given SwissPass account. Example configurations can be seen in the Javadoc of the
SwissPassPaymentInfo class.
[Link]().setCustomer(customer);
[Link]().setSwissPassPaymentInfo(swissPassInfo);
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 21/27
4.6 POWERPAY
For POWERPAY transactions, a Customer object has to be created and configured via
the setCustomer() option. In addition to the default parameters, this object must contain
a gender and an address with a city. The date of birth can be omitted but the user will
be prompted to enter it manually in that case.
Address address = new Address("Max", "Muster", "via streccione 2", "6900");
[Link]("Lugano"); // required
Customer customer = new Customer();
[Link](address);
[Link]("male"); // required
[Link](new Date(1980, 1, 1)); // optional
[Link]().setCustomer(customer);
4.7 Paysafecard
For Paysafecard transactions, a unique ID has to be set via the
setPaysafecardMerchantClientId() option for identifying a customer. As an example, this
could be the unique ID of your customer as registered within your database. If you are
using the e-mail address or any other personal information, please encrypt it.
[Link]().setPaysafecardMerchantClientId(id);
Listing 4-20 Configuration for Samsung Pay in the manifest of the test app
Note: The tag with name spay_debug_api_key must be defined even if it is empty.
For your release app, you only have to add:
<application>
...
<meta-data android:name="debug_mode" android:value="N" />
<meta-data android:name="spay_sdk_api_level" android:value="2.3" />
</application>
Listing 4-21 Configuration for Samsung Pay in the manifest of the production app
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 22/27
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 23/27
Listing 4-27 Configuration for (de-)serializing recurring payment methods to/from JSON in the
[Link]
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 24/27
5 API
Figure 5-3 gives an overview of the library’s classes. Full API documentation is located in
the javadoc directory of the documentation folder.
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 25/27
6 Library Integration
6.1 Package Contents
The library is distributed as a single .zip file with a directory structure shown in Table 6-2.
Directory Description
/doc Contains this documentation and Javadoc.
/[Link] AAR file to be added to Android Studio
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 26/27
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]
Version: 4.6.5
Datatrans Payment Library for Android
Date: 2021-12-16
Developer's Manual
Page: 27/27
7 Appendix
7.1 List of Illustrations
Figure 2-1: Payment process overview 9
Figure 3-2: Flow of a payment with deferred authorization (Google Pay) 16
Figure 5-3: Library classes 24
Figure 6-4: Import wizard for AAR package 25
Datatrans AG, Kreuzbühlstrasse 26, CH 8008 Zürich - Tel. +41 44 256 81 91, Fax +41 44 256 81 98 - [Link]