# SDK API Reference

## PayKKa

The SDK's main entry-point class, used to configure the environment, initialize the SDK flow, and more.

### useEnv() / useConf()

Switches the environment and merchant configurations currently used by the SDK.

- **Type**

```objectivec
+ (void)useEnv:(PayKKaEnv *)env;
+ (void)useConf:(PayKKaConf *)conf;
```

```swift
PayKKa.useEnv(_ env: PayKKaEnv)
PayKKa.useConf(_ conf: PayKKaConf)
```
- **Details**
  - `useEnv`: Switches the runtime environment currently used by the SDK.
  - `useConf`: Switches the merchant configuration currently used by the SDK.
  - These two methods only update the current global configuration; they do not automatically run the complete initialization flow.
  - The SDK's default environment is `PayKKaEnv.SANDBOX`.
  - In general, initialize the SDK once during app startup rather than switching configurations each time a payment is initiated.
- **Example**

```objectivec
#import <PayKKaCheckoutPayments/PayKKa.h>

[PayKKa useEnv:PayKKaEnv.SANDBOX];
[PayKKa useConf:appConf];
```

```swift
PayKKa.useEnv(.SANDBOX)
PayKKa.useConf(appConf)
```
- **See also**
  - [PayKKaEnv](#paykkaenv)
  - [PayKKaConf](#paykkaconf)


### init() / Init()

Initializes the SDK and applies the environment and merchant configurations.

- **Type**

```objectivec
+ (void)init:(PayKKaConf *)configuration environment:(nullable PayKKaEnv *)environment;
+ (void)init:(PayKKaConf *)configuration;
```

```swift
PayKKa.Init(_ configuration: PayKKaConf, _ environment: PayKKaEnv?)
PayKKa.Init(_ configuration: PayKKaConf)
```
- **Details**
  - `configuration`: The merchant configuration object. It must contain at least the gateway merchant ID and client key.
  - `environment`: An optional runtime environment. If it is nil, `PayKKaEnv.SANDBOX` is used by default.
  - Internally, `init` calls `useEnv(...)` and `useConf(...)` and completes SDK initialization.
  - Initialization must be completed before creating `PKPaymentBottomSheet` or any `PKPaymentBase` subclass, or before calling `goPay(...)`; otherwise, the SDK throws `NSInternalInconsistencyException`.
  - The Swift API is exposed as `PayKKa.Init(...)`, with an uppercase `I`.
- **Example**

```objectivec
[PayKKa init:appConf environment:PayKKaEnv.SANDBOX];
// Or use the default SANDBOX environment
[PayKKa init:appConf];
```

```swift
PayKKa.Init(appConf, .SANDBOX)
// Or use the default SANDBOX environment
PayKKa.Init(appConf)
```


### goPay()

Note
This method is the legacy WebView checkout integration. For new integrations, prefer Drop-In (`PKPaymentBottomSheet`) or the Component for the relevant payment method. This method is not currently marked as `deprecated` in the public header files.

Displays the checkout in a WebView.
- **Type**

```objectivec
+ (void)goPay:(NSString *)sessionId
onPaymentCallback:(void (^)(PKPaymentResult *paymentResult))onPaymentCallback;

+ (void)goPay:(NSString *)sessionId
onPaymentCallback:(void (^)(PKPaymentResult *paymentResult))onPaymentCallback
onCloseTappedCallback:(void (^)(PKJSEvent *jsEvent))onCloseTappedCallback;
```

```swift
PayKKa.goPay(
    _ sessionId: String,
    onPaymentCallback: @escaping (PKPaymentResult) -> Void
)

PayKKa.goPay(
    _ sessionId: String,
    onPaymentCallback: @escaping (PKPaymentResult) -> Void,
    onCloseTappedCallback: @escaping (PKJSEvent) -> Void
)
```
- **Details**
  - `sessionId`: The Checkout Session ID created by the server.
  - `onPaymentCallback`: The callback invoked after payment completes. It returns a `PKPaymentResult` object.
  - `onCloseTappedCallback`: Invoked when the user taps the checkout close button. It returns a `PKJSEvent` object.
  - The SDK creates a full-screen WebView checkout and automatically finds the current topmost view controller (`UIViewController`) suitable for modal presentation.
- **Example**

```objectivec
[PayKKa goPay:@"your_session_id"
    onPaymentCallback:^(PKPaymentResult *result) {
        if (result.status == PKPaymentStatusSuccess) {
            NSLog(@"Payment successful");
        } else {
            NSLog(@"Payment result: %@", result.message);
        }
    }];
```

```swift
PayKKa.goPay("your_session_id") { result in
    if result.status == .success {
        print("Payment successful")
    } else {
        print("Payment result: \(result.message ?? "")")
    }
} onCloseTappedCallback: { _ in
    print("Checkout closed")
}
```


# Environment Configuration API

## PayKKaEnv

The built-in implementation of `PayKKaEnvironment`, used to define the backend environment to which the SDK connects.

- **Type**

```objectivec
@interface PayKKaEnv : PayKKaEnvironment
```
- **Preset environments**
  - `PayKKaEnv.SANDBOX`: Sandbox testing environment.
  - `PayKKaEnv.PROD_EU`: European production environment.
  - `PayKKaEnv.PROD_HK`: Hong Kong production environment.
- **Details**
  - Preset environments are provided through class properties, not an Objective-C enumeration.
  - Use `environmentCode` to obtain the current environment code.


## PayKKaConf

Defines the merchant and payment method configurations used by the SDK.

- **Type**

```objectivec
@interface PayKKaConf : NSObject
```
- **Properties**
  - `configuration` (`NSDictionary *`): The raw dictionary of the current configuration object.
- **Configuration options**
  - `KEY_GATEWAY_MERCHANT_ID`: Gateway merchant ID.
  - `KEY_CLIENT_KEY`: Checkout Client Key.
  - `KEY_LOCALE`: The language and region used by the SDK.
  - `KEY_APPLE_PAY_MERCHANT_ID`: Apple Pay Merchant ID.
  - `KEY_ALIPAY_PLUS_ACQUIRER_ID`: Alipay+ Acquirer ID.
  - `KEY_WECHAT_PAY_APP_ID`: WeChat Open Platform App ID.
  - `KEY_WECHAT_PAY_APP_UNIVERSAL_LINK`: Your app's Universal Link, used to return users to the app after payment is completed.


### initWithDict()

Initializes a merchant configuration object with a dictionary.

- **Type**

```objectivec
- (instancetype)initWithDict:(NSDictionary *)dict;
```

```swift
PayKKaConf(dict: [AnyHashable: Any])
```
- **Details**
  - At least `KEY_GATEWAY_MERCHANT_ID` and `KEY_CLIENT_KEY` must be provided.
  - When integrating Apple Pay, Alipay+, or WeChat Pay, also provide the corresponding payment method configuration options.
- **Example**

```objectivec
PayKKaConf *appConf = [[PayKKaConf alloc] initWithDict:@{
    KEY_GATEWAY_MERCHANT_ID: @"your_gateway_merchant_id",
    KEY_CLIENT_KEY: @"your_client_key",
    KEY_APPLE_PAY_MERCHANT_ID: @"merchant.com.example",
    KEY_ALIPAY_PLUS_ACQUIRER_ID: @"your_acquirer_id",
    KEY_WECHAT_PAY_APP_ID: @"your_wechat_app_id",
    KEY_WECHAT_PAY_APP_UNIVERSAL_LINK: @"https://example.com/wechat/"
}];
```

```swift
let appConf = PayKKaConf(dict: [
    KEY_GATEWAY_MERCHANT_ID: "your_gateway_merchant_id",
    KEY_CLIENT_KEY: "your_client_key",
    KEY_APPLE_PAY_MERCHANT_ID: "merchant.com.example",
    KEY_ALIPAY_PLUS_ACQUIRER_ID: "your_acquirer_id",
    KEY_WECHAT_PAY_APP_ID: "your_wechat_app_id",
    KEY_WECHAT_PAY_APP_UNIVERSAL_LINK: "https://example.com/wechat/"
])
```


# Payment Core API

## PKPaymentBase

The base class for each payment method. It stores the Checkout Session, payment result callback, and payment request interceptor.

- **Type**

```objectivec
@interface PKPaymentBase : NSObject
```
- **Properties**
  - `paymentResultCallback` (`id<PKPaymentResultCallback>`, nullable): The payment result callback.
  - `interceptor` (`id<PKPaymentInterceptor>`, nullable): The interceptor invoked before the payment request is presented.
- **Methods**
  - `initWithCheckoutSessionId:`: Creates a payment object using a Checkout Session ID.
  - `setError:`: Updates or clears the error displayed by the associated payment form.
  - `notifyResult:`: Sends a terminal payment status to the result callback.
  - `notifyError:`: Sends a payment error to the result callback.
  - `notifyUserCanceled:extraData:`: Sends a user cancellation event to the result callback.
- **Details**
  - The default initializer is unavailable. Use the designated initializer provided by the specific payment class.
  - `PayKKa` must be initialized before creating a payment object.
  - `paymentResultCallback` must be set before initiating payment.
  - Both `paymentResultCallback` and `interceptor` are strong references. Set them to `nil` when the page is destroyed or the payment object is no longer used to avoid retain cycles.


## PKPaymentResultCallback

The unified callback protocol for receiving payment results, errors, and user cancellation events.

- **Type**

```objectivec
@protocol PKPaymentResultCallback <NSObject>
```
- **Methods**

```objectivec
- (void)onResult:(PKPaymentResult *)paymentResult;
- (void)onError:(id)throwable;
- (void)onUserCanceled:(nullable PKPaymentBase *)paymentSource
             extraData:(nullable NSDictionary *)extraData;
```

```swift
func onResult(_ paymentResult: PKPaymentResult)
func onError(_ throwable: Any)
func onUserCanceled(
    _ paymentSource: PKPaymentBase?,
    extraData: [AnyHashable: Any]?
)
```
- **Details**
  - `onResult:`: Required method that receives the normalized terminal payment result.
  - `onError:`: Optional method that receives a payment error. Its parameter type is `id` and may be an `NSError` or another error object.
  - `onUserCanceled:extraData:`: Optional method called when the user cancels the payment.
  - After an error or cancellation, the merchant app should generally stop displaying its loading state and allow the user to try paying again.


## PKPaymentInterceptor

An optional interceptor protocol invoked before the payment request is presented.

- **Type**

```objectivec
@protocol PKPaymentInterceptor <NSObject>
```
- **Methods**

```objectivec
- (void)beforeRequestPayment:(id)paymentSource;
```

```swift
func beforeRequestPayment(_ paymentSource: Any)
```
- **Details**
  - It is currently used primarily by Apple Pay before the system payment sheet is presented.
  - In this method, you can read `PKApplePayment.paymentRequest` and adjust request content such as the payment summary.


# Drop-In API

## PKPaymentBottomSheet

A bottom sheet that displays the native Drop-In checkout containing multiple payment methods.

- **Type**

```objectivec
@interface PKPaymentBottomSheet : NSObject
```
- **Properties**
  - `onPayCallback` (`id<PKPaymentResultCallback>`): The payment result callback, which must be set before presentation.
  - `isUiInitCompleted` (`BOOL`): Indicates whether checkout UI initialization is complete.
  - `isProcessing` (`BOOL`): Indicates whether the checkout is currently processing a payment.


### initWithCheckoutSessionId()

Creates a Drop-In checkout using a Checkout Session ID.

- **Type**

```objectivec
- (instancetype)initWithCheckoutSessionId:(nullable NSString *)checkoutSessionId;

- (instancetype)initWithCheckoutSessionId:(nullable NSString *)checkoutSessionId
                      onSheetCloseCallback:(void (^ _Nullable)(PKPaymentBottomSheet *sheet))onSheetCloseCallback;
```

```swift
PKPaymentBottomSheet(checkoutSessionId: String?)
PKPaymentBottomSheet(
    checkoutSessionId: String?,
    onSheetCloseCallback: ((PKPaymentBottomSheet) -> Void)?
)
```
- **Details**
  - `checkoutSessionId`: A valid Checkout Session ID created by the server.
  - `onSheetCloseCallback`: Called on the main thread after the sheet's closing animation completes.
  - The default initializer is unavailable.


### showMerchantName() / show()

Configures and presents the Drop-In checkout.

- **Type**

```objectivec
- (void)showMerchantName;
- (void)showFromPresenter:(nullable UIViewController *)presenter
               completion:(void (^ _Nullable)(void))completion;
```

```swift
sheet.showMerchantName()
sheet.show(fromPresenter: UIViewController?, completion: (() -> Void)?)
```
- **Details**
  - `showMerchantName`: Displays the merchant name section, which is hidden by default.
  - `presenter`: The view controller used for modal presentation. When `nil` is passed, the SDK automatically finds the current view controller suitable for presentation.
  - `completion`: The callback invoked after the presentation animation completes.


### hide()

Closes the Drop-In checkout.

- **Type**

```objectivec
- (void)hideWithCompletion:(void (^ _Nullable)(void))completion;
- (void)hide;
```
- **Details**
  - When leaving the page or no longer using the sheet, call `hide` and release the instance.
  - Use `setShouldDismissOnBackgroundTap:` and `setShouldDismissOnDraggingDownSheet:` to control user dismissal behavior.
- **Example**

```objectivec
PKPaymentBottomSheet *sheet =
    [[PKPaymentBottomSheet alloc]
        initWithCheckoutSessionId:@"your_session_id"
        onSheetCloseCallback:^(PKPaymentBottomSheet *sheet) {
            NSLog(@"Checkout closed");
        }];
sheet.onPayCallback = self;
[sheet showMerchantName];
[sheet showFromPresenter:self completion:nil];
```

```swift
let sheet = PKPaymentBottomSheet(checkoutSessionId: "your_session_id") { _ in
    print("Checkout closed")
}
sheet.onPayCallback = callback
sheet.showMerchantName()
sheet.show(fromPresenter: nil, completion: nil)
```


# Apple Pay API

## PKApplePayment

Builds an Apple Pay request, presents the system payment sheet, and submits payment credentials.

- **Type**

```objectivec
@interface PKApplePayment : PKPaymentBase
```
- **Properties**
  - `form` (`PKApplePaymentForm *`, nullable): The associated Apple Pay form.
  - `paymentRequest` (`PKPaymentRequest *`, nullable): The Apple Pay request generated for the current payment flow.
  - `paymentResultCallback`: The payment result callback inherited from `PKPaymentBase`.
  - `interceptor`: The payment request interceptor inherited from `PKPaymentBase`.


### requestPayment()

Initiates an Apple Pay payment.

- **Type**

```objectivec
- (void)requestPaymentWithCheckoutSessionId:(nullable NSString *)checkoutSessionId;
- (void)requestPayment;
+ (BOOL)canMakePayments;
```

```swift
payment.request()
PKApplePayment.canMakePayments()
```
- **Details**
  - `requestPaymentWithCheckoutSessionId:`: Initiates payment using the provided Checkout Session ID.
  - `requestPayment`: Initiates payment using the Checkout Session ID stored during initialization.
  - `canMakePayments`: Checks whether the device has basic Apple Pay capability. It does not validate the merchant, card network, or currency configuration for the current Checkout.
  - `paymentResultCallback` must be set before this method is called.
  - Use `setError:nil` to clear an old error from the associated form.
- **Example**

```objectivec
PKApplePayment *payment =
    [[PKApplePayment alloc] initWithCheckoutSessionId:@"your_session_id"];
payment.form = form;
payment.paymentResultCallback = self;
payment.interceptor = self;
[payment setError:nil];
[payment requestPayment];
```

```swift
let payment = PKApplePayment(checkoutSessionId: "your_session_id")
payment.form = form
payment.paymentResultCallback = callback
payment.interceptor = interceptor
payment.setError(nil)
payment.request()
```


## PKApplePaymentForm

An Apple Pay form component containing the Apple Pay button, loading state, and error message area.

- **Type**

```objectivec
@interface PKApplePaymentForm : UIControl
```
- **Properties**
  - `pkApplePaymentButton` (`PKApplePaymentButton *`): The Apple Pay payment button.
- **Methods**
  - `setError:`: Updates or clears the payment error.
  - `setLoading:animated:`: Updates the form's loading state.


## PKApplePaymentButton

The Apple Pay payment button component.

- **Type**

```objectivec
@interface PKApplePaymentButton : UIControl
```
- **Properties**
  - `applePaymentButton` (`PKPaymentButton *`): The internal PassKit button.
  - `onTap`: The button tap callback.
  - `loading` (`BOOL`): Indicates whether the button is currently loading.
- **Methods**
  - `setEnabled:animated:`: Updates whether the button is enabled.
  - `setLoading:`: Updates the loading state.
  - `setLoading:animated:`: Updates the loading state with an animation.
- **Details**
  - Bind business tap events to the outer `PKApplePaymentButton`, not directly to the internal `PKPaymentButton`.
  - If both `onTap` and Target/Action are set, the SDK runs `onTap` first and then sends `UIControlEventTouchUpInside`.


# Card Payment API

## PKBankCardPayment

Initializes the card form configuration, validates the form, and submits a card payment.

- **Type**

```objectivec
@interface PKBankCardPayment : PKPaymentBase
```
- **Properties**
  - `form` (`PKCardPaymentForm *`): The card form bound to the current payment object.


### initWithPKCardPaymentForm()

Creates a payment object using a card form and Checkout Session ID.

- **Type**

```objectivec
- (instancetype)initWithPKCardPaymentForm:(nullable PKCardPaymentForm *)form
                        checkoutSessionId:(nullable NSString *)checkoutSessionId;

- (instancetype)initWithPKCardPaymentForm:(nullable PKCardPaymentForm *)form
                        checkoutSessionId:(nullable NSString *)checkoutSessionId
                                 complete:(void (^ _Nullable)(NSError * _Nullable error,
                                                              NSDictionary * _Nullable sessionInfo))complete;
```

```swift
PKBankCardPayment(
    pkCardPaymentForm: PKCardPaymentForm?,
    checkoutSessionId: String?,
    complete: ((Error?, [AnyHashable: Any]?) -> Void)?
)
```
- **Details**
  - `form`: The form used to collect card and billing address information. It must be available when payment is initiated.
  - `checkoutSessionId`: The Checkout Session ID created by the server.
  - `complete`: The callback invoked after the asynchronous field configuration request completes. It returns Session information on success or an error on failure.
  - `complete` is called only when the form field configuration must be loaded asynchronously. It is not called if the form is nil or field configuration has already completed.
  - The base class's `initWithCheckoutSessionId:` is unavailable for `PKBankCardPayment`.


### requestPayment()

Validates the form and initiates a card payment.

- **Type**

```objectivec
- (void)requestPaymentWithCheckoutSessionId:(nullable NSString *)checkoutSessionId;
```
- **Details**
  - Before initiating payment, set `paymentResultCallback` and ensure that form initialization is complete and the input is valid.
  - Disable the form and payment button until form initialization is complete.
  - Use `setError:nil` to clear an old payment error from the form.
- **Example**

```objectivec
PKCardPaymentForm *form = [[PKCardPaymentForm alloc] init];
PKBankCardPayment *payment =
    [[PKBankCardPayment alloc]
        initWithPKCardPaymentForm:form
        checkoutSessionId:@"your_session_id"
        complete:^(NSError *error, NSDictionary *sessionInfo) {
            if (error) {
                [form setError:error];
            }
        }];
payment.paymentResultCallback = self;
[payment requestPaymentWithCheckoutSessionId:@"your_session_id"];
```


## PKCardPaymentForm

A form component that collects and validates card, cardholder, and billing address information.

- **Type**

```objectivec
@interface PKCardPaymentForm : UIControl
```
- **Methods**

```objectivec
- (void)validateWithCallback:(void (^)(NSArray<NSNumber *> *resultArray))onValidateCallback
             onErrorCallback:(void (^)(NSError *error))onErrorCallback;

- (void)setEditingChangedCallback:(void (^)(void))onAllFieldsValidCallback
      onFieldInputInvalidCallback:(void (^)(NSError *error))onFieldInputInvalidCallback;

- (void)setError:(nullable id)throwable;
```
- **Details**
  - `validateWithCallback:onErrorCallback:`: Validates all payment fields and synchronously updates their error styles.
  - `setEditingChangedCallback:onFieldInputInvalidCallback:`: Observes real-time form validation state and can be used to control whether the payment button is enabled.
  - `setError:`: Updates or clears the payment error at the bottom of the form without changing the validation state of individual input fields.
  - Set the editing callback only once. Repeated calls may add additional listeners to the input fields.


# Alipay+ API

## PKAlipayPlusPayment

Creates an Alipay+ payment order, presents the payment sheet, and handles the payment result.

- **Type**

```objectivec
@interface PKAlipayPlusPayment : PKPaymentBase
```
- **Properties**
  - `form` (`PKAlipayPlusPaymentForm *`, nullable): The Alipay+ form used to display payment errors.


### requestPayment()

Initiates an Alipay+ payment.

- **Type**

```objectivec
- (void)requestPaymentWithCheckoutSessionId:(nullable NSString *)checkoutSessionId;
- (void)requestPayment;
```

```swift
payment.request()
```
- **Details**
  - `paymentResultCallback` must be set before this method is called.
  - `requestPayment` uses the Checkout Session ID stored during initialization.
  - It depends on `KEY_ALIPAY_PLUS_ACQUIRER_ID` in the merchant configuration.
  - After the user returns to the app from an external wallet or page, the SDK may continue polling for the order's final status and complete the result callback.
- **Example**

```swift
let form = PKAlipayPlusPaymentForm()
let payment = PKAlipayPlusPayment(checkoutSessionId: "your_session_id")
payment.form = form
payment.paymentResultCallback = callback
payment.setError(nil)
payment.request()
```


## PKAlipayPlusPaymentForm

A form component used to display Alipay+ payment errors.

- **Type**

```objectivec
@interface PKAlipayPlusPaymentForm : UIControl
```
- **Methods**
  - `setError:`: Updates or clears the payment error.
- **Details**
  - It currently has no additional input fields and is used primarily to present the error state.
  - The merchant app provides the payment button separately.


# WeChat Pay API

## PKWeChatPayment

Creates a WeChat Pay order, opens the WeChat app, and handles the payment result.

- **Type**

```objectivec
@interface PKWeChatPayment : PKPaymentBase
```
- **Properties**
  - `form` (`PKWeChatPaymentForm *`, nullable): The WeChat Pay form used to display payment errors.


### requestPayment()

Initiates a WeChat Pay payment.

- **Type**

```objectivec
- (void)requestPaymentWithCheckoutSessionId:(nullable NSString *)checkoutSessionId;
- (void)requestPayment;
```

```swift
payment.request()
```
- **Details**
  - `paymentResultCallback` must be set before this method is called.
  - `requestPayment` uses the Checkout Session ID stored during initialization.
  - It depends on `KEY_WECHAT_PAY_APP_ID` and `KEY_WECHAT_PAY_APP_UNIVERSAL_LINK` in the merchant configuration.
  - After the user returns to the app from WeChat, the SDK may continue polling for the order's final status and complete the result callback.
- **Example**

```objectivec
PKWeChatPaymentForm *form = [[PKWeChatPaymentForm alloc] init];
PKWeChatPayment *payment =
    [[PKWeChatPayment alloc] initWithCheckoutSessionId:@"your_session_id"];
payment.form = form;
payment.paymentResultCallback = self;
[payment setError:nil];
[payment requestPayment];
```


## PKWeChatPaymentForm

A form component used to display WeChat Pay payment errors.

- **Type**

```objectivec
@interface PKWeChatPaymentForm : UIControl
```
- **Methods**
  - `setError:`: Updates or clears the payment error.
- **Details**
  - It currently has no additional input fields and is used primarily to present the error state.
  - The merchant app provides the payment button separately.


## WeChatPayKKaHandler

Forwards URL Scheme and Universal Link callbacks received by the merchant app to WeChatOpenSDK and the current WeChat Pay object.

- **Type**

```objectivec
@interface WeChatPayKKaHandler : NSObject
```
- **Methods**

```objectivec
+ (instancetype)shared;
+ (BOOL)handleOpenURL:(NSURL *)url;
+ (BOOL)handleUniversalLink:(NSUserActivity *)userActivity;
```

```swift
WeChatPayKKaHandler.shared()
WeChatPayKKaHandler.handleOpen(_ url: URL) -> Bool
WeChatPayKKaHandler.handleUniversalLink(_ userActivity: NSUserActivity) -> Bool
```
- **Details**
  - `handleOpenURL:`: Handles a URL Scheme callback.
  - `handleUniversalLink:`: Handles a Universal Link callback.
  - Returns `YES` when WeChatOpenSDK accepts the callback; returns `NO` if a dependency is missing or a runtime invocation fails.
  - The merchant app should call the public forwarding methods above and must not pass `WeChatPayKKaHandler.shared` directly to `WXApi`.
- **Example**

```objectivec
- (void)scene:(UIScene *)scene
    openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts {
    NSURL *url = URLContexts.anyObject.URL;
    if (url) {
        [WeChatPayKKaHandler handleOpenURL:url];
    }
}

- (void)scene:(UIScene *)scene
    continueUserActivity:(NSUserActivity *)userActivity {
    [WeChatPayKKaHandler handleUniversalLink:userActivity];
}
```

```swift
.onOpenURL { url in
    _ = WeChatPayKKaHandler.handleOpen(url)
}
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { activity in
    _ = WeChatPayKKaHandler.handleUniversalLink(activity)
}
```


# Data Models

## PKPaymentResult

An object containing the normalized payment result and raw payment data.

- **Type**

```objectivec
@interface PKPaymentResult : NSObject
```
- **Properties**
  - `status` (`PKPaymentStatus`): The payment status.
  - `message` (`NSString *`, nullable): The result message or error information.
  - `result` (`NSDictionary *`, nullable): The raw payment result data.
  - `paymentResultObj` (`NSDictionary *`): The complete dictionary representation of the payment result.


### initWithStatus()

Creates a payment result object using a payment status, raw result, and message.

- **Type**

```objectivec
- (instancetype)initWithStatus:(PKPaymentStatus)status
                        result:(nullable NSDictionary *)result
                       message:(nullable NSString *)message;
```

```swift
PKPaymentResult(
    status: PKPaymentStatus,
    result: [AnyHashable: Any]?,
    message: String?
)
```


### PKPaymentStatus

Payment status enumeration:

- `PKPaymentStatusUnknown` / `.unknown`: Unknown status.
- `PKPaymentStatusSuccess` / `.success`: Payment successful.
- `PKPaymentStatusExpired` / `.expired`: The payment or Checkout Session has expired.
- `PKPaymentStatusError` / `.error`: An error occurred during payment.


### fromString() / toString()

Converts between a payment result object and a JSON string.

- **Type**

```objectivec
+ (instancetype)fromString:(NSString *)jsonString;
- (NSString *)toString;
```


## PKJSEvent

Note
This type is used for JavaScript events from the legacy WebView checkout. For new integrations, prefer Drop-In or Component mode.

A JavaScript event from the WebView checkout.
- **Properties**
  - `type` (`PKJSEventType`): The event type.
  - `data` (`NSDictionary *`, nullable): The data carried by the event.
  - `jsEventObj` (`NSDictionary *`): The complete dictionary representation of the event.
- **PKJSEventType enumeration**
  - `EventTypeUnknown`: Unknown event.
  - `EventTypeClose`: The user tapped the checkout close button.
- **Methods**
  - `fromString:`: Creates an event object from a JSON string.
  - `toString`: Serializes the event object to a JSON string.