Pay with Swish

Deprecated
Deprecated in version 2.5.0 for Android SDK and version 3.3.0 for iOS SDK.
Use getSwishUrl instead.
In order to make a payment using Swish a swish token needs to be obtained by calling the getSwishToken function using a payment token provided by your server.
After obtaining this token, the app should use it to start the Swish app. Once the Swish intent is handled, the app should call getPaymentResponse in order to obtain the payment status. Swish Flow

Get Swish Token

Provides a valid Swish token for this payment.

Note

Please read the official Swish documentation on how to launch the app with a token.

ParameterDescription
receiveOnThe dispatch queue used when invoking the result callback handler. Defaults to main.
onResultResult callback handler.
Please note
SveaWalletClient is deprecated in version 3.1.0. Use new class SveaAppWallet instead.
SveaAppWalletSveaWalletClient (deprecated)
Copy
Copied
SveaAppWallet.shared.getSwishToken(paymentToken: paymentToken) { [weak self] result in
    switch result {
    case .success(let swishToken):
        // Build swish URL with token and open Swish if installed.
        guard let swishUrl = URL(string: "swish://paymentrequest?token=\(token)&callbackurl=yourapp://example")
            else { return } // Handle error creating url
        UIApplication.shared.open(swishUrl. options: [:], completionHandler: nil])
    case .failure(let error):
        print("Could not get swish token, got error: \(error)")
    }
}
Copy
Copied
SveaWalletClient.shared.getSwishToken(paymentToken: paymentToken) { [weak self] result in
    switch result {
    case .onSuccess(let swishToken):
        // Build swish URL with token and open Swish if installed.
        guard let swishUrl = URL(string: "swish://paymentrequest?token=\(token)&callbackurl=yourapp://example")
            else { return } // Handle error creating url
        UIApplication.shared.open(swishUrl. options: [:], completionHandler: nil])
    case .onFailure(let error):
        print("Could not get swish token, got error: \(error)")
    }
}

onSuccess

Returned when a Swish token is successfully generated

onFailure

Returned when an error occurs.

Possible errors

Copy
Copied
case unknownError           // An unknown error occurred.

Get payment response

Returns the status of a Swish payment

ParameterDescription
receiveOnThe dispatch queue used when invoking the result callback handler. Defaults to main.
onResultResult callback handler.
Please note
SveaWalletClient is deprecated in version 3.1.0. Use new class SveaAppWallet instead.
SveaAppWalletSveaWalletClient
Copy
Copied
SveaAppWallet.shared.getSwishPaymentResponse { [weak self] result in
    switch result {
    case .success:
        print("Swish payment completed!")
    case .failure(let error):
        print("Swish payment could not be completed, got error \(error)")
    }
}
Copy
Copied
SveaWalletClient.shared.getSwishPaymentResponse { [weak self] result in
    switch result {
    case .onSuccess:
        print("Swish payment completed!")
    case .onFailure(let error):
        print("Swish payment could not be completed, got error \(error)")
    }
}

onSuccess

Returned when a Swish payment is successfully completed.

onFailure

Returned when an error occurs.

Possible errors

Copy
Copied
case unknownError           // An unknown error occurred.