Set Up App2App
App2App integration enables your Android application to send payment commands to Paynt on the same device. Your app handles product selection and checkout, then triggers Paynt to process the payment—your app moves to the background while the payment screen appears. The device is then handed to the customer to complete the transaction.
This mode suits merchants who have their own application and need to accept payments for goods or services. It also supports more complex setups, allowing the terminal to interact with external systems like order management platforms or POS devices.
This guide helps you integrate the Paynt POS app with your Android application and complete your first App2App transaction.
What You'll Need
Hardware and Software:
- A computer with Android Studio installed (download from developer.android.com)
- An Android device or emulator running Android 5.0 (Lollipop) or newer
- The Paynt Payment App installed on your device (version 0.3.6 or newer)
Development Setup:
- An Android app project created in Android Studio
- Internet connection to download required libraries
- The test application source code for reference
Key Concepts
Before diving into the code, here's a quick overview of the concepts used in this guide:
| Concept | Description |
|---|---|
| Intent | A message that tells Android to perform an action. In this case, we use an intent to launch Paynt and request a payment. Paynt processes the transaction and returns the result to your app. |
| JSON | A data format for exchanging information between applications. Example: {"name": "John", "age": 30}. We use the Gson library to convert payment data to JSON automatically. |
| Kotlin | The programming language used in the code examples below. |
Step 1: Add the Gson Library
Add the Gson library to your project. This library converts payment data to JSON format.
- Open your app's
build.gradle.ktsfile (in theappfolder). - Find the
dependenciessection and add Gson:
dependencies {
implementation("com.google.code.gson:gson:2.10.1")
// ... your other dependencies
}
- Click Sync Now when Android Studio prompts you.
Step 2: Create the Payment Activity
Create the activity that will handle payment processing.
- In Android Studio, right-click on your package name.
- Select New → Kotlin Class/File.
- Name it
PaymentActivityand make it extendAppCompatActivity.
package com.yourcompany.yourapp // Your package name here
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.widget.Button
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import com.google.gson.Gson
class PaymentActivity : AppCompatActivity() {
// Listens for results from Paynt
private val paymentLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
handlePaymentResult(result.resultCode, result.data)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_payment)
val payButton = findViewById<Button>(R.id.payButton)
payButton.setOnClickListener {
startPayment()
}
}
private fun startPayment() {
val paymentDetails = mapOf(
"transType" to "SALE",
"uti" to "",
"amountTrans" to 2500, // €25.00 in cents
"printEnabled" to true,
"reference" to ""
)
val jsonPayment = Gson().toJson(paymentDetails)
val intent = Intent("com.paynt.payment.action.START_TRANSACTION").apply {
data = Uri.parse("transaction://paynt")
addCategory(Intent.CATEGORY_DEFAULT)
putExtra("start_transaction_request", jsonPayment)
}
if (intent.resolveActivity(packageManager) != null) {
paymentLauncher.launch(intent)
} else {
Toast.makeText(
this,
"Please install the Paynt Payment App",
Toast.LENGTH_LONG
).show()
}
}
private fun handlePaymentResult(resultCode: Int, data: Intent?) {
when (resultCode) {
Activity.RESULT_OK -> {
val responseJson = data?.getStringExtra("start_transaction_response")
if (responseJson != null) {
val response = Gson().fromJson(responseJson, Map::class.java)
val approved = response["transApproved"] as? Boolean ?: false
if (approved) {
Toast.makeText(this, "Payment Successful!", Toast.LENGTH_SHORT).show()
Log.d("Payment", "Auth Code: ${response["authCode"]}")
} else {
Toast.makeText(this, "Payment Declined", Toast.LENGTH_SHORT).show()
}
}
}
Activity.RESULT_CANCELED -> {
Toast.makeText(this, "Payment Cancelled", Toast.LENGTH_SHORT).show()
}
}
}
}
Step 3: Create the Layout
Create a layout file for your payment screen.
- In Android Studio, navigate to
res/layout. - Create a new layout file named
activity_payment.xml. - Add the following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Payment Demo"
android:textSize="24sp"
android:layout_marginBottom="32dp"/>
<Button
android:id="@+id/payButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pay €25.00"
android:textSize="18sp"/>
</LinearLayout>
Step 4: Test Your Integration
Run your app and verify the payment flow works correctly.
- Ensure the Paynt app is installed on your test device.
- Run your app from Android Studio.
- Tap Pay €25.00.
- The Paynt app should open and display the payment screen.
- Complete the payment prompts.
- Verify that "Payment Successful!" appears when done.
How It Works
Here's what happens when the user taps the payment button:
- Payment details created – Your app builds a data object containing the transaction type (SALE), amount (2500 cents = €25.00), and print settings.
- JSON conversion – Gson converts the payment details to JSON format.
- Intent sent – Your app sends an intent to launch Paynt with the payment data.
- Paynt processes payment – Paynt opens, handles the transaction, and collects payment from the customer.
- Results returned – Paynt sends the result (approved/declined, authorization code, etc.) back to your app.
- Result displayed – Your app shows the outcome to the merchant.
Troubleshooting
| Problem | Solution |
|---|---|
| "Please install the Paynt Payment App" appears | Ensure Paynt app version 0.3.6 or newer is installed on the device. |
| App crashes when clicking the button | Check Logcat for error messages. Verify the Gson library is added correctly and the layout file contains a button with id payButton. |
| Nothing happens when clicking the button | Verify the button click listener is set up correctly. Check Logcat for errors. |
Next Steps
Now that you have a working integration:
- Explore the How-To Guides to learn about refunds and other transaction types. Get started here.
- Read the Explanation section to understand the underlying concepts. Get started here.
- Use the Reference section for detailed code descriptions and API specifications. Get started here.
Note: The example above uses a simplified approach for learning purposes. For production apps, refer to the How-To Guides for the recommended implementation using proper data models.