Skip to content

Android

Step 1 Add the dependency

Place the .aar in your app module's libs/ folder and declare it in build.gradle.kts:

kotlin
dependencies {
    implementation(files("libs/PaymentGatewaySDK.aar"))

    // Transitive dependencies the SDK relies on — declare explicitly
    implementation("io.ktor:ktor-client-okhttp:3.1.3")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
}

Step 2 Build the PaymentRequest and generate the token

kotlin
val paymentRequest = PaymentRequest(
    externalId = "1Ktcu19Cp7",
    orderId = "ONxeTcEBE6",
    currency = "IDR",
    source = "payment_page",
    paymentMethod = "card",
    paymentChannel = "BRIQC",
    paymentMode = "CLOSE",
    paymentDetails = PaymentDetails(
        amount = 10_000L,
        isCustomerPayingFee = false,
        transactionDescription = "Order #1234",
        expiredTime = ""
    ),
    itemDetails = listOf(
        ItemDetails(
            itemId = "SKU-1",
            name = "Shirt",
            amount = 10_000,
            qty = 1,
            description = ""
        )
    ),
    // ...customerDetails, billingAddress, shippingAddress,
    // cardDetails, returnUrl, callbackUrl, paymentOptions
)

val credential = "$merchantId:$secretUnbound:$hashKey"
val token = credential.toByteArray().encodeBase64()
val json = Json.encodeToString(paymentRequest)

Step 3 Embed PaymentGatewayScreen in your navigation graph

The reference demo app embeds the SDK as a Compose Navigation route, passing token and jsonData as navigation arguments:

kotlin
composable(
    route = "PaymentScreen/{token}/{jsonData}",
    arguments = listOf(
        navArgument("token") { type = NavType.StringType },
        navArgument("jsonData") { type = NavType.StringType }
    )
) { backStackEntry ->

    val token = backStackEntry.arguments?.getString("token") ?: ""
    val jsonData = backStackEntry.arguments?.getString("jsonData") ?: ""

    PaymentGatewayScreen(
        token = token,
        jsonData = jsonData,
        onOpenNfc = {
            /* see Section 16.3 */
        }
    )
}

Step 4 Receive the result

PaymentGatewayScreen forwards onResult through to the underlying PaymentViewModel constructor. To receive it, pass a callback at the point where you navigate into the route — or, for simpler embeds without navigation, construct PaymentGatewayScreen directly:

kotlin
PaymentGatewayScreen(
    token = token,
    jsonData = jsonData,
    onOpenNfc = {
        /* ... */
    },
    onResult = { result: PaymentSdkResult ->
        if (result.isSuccess) {
            Log.d("Payment", "Success, link=${result.link}")
        } else {
            Log.d(
                "Payment",
                "Failed: ${result.responseMessage}"
            )
        }
    }
)

NFC context wiring on Android

openNfc(context: Any) expects a real Activity to call NfcAdapter#enableReaderMode(). Resolve it from the current Compose context rather than passing the Application context.

kotlin
val context = LocalContext.current

PaymentGatewayScreen(
    token = token,
    jsonData = jsonData,
    onOpenNfc = {
        val activity = runCatching {
            context.findActivity()
        }.getOrNull() ?: return@PaymentGatewayScreen

        viewModel.openNfc(activity)
    }
)

Step 5 Setup ENV

Rename gradlewe to .env (in the same directory, alongside settings.gradle.kts)

Payment Gateway API Base URL (staging/production)

API_BASE_URL=https://api-stage.mcpayment.id/card-v2/v1/charge

API_ENVIRONMENT=staging API_TIMEOUT_MS=30000

// EnvConfig generation command // To generate EnvConfig, copy the command below and run it in the terminal from the project root. ./gradlew :payment-core:generateEnv

##Step 6 Build Sdk Library Android & iOS

After generate EnvConfig write this on your terminal root project :

kotlin
./gradlew :payment-core:assembleRelease

and then this

kotlin
./gradlew :payment-core:buildSdk

and last

kotlin
./gradlew :payment-core:exportSdk

and it will distribute the sdk for both android &iOS in folder dist

note : everytime you change the .env, you need to repeat step 5 & 6 before consume sdk

iFortepay API Documentation