Skip to main content

Interface

interface PayMayaCheckout
The checkout client for initiating and managing checkout payment flows.

Creating an Instance

newBuilder()

Returns a new PayMayaCheckout.Builder instance for constructing the client.
val checkoutClient = PayMayaCheckout.newBuilder()
    .clientPublicKey("your-public-key")
    .environment(PayMayaEnvironment.SANDBOX)
    .logLevel(LogLevel.INFO)
    .build()

Methods

startCheckoutActivityForResult()

Initiates the checkout flow.
fun startCheckoutActivityForResult(
    activity: Activity,
    request: CheckoutRequest
)
activity
Activity
required
The current activity from which to launch the checkout flow
request
CheckoutRequest
required
Checkout request containing all information about the payment
Usage:
val checkoutRequest = CheckoutRequest(
    totalAmount = TotalAmount(
        value = 100.00,
        currency = "PHP"
    ),
    buyer = Buyer(
        firstName = "Juan",
        lastName = "Dela Cruz",
        contact = Contact(
            email = "[email protected]",
            phone = "+639171234567"
        )
    ),
    items = listOf(
        Item(
            name = "Sample Item",
            quantity = 1,
            amount = ItemAmount(
                value = 100.00
            )
        )
    ),
    redirectUrl = RedirectUrl(
        success = "https://example.com/success",
        failure = "https://example.com/failure",
        cancel = "https://example.com/cancel"
    ),
    requestReferenceNumber = "ORDER-123456"
)

checkoutClient.startCheckoutActivityForResult(this, checkoutRequest)
Use onActivityResult() to get the payment result after the checkout flow completes.

onActivityResult()

Gets the payment result. Call this from your Activity’s onActivityResult() method.
fun onActivityResult(
    requestCode: Int,
    resultCode: Int,
    data: Intent?
): PayMayaCheckoutResult?
requestCode
Int
required
The request code from the activity result
resultCode
Int
required
The result code from the activity result
data
Intent?
required
The intent data from the activity result
Returns: PayMayaCheckoutResult? - Returns non-null result if the completed activity was started by startCheckoutActivityForResult() Usage:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    
    checkoutClient.onActivityResult(requestCode, resultCode, data)?.let { result ->
        when (result) {
            is PayMayaCheckoutResult.Success -> {
                // Payment successful
                val paymentId = result.id
                Log.d(TAG, "Payment successful: $paymentId")
            }
            is PayMayaCheckoutResult.Failure -> {
                // Payment failed
                val message = result.message
                Log.e(TAG, "Payment failed: $message")
            }
            is PayMayaCheckoutResult.Cancel -> {
                // Payment cancelled by user
                Log.d(TAG, "Payment cancelled")
            }
        }
    }
}

checkPaymentStatus()

Checks the status of a payment. This method is synchronous and must not be called from the main thread.
fun checkPaymentStatus(id: String): CheckPaymentStatusResult
id
String
required
The payment ID to check status for
Returns: CheckPaymentStatusResult - The current status of the payment Usage:
// Call from a background thread
viewModelScope.launch(Dispatchers.IO) {
    val status = checkoutClient.checkPaymentStatus(paymentId)
    when (status) {
        is CheckPaymentStatusResult.Success -> {
            // Handle success
        }
        is CheckPaymentStatusResult.Failure -> {
            // Handle failure
        }
    }
}
This method is synchronous. Do not call it from the main thread or your app will freeze.

Builder Methods

clientPublicKey()

Sets the client public key. Required.
fun clientPublicKey(value: String): Builder
value
String
required
Your PayMaya public API key

environment()

Sets the environment type (sandbox or production). Required.
fun environment(value: PayMayaEnvironment): Builder
value
PayMayaEnvironment
required
The environment to use: PayMayaEnvironment.SANDBOX or PayMayaEnvironment.PRODUCTION

logLevel()

Sets the log level. Optional.
fun logLevel(value: LogLevel): Builder
value
LogLevel
The logging level: LogLevel.NONE, LogLevel.ERROR, LogLevel.INFO, or LogLevel.DEBUG

build()

Builds and returns the PayMayaCheckout client instance.
fun build(): PayMayaCheckout
Returns: PayMayaCheckout - The configured checkout client instance

Complete Example

class CheckoutActivity : AppCompatActivity() {
    
    private lateinit var checkoutClient: PayMayaCheckout
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_checkout)
        
        // Initialize the checkout client
        checkoutClient = PayMayaCheckout.newBuilder()
            .clientPublicKey("pk-test-12345")
            .environment(PayMayaEnvironment.SANDBOX)
            .logLevel(LogLevel.INFO)
            .build()
        
        // Start checkout when button is clicked
        findViewById<Button>(R.id.payButton).setOnClickListener {
            startCheckout()
        }
    }
    
    private fun startCheckout() {
        val checkoutRequest = CheckoutRequest(
            totalAmount = TotalAmount(
                value = 100.00,
                currency = "PHP"
            ),
            buyer = Buyer(
                firstName = "Juan",
                lastName = "Dela Cruz",
                contact = Contact(
                    email = "[email protected]",
                    phone = "+639171234567"
                )
            ),
            items = listOf(
                Item(
                    name = "Sample Item",
                    quantity = 1,
                    amount = ItemAmount(
                        value = 100.00
                    )
                )
            ),
            redirectUrl = RedirectUrl(
                success = "https://example.com/success",
                failure = "https://example.com/failure",
                cancel = "https://example.com/cancel"
            ),
            requestReferenceNumber = "ORDER-123456"
        )
        
        checkoutClient.startCheckoutActivityForResult(this, checkoutRequest)
    }
    
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        
        checkoutClient.onActivityResult(requestCode, resultCode, data)?.let { result ->
            when (result) {
                is PayMayaCheckoutResult.Success -> {
                    Toast.makeText(this, "Payment successful!", Toast.LENGTH_LONG).show()
                    // Verify payment status on your server
                }
                is PayMayaCheckoutResult.Failure -> {
                    Toast.makeText(this, "Payment failed: ${result.message}", Toast.LENGTH_LONG).show()
                }
                is PayMayaCheckoutResult.Cancel -> {
                    Toast.makeText(this, "Payment cancelled", Toast.LENGTH_SHORT).show()
                }
            }
        }
    }
}

Build docs developers (and LLMs) love