Skip to main content

Introduction

The Spotflow Android SDK empowers developers to seamlessly integrate payment functionalities into their Android applications. It provides UI components and methods that allow you accept payment in your Android app.

Project Requirements

To integrate the Spotflow Android SDK into your project, ensure the following prerequisites are met:

  • Android Studio 4.1 or later
  • Android SDK API level 21 or higher while the minimum supported SDK version is 15
  • Android Gradle Plugin 7.2 and above
  • Gradle 7.1.3 and above
  • AndroidX
Beta Release

The Android SDK is currently a beta release. If you encounter any issues, kindly reach out to our support team at support@spotflow.one.

Installation

  1. Add the Spotflow SDK dependency to your app-level build.gradle file:
dependencies {
implementation 'com.spotflow:spotflow-android:latest_version'
}
  1. Add the Internet permission to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET" />
  1. Sync your project with Gradle files to download the SDK into your project. Upon installation, you gain access to the UI components and methods to accept seamless payment experiences in your Android app.

Parameters Required by the Library

ParameterTypeDescription
merchantIdStringThe unique identifier for the merchant.
planIdStringThe unique identifier for the payment transaction.
keyStringThe API key for authenticating the transaction.
encryptionKeyStringThis key is used to encrypt the card.
customerEmailStringThe email address of the customer.
customerNameString?The name of the customer (optional).
customerPhoneNumberString?The phone number of the customer (optional).
customerIdString?The unique identifier for the customer (optional).
paymentDescriptionString?A description of the payment (optional).
appLogoInt?The resource ID for the app logo (optional).
appNameString?The name of the app (optional).

Usage with Jetpack Compose

For users utilizing Jetpack Compose, you can directly use the composable function PaymentUI.

Integration Example

// MainActivity.kt
package com.example.app

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import com.spotflow.compose.PaymentUI

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
PaymentUI(
merchantId = "your_merchant_id",
paymentId = "your_payment_id",
fromCurrency = "USD",
toCurrency = "EUR",
amount = 100.0,
key = "your_key",
customerEmail = "customer@example.com",
customerName = "John Doe",
customerPhoneNumber = "1234567890",
paymentDescription = "Payment for services",
appLogo = R.drawable.your_logo,
appName = "Your App",
onSuccess = { transactionId, paymentData ->
// Handle successful payment
},
onFailure = { errorCode, errorMessage ->
// Handle payment failure
}
)
}
}
}

Usage by Launching an Activity

For users who do not use Jetpack Compose, you can integrate the payment functionality by launching a provided activity.

Integration Example

// MainActivity.kt
package com.example.app

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.spotflow.compose.PaymentActivity

class MainActivity : AppCompatActivity() {

private val PAYMENT_REQUEST_CODE = 1001

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

// Initialize payment
SpotFlowPaymentActivity.start(
customerEmail: "customer@example.com" ,
customerName: "John Snow", //optional
customerPhoneNumber: "000-000-000", //optional
customerId: "unique_id" //optional
merchantId: "unique_id"
planId: "plan_id",
key: "your_api_key",
encryptionKey: "encryption_key",
paymentDescription: "Product purchase",
requestCode = PAYMENT_REQUEST_CODE
)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == PAYMENT_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
val transactionId = data?.getStringExtra("transactionId")
val paymentData = data?.getSerializableExtra("paymentData") as? Map<String, Any>
// Handle successful payment
} else if (resultCode == Activity.RESULT_CANCELED) {
val errorCode = data?.getStringExtra("errorCode")
val errorMessage = data?.getStringExtra("errorMessage")
// Handle payment failure
}
}
}
}

Help

Feel free to create issues and pull requests on GitHub if you need any help.