Appearance
Android
Step 1 add Setting on settings.gradle.kts:
kotlin
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url = uri("https://nexus.ifortepay.id/nexus/content/repositories/solutions-sdk-releases/")
credentials {
username = providers.gradleProperty("nexusUsername").get()
password = providers.gradleProperty("nexusPassword").get()
}
}
}
}Step 2 Add the dependency
Implement and declare it in build.gradle.kts:
kotlin
dependencies {
implementation(“com.ifortepay.sdk:payment-core-android:1.0.0”)
// 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 3 Build the PaymentRequest and generate the token
kotlin
val paymentRequest = PaymentRequest(
externalId = "1Ktru19Cp7",
orderId = "ONxeTcEBE6",
currency = "IDR",
source = "payment_page",
paymentMethod = "card",
paymentChannel = "BRICC",
paymentMode = "CLOSE",
paymentDetails = PaymentDetails(
amount = 10000,
isCustomerPayingFee = false,
transactionDescription = "Clothes",
expiredTime = "",
),
itemDetails = listOf(
ItemDetails(
itemId = "Artikel 1",
name = "shirt",
amount = 10000,
qty = 1,
description = "3131"
),
),
customerDetails = CustomerDetails(
email = "[email protected]",
fullName = "Testing",
phone = "08970799128",
ipAddress = "182.30.91.67",
),
billingAddress = BillingAddres(
fullName = "CC Test",
phone = "0893456789",
address = "Kosan Hj Hasan",
city = "Tangerang",
postalCode = "19127",
country = "ID",
),
shippingAddress = ShippingAddres(
fullName = "MCP",
phone = "0893456789",
address = "Bandara Mas",
city = "Malang",
postalCode = "10210",
country = "ID",
),
cardDetails = CardDetails(
cardNumber = "",
cardExpiredMonth = "",
cardExpiredYear = "",
cardCvn = "",
cardHolderName = ""
),
returnUrl = "https://superapp-stg.ifortepay.id/",
callbackUrl = "https://mcpid.free.beeceptor.com",
paymentOptions = PaymentOptions(
useRewards = true,
campaign_code = "002",
tenor = "0"
),
additionalData = "",
)
val credential = "$merchantId:$secretUnbound:$hashKey"
val token = credential.toByteArray().encodeBase64()
val json = Json.encodeToString(paymentRequest)Step 4 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 5 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 realActivityto callNfcAdapter#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)
}
)