Prerequisites
Before you begin, make sure you have:- Completed the installation steps
- A PayMaya public API key (get sandbox keys)
- An Activity or Fragment where you want to initiate payments
For testing, use the Sandbox environment with test credit card numbers.
Complete Example
Follow these steps to implement a basic checkout flow:Initialize the Checkout Client
Create a PayMaya Checkout client instance. This should typically be done in your Activity’s Builder Parameters:
onCreate() or as a class property:MainActivity.kt
clientPublicKey(): Your PayMaya public API key (required)environment():PayMayaEnvironment.SANDBOXorPayMayaEnvironment.PRODUCTION(required)logLevel(): Logging level for debugging (optional, defaults to ERROR)
LogLevel.VERBOSE: Http request/response lines, headers, and bodiesLogLevel.DEBUG: Http request/response lines and headersLogLevel.INFO: Http request/response lines onlyLogLevel.WARN,LogLevel.ERROR,LogLevel.ASSERT
Create a Checkout Request
Build a CheckoutRequest Parameters:
CheckoutRequest with transaction details:MainActivity.kt
The
requestReferenceNumber should be a unique identifier for each transaction. This helps you track payments in your system.totalAmount: Transaction amount with currency (required)buyer: Customer information (optional)items: List of items being purchased (required)requestReferenceNumber: Your unique transaction reference (required)redirectUrl: URLs for different payment outcomes (required)metadata: Additional custom data as JSONObject (optional)
Handle Payment Results
Override Result Types:
onActivityResult() to receive the payment result:MainActivity.kt
If the user closes the checkout activity (e.g., by pressing the Back button), the SDK automatically checks the payment status and returns the appropriate result.
PayMayaCheckoutResult.Success: Payment completed successfully- Contains:
checkoutId
- Contains:
PayMayaCheckoutResult.Cancel: Payment canceled by user- Contains:
checkoutId(if available)
- Contains:
PayMayaCheckoutResult.Failure: Payment failed- Contains:
checkoutId(if available),exception
- Contains:
Check Payment Status (Optional)
You can manually verify payment status using the Payment statuses include:
checkoutId:MainActivity.kt
PAYMENT_SUCCESS: Payment completed successfullyAUTH_FAILED: Authentication failedPAYMENT_FAILED: Payment processing failed- Other statuses as defined in
PaymentStatusenum
Full Example Code
Here’s the complete Activity implementation:MainActivity.kt
Testing in Sandbox
Use these test credit cards in the Sandbox environment:| Card Type | Card Number | CVV | Expiry |
|---|---|---|---|
| Visa | 4123450131001381 | 123 | Any future date |
| Mastercard | 5455590000000009 | 123 | Any future date |
Find more test cards in the PayMaya Developer Documentation.
Common Issues
onActivityResult not called (Android 11+)
If you’re targeting Android 11 (API 30) or higher and using Activity Result APIs:Invalid API Key Error
Ensure you’re using:- Public key (starts with
pk-) - Correct environment (Sandbox keys won’t work in Production)
- Valid, active API key
Next Steps
Checkout API
Learn about advanced Checkout features
Pay With PayMaya
Integrate PayMaya wallet payments
Vault API
Tokenize cards for recurring payments
Error Handling
Handle errors and exceptions