Skip to main content

Interface

interface PayWithPayMaya
The PayWithPayMaya client for initiating single payments and creating wallet links that allow charging a PayMaya account.

Creating an Instance

newBuilder()

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

Methods

startSinglePaymentActivityForResult()

Initiates the single payment flow.
fun startSinglePaymentActivityForResult(
    activity: Activity,
    request: SinglePaymentRequest
)
activity
Activity
required
The current activity from which to launch the payment flow
request
SinglePaymentRequest
required
Single payment request containing all information about the payment
Usage:
val paymentRequest = SinglePaymentRequest(
    totalAmount = TotalAmount(
        value = 100.00,
        currency = "PHP"
    ),
    requestReferenceNumber = "REF-123456",
    metadata = mapOf(
        "orderDetails" to "Sample order"
    )
)

payWithPayMayaClient.startSinglePaymentActivityForResult(this, paymentRequest)
Use onActivityResult() to get the payment result after the payment flow completes.

startCreateWalletLinkActivityForResult()

Initiates the create wallet link flow that allows charging a PayMaya account.
fun startCreateWalletLinkActivityForResult(
    activity: Activity,
    request: CreateWalletLinkRequest
)
activity
Activity
required
The current activity from which to launch the wallet link flow
request
CreateWalletLinkRequest
required
Create wallet link request containing necessary information
Usage:
val walletLinkRequest = CreateWalletLinkRequest(
    requestReferenceNumber = "WL-123456",
    metadata = mapOf(
        "customerId" to "customer-001"
    )
)

payWithPayMayaClient.startCreateWalletLinkActivityForResult(this, walletLinkRequest)
Use onActivityResult() to get the wallet link result after the flow completes.

onActivityResult()

Gets the payment or wallet link result. Call this from your Activity’s onActivityResult() method.
fun onActivityResult(
    requestCode: Int,
    resultCode: Int,
    data: Intent?
): PayWithPayMayaResult?
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: PayWithPayMayaResult? - Returns non-null result if the completed activity was started by startSinglePaymentActivityForResult() or startCreateWalletLinkActivityForResult(). The result can be SinglePaymentResult or CreateWalletLinkResult. Usage:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    
    payWithPayMayaClient.onActivityResult(requestCode, resultCode, data)?.let { result ->
        when (result) {
            is SinglePaymentResult.Success -> {
                val paymentId = result.id
                Log.d(TAG, "Payment successful: $paymentId")
            }
            is SinglePaymentResult.Failure -> {
                val message = result.message
                Log.e(TAG, "Payment failed: $message")
            }
            is SinglePaymentResult.Cancel -> {
                Log.d(TAG, "Payment cancelled")
            }
            is CreateWalletLinkResult.Success -> {
                val linkId = result.linkId
                Log.d(TAG, "Wallet link created: $linkId")
            }
            is CreateWalletLinkResult.Failure -> {
                val message = result.message
                Log.e(TAG, "Wallet link failed: $message")
            }
            is CreateWalletLinkResult.Cancel -> {
                Log.d(TAG, "Wallet link 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 = payWithPayMayaClient.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 PayWithPayMaya client instance.
fun build(): PayWithPayMaya
Returns: PayWithPayMaya - The configured PayWithPayMaya client instance

Complete Example - Single Payment

class PaymentActivity : AppCompatActivity() {
    
    private lateinit var payWithPayMayaClient: PayWithPayMaya
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_payment)
        
        // Initialize the client
        payWithPayMayaClient = PayWithPayMaya.newBuilder()
            .clientPublicKey("pk-test-12345")
            .environment(PayMayaEnvironment.SANDBOX)
            .logLevel(LogLevel.INFO)
            .build()
        
        // Start payment when button is clicked
        findViewById<Button>(R.id.payButton).setOnClickListener {
            startSinglePayment()
        }
    }
    
    private fun startSinglePayment() {
        val paymentRequest = SinglePaymentRequest(
            totalAmount = TotalAmount(
                value = 100.00,
                currency = "PHP"
            ),
            requestReferenceNumber = "REF-123456",
            metadata = mapOf(
                "orderDetails" to "Sample order"
            )
        )
        
        payWithPayMayaClient.startSinglePaymentActivityForResult(this, paymentRequest)
    }
    
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        
        payWithPayMayaClient.onActivityResult(requestCode, resultCode, data)?.let { result ->
            when (result) {
                is SinglePaymentResult.Success -> {
                    Toast.makeText(this, "Payment successful!", Toast.LENGTH_LONG).show()
                }
                is SinglePaymentResult.Failure -> {
                    Toast.makeText(this, "Payment failed: ${result.message}", Toast.LENGTH_LONG).show()
                }
                is SinglePaymentResult.Cancel -> {
                    Toast.makeText(this, "Payment cancelled", Toast.LENGTH_SHORT).show()
                }
            }
        }
    }
}
class WalletLinkActivity : AppCompatActivity() {
    
    private lateinit var payWithPayMayaClient: PayWithPayMaya
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_wallet_link)
        
        // Initialize the client
        payWithPayMayaClient = PayWithPayMaya.newBuilder()
            .clientPublicKey("pk-test-12345")
            .environment(PayMayaEnvironment.SANDBOX)
            .logLevel(LogLevel.INFO)
            .build()
        
        // Start wallet link creation when button is clicked
        findViewById<Button>(R.id.linkWalletButton).setOnClickListener {
            createWalletLink()
        }
    }
    
    private fun createWalletLink() {
        val walletLinkRequest = CreateWalletLinkRequest(
            requestReferenceNumber = "WL-123456",
            metadata = mapOf(
                "customerId" to "customer-001"
            )
        )
        
        payWithPayMayaClient.startCreateWalletLinkActivityForResult(this, walletLinkRequest)
    }
    
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        
        payWithPayMayaClient.onActivityResult(requestCode, resultCode, data)?.let { result ->
            when (result) {
                is CreateWalletLinkResult.Success -> {
                    Toast.makeText(this, "Wallet linked successfully!", Toast.LENGTH_LONG).show()
                    // Store the link ID for future charges
                    val linkId = result.linkId
                }
                is CreateWalletLinkResult.Failure -> {
                    Toast.makeText(this, "Wallet link failed: ${result.message}", Toast.LENGTH_LONG).show()
                }
                is CreateWalletLinkResult.Cancel -> {
                    Toast.makeText(this, "Wallet link cancelled", Toast.LENGTH_SHORT).show()
                }
            }
        }
    }
}

Build docs developers (and LLMs) love