Pay by Card Integration (Standalone)

This section covers the standalone Pay by Card mode, which shows only card payment options in a dedicated sheet.

Integration

  1. Fetch session configuration
private suspend fun fetchSessionConfiguration(): PBLConfiguration {
    val response = apiClient.initPayment()
    return PBLConfiguration(
        sessionId = response.sessionId,
        ephemeralKey = response.ephemeralKey,
        userId = "user_id_from_app",
        environment = PBLEnvironment.SANDBOX
    )
}
  1. Launch the Pay By card
private var payablSDK: PayablSDK? = null

private fun placeOrderWithSessionInit() {
    lifecycleScope.launch {
        val configuration = fetchSessionConfiguration()
        payablSDK = PayablSDK.init(configuration)
        payablSDK?.startPayByCard(supportFragmentManager) { result ->
            handlePaymentResult(result)
        }
    }
}
  1. Handle results
private fun handlePaymentResult(result: PBLPaymentResult) {
    when (result) {
        is PBLPaymentResult.Completed -> {
            // Payment successful
        }
        is PBLPaymentResult.Canceled -> {
            // User cancelled
        }
        is PBLPaymentResult.Failed -> {
            // Payment failed
        }
    }
    payablSDK = null
}

Best Practises

DO:

  • Create a new session for each payment attempt.
  • Initialize PayablSDK only when user starts payment.
  • Clean up payablSDK after receiving a result.

DON'T:

  • Reuse sessions across multiple payments.
  • Initialize SDK at app startup.
  • Share sessions between users.

Testing

Sandbox Configuration

Use sandbox while developing:

val configuration = PBLConfiguration(
    sessionId = "sandbox_session_id",
    ephemeralKey = "sandbox_ephemeral_key",
    userId = "test_user_123",
    environment = PBLEnvironment.SANDBOX
)

Test Scenarios (Pay by Card)

Here are the comprehensive test scenarios for Pay by Card using the provided test card numbers. Use Sandbox environment (PBLEnvironment.SANDBOX) for all tests.

Test Card Details

  • Expiry Date: Any future date (MM/YY later than current date, e.g., 12/27)
  • CVV/CVC: Any 3 digits (e.g., 123)

Success Scenarios

Card NetworkCard NumberExpected ResultNotes
Mastercard5232050000010003PBLPaymentResult.CompletedSuccessful authorization
VISA4149011500000147PBLPaymentResult.CompletedSuccessful authorization

Decline Scenarios

Card NetworkCard NumberExpected ResultError CodeError Meaning
VISA4024007119078466PBLPaymentResult.Failed.Error51Insufficient funds
VISA4532904789286871PBLPaymentResult.Failed.Error41Lost card / Do Not Honor