Skip to content

2C2P/OneTwoThreeSDK-iOS

Repository files navigation

OneTwoThreeSDK

Installation

Swift Package Manager

To integrate OneTwoThreeSDK using Swift Package Manager, you can easily add this to your Xcode project:

dependencies: [
    .package(url: "https://github.com/OrawanM/OneTwoThreeSDK.git", .upToNextMajor(from: "1.0.2"))
]

Import

import OneTwoThreeSDK

Usage

import OneTwoThreeSDK

class ViewController: UIViewController {

    let service = OneTwoThreeSDKService(
        checksumKey: "CHECKSUM_KEY",
        publicKey: "PUBLIC_KEY",
        privateKey: "PRIVATE_KEY",
        passphrase: "PASSPHASE"
    )
    
    let merchant = Merchant(
        id: "[email protected]",
        redirectURL: "onetwothreeapp://",
        notificationURL: "https://uat2.123.co.th/DemoShopping/apicallurl.aspx",
        merchantData: [
            MerchantData(key: "item", value: "943-cnht302gg"),
            MerchantData(key: "item", value: "FH403"),
            MerchantData(key: "item", value: "10,000.00"),
            MerchantData(key: "item", value: "Ref. 43, par. 7")
        ]
    )
    let transaction = Transaction(
        merchantReference: "309321249653",
        preferredAgent: "SCB",
        productDesc: "",
        amount: "100",
        currencyCode: "THB",
        paymentInfo: "",
        paymentExpiry: "2021-12-10 11:21:36"
    )
    let buyer = Buyer(
        email: "[email protected]",
        mobile: "09912345678",
        language: "EN",
        notifyBuyer: true,
        title: "Mr",
        firstName: "Bruce",
        lastName: "Wayne"
    )
    
    func startDeeplink() {
        service.startDeeplink(merchant: merchant, transaction: transaction, buyer: buyer) { response in
            // TODO: Success
            
            // NOTE: Redirect to bank app using 'deeplinkURL' from the response.
            if let deeplinkURL = response?.deeplinkURL, let url = URL(string: deeplinkURL) {
                UIApplication.shared.open(url) { (result) in
                    if result {
                        // TODO: Success
                    } else {
                        // TODO: Failed
                    }
                }
            }
            
        } failureBlock: { error in
            // TODO: Failed
        }
    }
        
}

Contributing

2C2P

License

MIT