The main entry class of the SDK, used to configure the environment and start the payment flow.
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.EMPTYis 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
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.SANDBOXis used by default.- Internally,
initcallsuseEnv(...)anduseConf(...)and completes SDK initializations. - Before calling
goPay(...)or any SwiftUI checkout-related capability, you should complete initialization first; otherwise, anNSInternalInconsistencyExceptionwill be thrown. - The Swift exposed name is
PayKKa.Init(...), with an uppercaseI.
Example
[PayKKa init:appConf environment:PayKKaEnv.SANDBOX]; // or [PayKKa init:appConf];PayKKa.Init(appConf, .SANDBOX) // or PayKKa.Init(appConf)
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 aPaymentResultobject.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); } }];
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.
Used to define the merchant configuration used by the SDK.
Type
@interface PayKKaConf : NSObjectProperties
EMPTY(PayKKaConf *): Built-in empty configuration object. By default, it contains empty-string values forgatewayMerchantIdandclientKey.configuration(NSDictionary *): The raw dictionary of the current configuration object.
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_IDKEY_CLIENT_KEY
- It is recommended to provide at least the following fields:
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.
Payment status enum:
PaymentStatusSuccess: Payment succeeded.PaymentStatusExpired: The payment session has expired.PaymentStatusError: An error occurred during payment.PaymentStatusUnknown: Unknown status.
Serializes the payment result to a JSON string.
- Type
- (NSString *)toString;