Payrails 1.0.0

Payrails 1.0.0

Nikita Gubchenko 管理。



Payrails 1.0.0

  • Payrails

Payrails iOS SDK

Payrails iOS SDK 为您提供构建客户结账体验的组件。

Cocoapods 安装

pod 'Payrails/Checkout'

使用 Swift Package Manager 安装

使用 https://github.com/payrails/ios-sdk 作为仓库 URL。

启用苹果支付功能

要在您的应用程序中启用苹果支付,您需要在项目目标的设置中,添加商户ID到签名与能力

初始化Payrails React Native SDK

使用以下示例初始化Payrails客户端上下文。

异步/等待

import Payrails

private var payrails: Payrails.Session?

payrails = try await Payrails.configure(
 with: .init(
     version: version,
  data: data,
   option: .init(env: .dev)
   )
)

回调

Payrails.configure(with: .init(
        version: version,
                    data: data,
                    option: .init(env: .dev)
                )) { [weak self] result in
                    switch result {
                    case let .success(session):
                        self?.payrails = session
                    case let .failure(error):
                        print(error)
                    }
                }

其中 data 是base64字符串,版本是SDK版本,这些数据均从您的后端获取。

一旦SDK初始化完成,您的客户端现在可以直接与Payrails交互。

用户界面元素

Payrails iOS SDK为您提供了苹果支付和贝宝的按钮。

  1. 初始化Tokenization上下文
private let applePayButton = ApplePayButton(
        paymentButtonType: .checkout,
        paymentButtonStyle: .black
    )
applePayButton.onTap = { [weak self] in
            //make payment
}

private let payPalButton = PayPalButton()
payPalButton.onTap = { [weak self] in
            //make payment
}

检查可用的支付方式

Payrails iOS SDK允许您轻松检查特定支付方式是否可用。

applePayButton.isHidden = !payrails.isPaymentAvailable(type: .applePay)
payPalButton.isHidden = !payrails.isPaymentAvailable(type: .payPal)

创建新支付

Payrails iOS SDK 允许您轻松使用以下方式执行支付:

异步/等待

import Payrails

Task { [weak self, weak payrails] in
            let result = await payrails?.executePayment(
                with: type, //.applePay or .payPal
                saveInstrument: false, //set to true if you want to store payment
                presenter: self
            )

            DispatchQueue.main.async {
                switch result {
                case .success:
                    self?.log("Payment was successful!")
                case .authorizationFailed:
                    self?.log("Payment failed due to authorization")
                case .failure:
                    self?.log("Payment failed")
                case let .error(error):
                    self?.log(
                        format: "Payment failed due to error: %@",
                        error.localizedDescription
                    )
                case .cancelledByUser:
                    self?.log("Payment was cancelled by user")
                }
            }
        }

回调

payrails.executePayment(
            with: type, //.applePay or .payPal
            saveInstrument: false, //set to true if you want to store payment
            presenter: self) { [weak self] result in
                switch result {
                case .success:
                    self?.log("Payment was successful!")
                case .authorizationFailed:
                    self?.log("Payment failed due to authorization")
                case .failure:
                    self?.log("Payment failed (failure state)")
                case let .error(error):
                    self?.log(
                        format: "Payment failed due to error: %@",
                        error.localizedDescription
                    )
                case .cancelledByUser:
                    self?.log("Payment was cancelled by user")
                }
        }

在哪里

extension YourPaymentViewController: PaymentPresenter {
    func presentPayment(_ viewController: UIViewController) {
        DispatchQueue.main.async {
            self.present(viewController, animated: true)
        }
    }
}

存储的支付

Payrails iOS SDK 允许您检索和重复使用存储的支付

 payrails.storedInstruments.forEach { storedElement in
            switch storedElement.type {
            case .payPal:
                let storedPayPalButton = PayPalButton()
                storedPayPalButton.onTap = { [weak self] in
                    self?.pay(storedInstrument: storedElement)
                }
            default:
                break
            }
        }

private func pay(
        storedInstrument: StoredInstrument
    ) {
        Task { [weak self, weak payrails] in
            let result = await payrails?.executePayment(
                withStoredInstrument: storedInstrument,
                presenter: self
            )

            DispatchQueue.main.async {
                switch result {
                case .success:
                    self?.log("Payment was successful!")
                case .authorizationFailed:
                    self?.log("Payment failed due to authorization")
                case .failure:
                    self?.log("Payment failed (failure state)")
                case let .error(error):
                    self?.log(
                        format: "Payment failed due to error: %@",
                        error.localizedDescription
                    )
                case .cancelledByUser:
                    self?.log("Payment was cancelled by user")
                default:
                    break
                }
            }
        }
    }

安全策略

报告漏洞

如果您发现 Payrails iOS SDK 中的任何漏洞,请不要犹豫,立即报告

  1. 将披露发送至[email protected]

  2. 描述漏洞。

    如果您有一个修复方案,那是的最佳欢迎 -- 请将其附上或在您的消息中进行总结!

  3. 我们将评估漏洞,并在必要时发布修复程序或缓解步骤以处理它。我们将联系您告知结果,并在报告中向您致谢。

    请勿在修复发布之前公开披露漏洞

  4. 一旦我们发布了修复方案,或者由于任何原因决定不修复漏洞,您可以公开披露。