Skip to main content

Overview

All PayMaya SDK clients (PayMayaCheckout, PayWithPayMaya, and PayMayaVault) use a builder pattern for configuration. The builder provides a fluent API to set required and optional parameters before creating the client instance.

Builder Interface

Each client provides a Builder interface accessible via newBuilder():
val client = PayMayaCheckout.newBuilder()
    .clientPublicKey("pk-test-xxx")
    .environment(PayMayaEnvironment.SANDBOX)
    .logLevel(LogLevel.DEBUG)
    .build()

Common Methods

These methods are available on all client builders:

clientPublicKey()

value
String
required
Your PayMaya public API key
Sets the client public key for authentication.
.clientPublicKey("pk-test-xxx")
Use sandbox keys (starting with pk-test-) for SANDBOX environment and production keys for PRODUCTION environment. Never commit production keys to version control.

environment()

value
PayMayaEnvironment
required
The target environment (SANDBOX or PRODUCTION)
Sets the environment type.
.environment(PayMayaEnvironment.SANDBOX)
See PayMayaEnvironment for details.

logLevel()

value
LogLevel
The logging verbosity level
Sets the log level for SDK operations. Optional.
.logLevel(LogLevel.DEBUG)
See LogLevel for available levels.

build()

Builds and returns the configured client instance.
val client = PayMayaCheckout.newBuilder()
    .clientPublicKey("pk-test-xxx")
    .environment(PayMayaEnvironment.SANDBOX)
    .build()
The build() method will throw an exception if required parameters (clientPublicKey and environment) are not set.

Vault-Specific Methods

PayMayaVault.Builder includes an additional method:
value
Int
Drawable resource ID for custom logo
Sets a custom logo for the Vault UI. Optional.
val vaultClient = PayMayaVault.newBuilder()
    .clientPublicKey("pk-test-xxx")
    .environment(PayMayaEnvironment.SANDBOX)
    .logo(R.drawable.custom_logo)
    .build()
You can also customize the logo and other UI elements using Android styles and themes.

Complete Examples

val checkoutClient = PayMayaCheckout.newBuilder()
    .clientPublicKey("pk-test-xxx")
    .environment(PayMayaEnvironment.SANDBOX)
    .logLevel(LogLevel.DEBUG)
    .build()

Builder Pattern Benefits

  • Fluent API: Chain configuration methods for readable code
  • Type Safety: Compile-time validation of parameter types
  • Immutability: Built clients are immutable once created
  • Required Parameters: Build fails if required config is missing
  • Optional Parameters: Sensible defaults for optional settings

Best Practices

  1. Store Client Instance: Create the client once and reuse it throughout your app
class PaymentManager {
    private val checkoutClient = PayMayaCheckout.newBuilder()
        .clientPublicKey(BuildConfig.PAYMAYA_PUBLIC_KEY)
        .environment(PayMayaEnvironment.SANDBOX)
        .build()
}
  1. Use BuildConfig: Store API keys in build.gradle and reference via BuildConfig
.clientPublicKey(BuildConfig.PAYMAYA_PUBLIC_KEY)
  1. Environment-Specific Keys: Use different keys for debug/release builds
val environment = if (BuildConfig.DEBUG) {
    PayMayaEnvironment.SANDBOX
} else {
    PayMayaEnvironment.PRODUCTION
}

val client = PayMayaCheckout.newBuilder()
    .clientPublicKey(BuildConfig.PAYMAYA_PUBLIC_KEY)
    .environment(environment)
    .build()

See Also

Build docs developers (and LLMs) love