Skip to content

SDK API Reference

PayKKa

The main entry class of the SDK, used to configure the environment and start the payment flow.

useEnv() / useConf()

Switch the SDK's current environment configuration and merchant configuration.

  • Type

    + (void)useEnv:(PayKKaEnv *)env;
    + (void)useConf:(PayKKaConf *)conf;
    PayKKa.useEnv(_ env: PayKKaEnv)
    PayKKa.useConf(_ conf: PayKKaConf)
  • Details

    • useEnv: Switches the SDK's current runtime environment.
    • useConf: Switches the SDK's current merchant configuration.
    • These two methods only update the current global configuration and do not perform the full initialization flow automatically.
    • The default SDK environment is PayKKaEnv.SANDBOX; if no merchant configuration is explicitly set, PayKKaConf.EMPTY is used by default.
    • It is generally recommended to set these values during app startup or before launching checkout.
  • Example

    #import <PayKKaCheckoutPayments/PayKKa.h>
    
    [PayKKa useEnv:PayKKaEnv.SANDBOX];
    [PayKKa useConf:appConf];
    PayKKa.useEnv(.SANDBOX)
    PayKKa.useConf(appConf)
  • Reference

init() / Init()

Initializes the SDK and applies the environment and merchant configuration.

  • Type

    + (void)init:(PayKKaConf *)configuration environment:(nullable PayKKaEnv *)environment;
    + (void)init:(PayKKaConf *)configuration;
    PayKKa.Init(_ configuration: PayKKaConf, _ environment: PayKKaEnv?)
    PayKKa.Init(_ configuration: PayKKaConf)
  • Details

    • configuration: The merchant configuration object, which should at least include the gateway merchant ID and client key.
    • environment: Optional runtime environment. If omitted, PayKKaEnv.SANDBOX is used by default.
    • Internally, init calls useEnv(...) and useConf(...) and completes SDK initializations.
    • Before calling goPay(...) or any SwiftUI checkout-related capability, you should complete initialization first; otherwise, an NSInternalInconsistencyException will be thrown.
    • The Swift exposed name is PayKKa.Init(...), with an uppercase I.
  • Example

    [PayKKa init:appConf environment:PayKKaEnv.SANDBOX];
    // or
    [PayKKa init:appConf];
    PayKKa.Init(appConf, .SANDBOX)
    // or
    PayKKa.Init(appConf)

goPay()

Starts the payment flow and displays the checkout page.

  • Type

    + (void)goPay:(NSString *)sessionId onPaymentCallback:(PayKKaCallback)onPaymentCallback;
    
    + (void)goPay:(NSString *)sessionId onPaymentCallback:(PayKKaCallback)onPaymentCallback
                                    onCloseTappedCallback:(void (^ _Nullable)(JSEvent *jsEvent))onCloseTappedCallback;
  • Details This method creates a full-screen checkout view controller and automatically finds the current topmost view controller suitable for modal presentation to display it. It supports handling payment result callbacks as well as an optional close-button tap callback.

    • sessionId: The payment session ID returned by your backend.
    • onPaymentCallback: Callback triggered after payment completes, returning a PaymentResult object.
    • onCloseTappedCallback: Optional. Triggered when the user taps the close button in the upper-left corner of the checkout page.
  • Example

    [PayKKa goPay:@"your_session_id" onPaymentCallback:^(PaymentResult *result) {
        if (result.status == PaymentStatusSuccess) {
            NSLog(@"Payment succeeded");
        } else {
            NSLog(@"Payment failed: %@", result.message);
        }
      }];

Environment Configuration API

PayKKaEnv

Used to define the backend environment the SDK connects to.

  • Built-in Environments
    • PayKKaEnv.SANDBOX: Sandbox testing environment.
    • PayKKaEnv.PROD_EU: Europe production environment.
    • PayKKaEnv.PROD_HK: Hong Kong production environment.

PayKKaConf

Used to define the merchant configuration used by the SDK.

  • Type

    @interface PayKKaConf : NSObject
  • Properties

    • EMPTY (PayKKaConf *): Built-in empty configuration object. By default, it contains empty-string values for gatewayMerchantId and clientKey.
    • configuration (NSDictionary *): The raw dictionary of the current configuration object.

initWithDict()

Initializes a merchant configuration object with a dictionary.

  • Type

    - (instancetype)initWithDict:(NSDictionary *)dict;
  • Details

    • It is recommended to provide at least the following fields:
      • KEY_GATEWAY_MERCHANT_ID
      • KEY_CLIENT_KEY

Data Models

PaymentResult

An object that contains detailed payment result information.

  • Properties
    • status (PaymentStatus): Payment status.
    • message (NSString *): Related message or error description.
    • result (NSDictionary *): Raw payment data.

PaymentStatus

Payment status enum:

  • PaymentStatusSuccess: Payment succeeded.
  • PaymentStatusExpired: The payment session has expired.
  • PaymentStatusError: An error occurred during payment.
  • PaymentStatusUnknown: Unknown status.

toString()

Serializes the payment result to a JSON string.

  • Type
    - (NSString *)toString;