App2App integration with android library
In this case of integration, you don't need to edit your server-side. In your mobile application, you don't have to implement network communication. We have already do it for you. If you use the Barion Android library you have to add a few lines of code to your existing codebase. The disadvantages are, that you have to notify your own server-side about the payments and your mobile app will contain the POSKey of the shop.
It is highly recommended to obfuscate client applications! We recommend using ProGuard or DexGuard.
Downloads, example
You can download the Barion Android Library from Barion's Github page.
The example project can be downloadable from Barion's Github page.
The library contains the necessary models, so you don't need to implement them.
Integration steps
1. step - Add the library to your project
Download the .aar file from Barion's Github page and put it into your libs directory!
2. step - Edit build.gradle file
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'barionlibrary-1.1.0', ext:'aar')
}
3. step - Edit the AndroidManifest.xml file
At first, you need to edit the AndroidManifest.xml file.
3.1. step - Providing internet access
For the communication, your application must have internet access. So add the internet access permission to your AndroidManifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.barion.example.app2app.libraryintegration">
<uses-permission android:name="android.permission.INTERNET" />
<!-- The rest of your AndroidManifest.xml -->
</manifest>
3.2. step - Add redirect scheme
In order to redirect from the Barion gateway client into the integrator application, a redirect scheme is needed. You can choose anything, but it should be unique. In our example, this is myredirecturl. This scheme will be given by the RedirectUrl property of the Payment/Start request. You need to add this scheme in intent-filter into your result activity section.
<activity
android:name=".activities.PaymentResultActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myredirecturl" />
</intent-filter>
</activity>
4. step - Initiate payment with the library
At any point in the mobile application - where the products that you want to pay are available - you should initiate the payment in the Barion System. The Barion Android Library will check the parameters and if anything is wrong, it will return with an error. The possible error codes can be found on this page.
You can define the environment of the Barion System, which can be our TEST or PRODUCTION environment.
Barion.getInstance().environment = BarionEnvironment.TEST
To initiate the payment you need to implement a few lines of code:
val request = BarionStartPaymentRequest(
posKey = "f199e514-9199-40f9-a210-55a0c75be8cc", // the POSKey of the shop
paymentType = PaymentType.IMMEDIATE,
guestCheckOut = true,
fundingSources = listOf("All"),
paymentRequestId = "12345",
locale = "hu-HU",
currency = "EUR",
transactions = listOf(
PaymentTransaction(
posTransactionId = "f192e544-9199-46f9-a240-55a0c75be8cc",
payee = "[email protected]",
total = 200,
comment = "The new App2App Library",
products = listOf( // list of your products
Product(
name = "The history of money",
description = "The evolution of money from the stoneage to Barion",
quantity = 1.0,
unit = "db",
price = 40.0,
sKU = "APP2APPDEMO_PENZTORT"
)
)
)
),
redirectUrl = "myredirecturl://"
)
Barion
.getInstance()
.startPayment(requireContext(), request)
- The product list contain the products that Product type objects.
- The PaymentSettingsModel object contains the settings, you can read about it on the Payment/Start page.
- The PaymentTransaction object contains the settings of the transactions, you can read about it on the PaymentTransaction page.
- The library will open the gateway web client to the user.
5. step - Get results
The library provides functionality to request the results of a payment.
Barion
.getInstance()
.getPaymentState(request)
if (response.errors.isEmpty()) {
// Handle success case
} else {
// Handle error case
}
If everything went fine you can get every information about the payment from the response variable. If there was an error you will get it in the errors list.