Configure the payment environment used by the SDK.
Type
public static void useEnv(PayKKaEnvironment env)Details This method is used to set the payment environment before initiating a payment. It supports a sandbox environment and multiple production environments. If this method is not called,
PayKKaEnv.SANDBOXis used by default.Example
import com.paykka.android.checkout.PayKKa; import com.paykka.android.checkout.PayKKaEnv; // Use production environment (Hong Kong) PayKKa.useEnv(PayKKaEnv.PROD_HK);
Initiate the payment process.
Type
public static void goPay( Activity context, String sessionId, PaymentResultCallback onPaymentResultCallback ) public static void goPay( Activity context, String sessionId, PaymentResultCallback onPaymentResultCallback, JSEventCallback onCloseTappedCallback )Details
context: The Activity currently initiating the payment.sessionId: The payment session ID, retrieved from the server.onPaymentResultCallback: Payment result callback.onCloseTappedCallback(optional): Callback when the user taps the close button on the payment page.
This method checks if the device supports
PaymentRequest. If supported, it opensPayKKaWKWebViewActivitywithin the app for payment; otherwise, it redirects to an external browser (Chrome preferred) to complete the payment.Note: When using this method, you must call
PayKKa.onPaymentResultin theonActivityResultof the initiating Activity to ensure the callback is triggered.Example
PayKKa.goPay(this, "your_session_id", result -> { switch (result.getStatus()) { case SUCCESS: // Payment successful break; case ERROR: // Payment failed break; } }); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); PayKKa.onPaymentResult(requestCode, resultCode, data); }
Register a payment result listener in modern Android development (ComponentActivity).
Type
public static PayKKaActivityResultLauncher registerForActivityResult( ComponentActivity context, PaymentResultCallback onPaymentResultCallback )Details This is the recommended integration method, utilizing Android's
ActivityResultLauncherAPI. It registers the callback when the Activity is created and returns aPayKKaActivityResultLauncherinstance.Example
public class MyActivity extends AppCompatActivity { private PayKKaActivityResultLauncher launcher; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Must be registered during onCreate or the initialization phase launcher = PayKKa.registerForActivityResult(this, result -> { // Handle payment result }); } private void startPayment() { launcher.goPay("your_session_id"); } }
Payment result object.
Properties
getStatus(): Returns thePaymentResult.Statusenum.getResult(): Returns aJSONObjectcontaining detailed payment result data.getMessage(): Returns result description information.
PaymentResult.Status Enum
SUCCESS: Payment successful.EXPIRED: Payment expired.ERROR: Payment error.UNKNOWN: Unknown status.
JavaScript events from the payment page.
Properties
getType(): ReturnsJSEvent.JSEventType.getData(): Returns theJSONObjectdata carried by the event.
JSEvent.JSEventType Enum
CLOSE_TAPPED: User tapped the close/back button on the payment page.UNKNOWN: Unknown event.
Predefined payment environments.
- Enum Values
SANDBOX: Sandbox test environment.PROD_EU: European production environment.PROD_HK: Hong Kong production environment.