# SDK API Reference

## Global Configuration and Initialization

### PayKKaEnvironment

SDK environment interface used to define configuration such as API domain, checkout URL, Google Pay gateway parameters, and 3DS environment.

- **Type**

```java
public interface PayKKaEnvironment
```
- **Details**
  - You can implement this interface to extend custom environments.
  - The SDK provides a built-in implementation via the `PayKKaEnv` enum, commonly including:
    - `SANDBOX`
    - `PROD_EU`
    - `PROD_HK`


### PayKKaEnv

Built-in enum implementation of `PayKKaEnvironment`.

- **Type**

```java
public enum PayKKaEnv implements PayKKaEnvironment
```
- **Enum Values**
  - `SANDBOX`: Sandbox test environment.
  - `PROD_EU`: Europe production environment.
  - `PROD_HK`: Hong Kong production environment.


### PayKKaConfiguration

Merchant configuration interface. You can implement this interface to define your own merchant parameters.

- **Type**

```java
public interface PayKKaConfiguration
```
- **Configuration Options**
  - `GatewayMerchantId` (`getGatewayMerchantId()`): Gateway merchant ID.
  - `ClientKey` (`getClientKey()`): Client key.
  - `Locale` (`getLocale()`): Language/region, optional by default.
  - `WeChatPayAppId` (`getWeChatPayAppId()`): AppID from the WeChat Open Platform, optional by default.
  - `AlipayPlusAcquirerId` (`getAlipayPlusAcquirerId()`): `Participant ID` from the Alipay+ Developer Center, optional by default.


### PayKKa.useEnv()

Globally switch the current environment used by the SDK.

- **Type**

```java
public static void useEnv(PayKKaEnvironment env)
```
- **Details**
Effective when called before payment; affects subsequent API requests and checkout behavior.


### PayKKa.useConf()

Globally switch the current merchant configuration used by the SDK.

- **Type**

```java
public static void useConf(PayKKaConfiguration conf)
```
- **Details**
Once set, it becomes the default merchant configuration for subsequent payment flows.


### PayKKa.init()

Initialize the SDK and apply environment, merchant configuration, and language settings.

- **Type**

```java
public static void init(
  @NonNull ComponentActivity contextActivity,
  PayKKaConfiguration configuration,
  PayKKaEnvironment environment
)

public static void init(
  @NonNull ComponentActivity contextActivity,
  PayKKaConfiguration configuration
)
```
- **Details**
  - Recommended to call during initialization of the payment host page.
  - If `environment` is null, `PayKKaEnv.SANDBOX` is used by default.
  - Global i18n language is applied based on `configuration.getLocale()`.


### PayKKa.goPay()

Note
This method is deprecated and will not be supported in future versions. Use the Drop-In (`PaymentBottomSheet`) approach to launch checkout with priority.

Shows checkout in WebView mode.
- **Type**

```java
@Deprecated
public static void goPay(
  Activity context,
  String sessionId,
  PaymentResultCallback onPaymentResultCallback
)

@Deprecated
public static void goPay(
  Activity context,
  String sessionId,
  PaymentResultCallback onPaymentResultCallback,
  JSEventCallback onCloseTappedCallback
)
```
- **Details**
  - `context`: `Activity` that initiates the payment.
  - `sessionId`: Payment session ID created by your server.
  - `onPaymentResultCallback`: Payment result callback.
  - `onCloseTappedCallback` (optional): Callback when the user taps close.


## Networking and Data Mapping

### PayKKaHttpClient

Global singleton HTTP client wrapped on top of OkHttp.

- **Type**

```java
public final class PayKKaHttpClient
```
- **Details**
  - Responsible for request construction and sending.
  - Automatically sets/merges default headers (such as SDK version, app info, locale).
  - Provides unified response parsing and error handling.


### CheckoutApi

Core checkout business API.

- **Type**

```java
public class CheckoutApi extends ApiBase
```
- **Required Configuration Properties**
  - `checkoutSessionId`
  - `clientKey`
- **Methods**
  - `requestComponentCheckoutSessionInfo()`: Fetch checkout session info.
  - `requestComponentCheckoutSessionPaymentsQuery()`: Query session payment status.
  - `createCheckoutSessionPayments(...)`: Submit a payment request.
  - `request3DSParamsQuery(...)`: Query 3DS parameters.
  - `request3DSCallback(...)`: Trigger 3DS callback confirmation.


### PublicApi

Public capability API, global singleton.

- **Type**

```java
public class PublicApi extends ApiBase
```
- **Methods**
  - `requestPubDataDictGet(...)`: Retrieve data dictionary.
  - `requestAddressProvinceDict(...)`: Retrieve province/state data.
  - `requestAddressCityDict(...)`: Retrieve city data.
  - `requestAddressStyle(...)`: Retrieve address form style configuration.
  - `requestPubChannelSdkConfig(...)`: Retrieve channel SDK configuration.


### DTO (Data Transfer Objects)

The SDK uses Java objects for request/response payloads and business fields, mainly under:

- `com.paykka.android.checkout.model`
- `com.paykka.android.checkout.model.dto`
- `com.paykka.android.checkout.model.dto.enums`


Common objects include payment payloads, session info, billing address, payment methods, and enum types.

## User Interface

### GooglePayment

Used to initiate Google Pay payment flow.

- **Type**

```java
public final class GooglePayment extends PaymentBase
```
- **Methods**
  - `requestPayment(String checkoutSessionId, PaymentResultCallback paymentResultCallback)`: Initiates Google Pay and handles the result.


### GooglePaymentForm

Google Pay button component (`LinearLayout`).

- **Type**

```java
public class GooglePaymentForm extends LinearLayout
```
- **Methods**
  - `showLoadingOverlay()`: Show loading overlay.
  - `hideLoadingOverlay()`: Hide loading overlay.


### WeChatPayment

Used to initiate the WeChat Pay payment flow.

- **Type**

```java
public class WeChatPayment extends PaymentBase
```
- **Methods**
  - `init(WeChatPaymentForm weChatPaymentForm, String checkoutSessionId, WeChatPaymentFormInitCallback initCallback)`: Binds the WeChat Pay form and payment session, and initializes WeChat Pay capability.
  - `requestPayment(PaymentResultCallback paymentResultCallback)`: Creates a WeChat Pay order, launches payment in the WeChat app, and handles payment results, user cancellation, and error callbacks.
- **Details**
  - `init(...)` must be completed before calling `requestPayment(...)`.
  - It depends on `getWeChatPayAppId()` in merchant configuration to complete the related WeChat Open Platform initialization.


### WeChatPaymentForm

WeChat Pay form component (`LinearLayout`).

- **Type**

```java
public class WeChatPaymentForm extends LinearLayout
```
- **Details**
  - This component is used to display the WeChat Pay form area and error messages.
  - It currently has no additional input fields and is mainly used to carry payment instructions and display error states.


### AlipayPlusPayment

Used to initiate the Alipay+ payment flow.

- **Type**

```java
public class AlipayPlusPayment extends PaymentBase
```
- **Methods**
  - `init(AlipayPlusPaymentForm alipayPlusPaymentForm, String checkoutSessionId, AlipayPaymentFormInitCallback initCallback)`: Binds the Alipay+ payment form and payment session, and initializes Alipay+ SDK configuration.
  - `requestPayment(PaymentResultCallback paymentResultCallback)`: Creates an Alipay+ payment order, displays the payment sheet, and handles payment results, cancellations, and error callbacks.
- **Details**
  - `init(...)` must be completed before calling `requestPayment(...)`.
  - It depends on `getAlipayPlusAcquirerId()` in merchant configuration to initialize the Alipay+ channel configuration.
  - After returning to the app from an external wallet or page, the SDK automatically polls payment status at the appropriate lifecycle stage and continues the result callback flow.


### AlipayPlusPaymentForm

Alipay+ payment form component (`LinearLayout`).

- **Type**

```java
public class AlipayPlusPaymentForm extends LinearLayout
```
- **Details**
  - This component is used to display the Alipay+ payment form area and error messages.
  - It currently has no additional input fields and is mainly used to carry payment instructions and display error states.


### BankCardPayment

Used to initiate bank card payment flow.

- **Type**

```java
public class BankCardPayment extends PaymentBase
```
- **Methods**
  - `init(CardPaymentForm cardPaymentForm, String checkoutSessionId, CardPaymentFormInitCallback initCallback)`: Initializes card payment instance and session context.
  - `requestPayment(PaymentResultCallback paymentResultCallback)`: Validates and submits card payment.


### CardPaymentForm

Bank card payment form component (`LinearLayout`).

- **Type**

```java
public final class CardPaymentForm extends LinearLayout
```
- **Methods**
  - `init(Context context)`: Initialize form view and input components.
  - `setInputValidationListener(InputValidationListener listener)`: Listen to input validation status.
  - `setEnabled(boolean enabled)`: Enable or disable form input.
  - `hideKeyboard()`: Dismiss keyboard.
  - `clearAllInputFocus()`: Clear all input focus.


### PaymentBottomSheet

Drop-In checkout bottom sheet (`BottomSheetLayout`).

- **Type**

```java
public final class PaymentBottomSheet extends BottomSheetLayout
```
- **Methods**
  - `showMerchantName()`: Display merchant name section.
  - `init(String checkoutSessionId, OnSheetCloseCallback onSheetCloseCallback)`: Initialize session and close callback.
  - `show(OnSheetLoadedCallback onLoadedCallback)` / `show()`: Show checkout.
  - `hide()`: Close checkout.


## Other Data Types

### PaymentResult

Payment result object.

- **Properties**
  - `getStatus()`: Returns `PaymentResult.Status` enum.
  - `getResult()`: Returns a `JSONObject` containing detailed payment result data.
  - `getMessage()`: Returns descriptive result message.
- **PaymentResult.Status Enum**
  - `SUCCESS`: Payment successful.
  - `EXPIRED`: Payment expired.
  - `ERROR`: Payment error.
  - `UNKNOWN`: Unknown status.


### JSEvent

Note
Deprecated and will not be supported in future versions.

JavaScript event from the payment page.
- **Properties**
  - `getType()`: Returns `JSEvent.JSEventType`.
  - `getData()`: Returns event payload data in `JSONObject`.
- **JSEvent.JSEventType Enum**
  - `CLOSE_TAPPED`: User taps close or back on the payment page.
  - `UNKNOWN`: Unknown event.