iMojeSDK 0.1.8

iMojeSDK 0.1.8

Krystian Kulawiak 维护。



 
依赖项
Alamofire= 4.9.1
AlamofireImage= 3.6.0
RxSwift= 6.5.0
RxCocoa= 6.5.0
 

iMojeSDK 0.1.8

  • 网友

iMojeSDK

CI Status Version License Platform

安装

imoje-ios-sdk 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile

pod 'iMojeSDK'

将此行添加到 pod 文件顶部

install! 'cocoapods', :disable_input_output_paths => true

本地化

按照 iMojeSDK 的示例创建文件 Localizable.strings

// Change sdk language
iMoje.sharedInstance.setLanguage(language: "pl")

用法

  • 创建新的 INGChosePaymentViewController 与额外的支付方式
func showChosePaymentButton() {
    let customPayments: [INGPaymentMethod] = [
        .custom(id: "visa", image: .named(imageName: "imoje"), name: "Dodatkowy kafelek")
    ]
    
    let viewController = INGChosePaymentViewController(customItems: customPayments)
    viewController.navigationBarTitle = nil
    
    viewController.itemSelected = {[weak self] method in
        self?.showConfirmView(item: method)
    }
    
    showViewController(viewController, animated: true)
}
  • 检索标准 id 支付方式 INGPaymentMethodType
    INGPaymentMethodType.from(string: item.id)
  • 创建新的 INGConfirmViewController
func showConfirmView(item: INGPaymentMethod) {
    var info = INGConfirm(amount: 1000)
    info.currency = "PLN"
    let uuid = UUID().uuidString
    info.orderId = "SDK-OID-\(uuid)"
    info.title = "some title"
    info.paymentMethod = INGPaymentMethodType.from(string: item.id)
    info.paymentFor = """
    Salon Samochodowy Warszawa
    00-00 Warszawa
    """
    var customer = INGConfirm.Customer()
    customer.firstName = "Jan"
    customer.lastName = "Kowalski"
    customer.email = "[email protected]"
    customer.phone = "512615122"
    customer.cid = "123"
    info.customer = customer
    
    let confirmViewController = INGConfirmViewController(confirm: info)
    
    confirmViewController.callback = {[weak self] in
        self?.submitPayment(confirm: info)
    }
    showViewController(confirmViewController, animated: true)
}
  • 使用自定义银行项创建 INGBankViewController
func showBanks(_ banks: [INGBank], confirm: INGConfirm) {
    let customBank = INGBank(paymentMethod: .custom(code: "Custom"), paymentMethodCode: .custom(code: "custom", image: .url(imageURL: URL(string: "https://www.interest.co.nz/sites/default/files/feature_images/bank-3_0_0_0.jpg")!), name: "Custom Bank"), isActive: true, isOnline: false, currency: "PLN")
    
    let banksViewController = INGBankViewController(banks: banks + [customBank])
    banksViewController.bankSelected = {[weak self] bank in
        self?.createTransaction(with: bank, confirm: confirm)
    }
    banksViewController.navigationBarTitle = nil
    banksViewController.numbersOfColumn = 3
    showViewController(banksViewController, animated: true)
}
  • 创建 INGWebViewController
func showWebView(request: URLRequest?, html: String?, baseURL: URL?) {
    var webViewContent: INGWebViewContent
    if let request = request {
        webViewContent = .request(request: request)
    } else {
        webViewContent = .html(html: html ?? "", baseURL: baseURL)
    }
    let webView = INGWebViewController(content: webViewContent, successRedirectURL: "https://test.com/success", failureRedirectURL: "https://test.com/failure")
    
    webView.onSuccess = {[weak self] in
        print("Success")
        if RootViewController.showViewControllerModally {
            self?.dismiss(animated: true, completion: nil)
        } else {
            self?.navigationController?.popToRootViewController(animated: true)
        }
    }
    
    webView.onFailure = {[weak self] in
        print("Failure")
        if RootViewController.showViewControllerModally {
            self?.dismiss(animated: true, completion: nil)
        } else {
            self?.navigationController?.popToRootViewController(animated: true)
        }
    }

    showViewController(webView, animated: true)
}

ApplePay 使用

  • 启动 ApplePay
    var applePayHandler: INGApplePayHandler?
    
    func createApplePayPayment(confirm: INGConfirm) {
        let transaction = INGApplePayTransaction(merchantIdentifier: "Your merchant",
                                                 paymentItemDescription: "Payment Description",
                                                 amount: NSDecimalNumber(value: confirm.amount / 100)) // amount = 100.99 is equal to 100,99 zł
        applePayHandler = INGApplePayHandler(onSuccess: { resultToken in
            guard let codableToken = resultToken.codable else {
                return
            }
            let transaction: CreateTransaction = self.baseTransaction(confirm: confirm)
            transaction.paymentMethod = .card
            transaction.paymentMethodCode = .ecom3ds
            transaction.wallet = .init(applePay: codableToken)
            self.createTransaction(transaction)
        }, onFailure: { [weak self] error in
            self?.showError(error: error)
        })
        applePayHandler?.purchase(in: self, with: transaction)
    }

作者

网民,[email protected]

许可证

iMojeSDK 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。