Snabble Pay iOS SDK


开始使用

初始化 Snabble Pay

SnabblePay 需要使用与您的项目关联的 ApiKey 进行初始化。可选变量是 CredentialURLSessionCredential 在添加第一个支付方式后由 SnabblePayDelegate 报告。您有责任安全地存储这些信息。现有用户需要提供这些凭据。别忘了设置 delegate 以存储 Credential 实例和用于测试的 environment 变量。

var credentials: Credentials?
if let encodedCredentials = UserDefaults.credentials {
    credentials = try? JSONDecoder().decode(Credentials.self, from: encodedCredentials)
}

let snabblePay: SnabblePay = .init(
    apiKey: "IO2wX69CsqZUQ3HshOnRkO4y5Gy/kRar6Fnvkp94piA2ivUun7TC7MjukrgUKlu7g8W8/enVsPDT7Kvq28ycw==", // this is a test API-KEY
    credentials: credentials
)
snabblePay.environment = .development // .staging, .production
snabblePay.delegate = snabblePay
extension SnabblePay: SnabblePayDelegate {
    public func snabblePay(_ snabblePay: SnabblePay, didUpdateCredentials credentials: Credentials?) {
        if let encoded = try? JSONEncoder().encode(credentials) {
            UserDefaults.credentials = encoded
       } else {
            UserDefaults.credentials = nil
        }
    }
}

新账户、新授权和会话启动的示例流程

以下序列展示了从创建新账户到启动新会话的基本流程(成功路径)。

Flow

使用 accountCheck 以接收包含验证链接的 AccountCheck

snabblePay.accountCheck(
    withAppUri: "snabble-pay://account/check", // Callback URLScheme to inform the app that the process is completed
    city: "Bonn", // The city of residence
    countryCode: "DE" // The countryCode [PayOne - ISO 3166](https://docs.payone.com/pages/releaseview.action?pageId=1213959) of residence
)

打开 validationURL 以启动支付方式验证。验证成功后,用户将被重定向到通过给定的 appUri 返回应用程序,其中 appUri 包含作为查询参数的 accountId

然后应该使用给定的 accountId 获取账户。

snabblePay.account(withId: accountId)

如果账户缺少授权,则需要使用 accountId 创建一个新的授权。

snabblePay.createMandate(forAccountId: accountId)

接受授权以继续进行后续交互。要接受授权,应用程序必须指定授权的 accountId 和授权在前一次调用中收到的 mandateId

snabblePay.acceptMandate(withId: mandateId, forAccountId: accountId)

成功接受授权后,可以启动 Session 以生成二维码。应用程序需要提供将用于支付的 accountId

snabblePay.startSession(withAccountId: accountId)

Session 有一个变量 Token。请使用 Tokenvalue 变量来显示二维码。