Snabble Pay SDK for iOS
Getting Started
Initialize Snabble Pay
SnabblePay needs to be initialized with an ApiKey
associated with your project. Optional variables are the Credential
and an URLSession
. The Credential
are reported by the SnabblePayDelegate
after the first payment method is added. You are responsible for storing the information securely. These credentials need to be provided for existing users. Don’t forget to set the delegate
to store the Credential
instance and environment
variable for testing.
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
}
}
}
Example Flow for a new account, new mandate and a session start
The following sequence displays the basic flow (happy path) from creating a new account up to starting a new session.

Use accountCheck
to receive an AccountCheck
holding the validation link.
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
)
Open the validationURL
to start the payment method verification. After a succeeded validation the user will be redirected to the application over the given appUri, which contains an accountId
as query parameter.
The account should then be fetched with the given accountId
.
snabblePay.account(withId: accountId)
If the mandate for the account is missing, a new one needs to be created with the accountId
.
snabblePay.createMandate(forAccountId: accountId)
Accept the mandate to continue with further interaction. To accept a mandate, the application must specify the accountId
for the mandate and the mandateId
that the mandate received in the previous call.
snabblePay.acceptMandate(withId: mandateId, forAccountId: accountId)
After the mandate has been accepted successfully, a Session
can be started to generate a QRCode. The application needs to provide an accountId
, which should be used for the payment.
snabblePay.startSession(withAccountId: accountId)
The Session
has a variable Token
. Please use the value
variable of the Token
to display a QR-Code.
Snabble Pay SDK for iOS
Getting Started
Initialize Snabble Pay
SnabblePay needs to be initialized with an
ApiKey
associated with your project. Optional variables are theCredential
and anURLSession
. TheCredential
are reported by theSnabblePayDelegate
after the first payment method is added. You are responsible for storing the information securely. These credentials need to be provided for existing users. Don’t forget to set thedelegate
to store theCredential
instance andenvironment
variable for testing.Example Flow for a new account, new mandate and a session start
The following sequence displays the basic flow (happy path) from creating a new account up to starting a new session.
Use
accountCheck
to receive anAccountCheck
holding the validation link.Open the
validationURL
to start the payment method verification. After a succeeded validation the user will be redirected to the application over the given appUri, which contains anaccountId
as query parameter.The account should then be fetched with the given
accountId
.If the mandate for the account is missing, a new one needs to be created with the
accountId
.Accept the mandate to continue with further interaction. To accept a mandate, the application must specify the
accountId
for the mandate and themandateId
that the mandate received in the previous call.After the mandate has been accepted successfully, a
Session
can be started to generate a QRCode. The application needs to provide anaccountId
, which should be used for the payment.The
Session
has a variableToken
. Please use thevalue
variable of theToken
to display a QR-Code.