Pay with Swish

Important

Introduced in Android version 2.5.0 and iOS version 3.3.0.

In order to make a payment using Swish, a URL to launch the application needs to be obtained by calling the getSwishUrl function using a payment token provided by your server.After obtaining this URL, the app should use it to create an intent and launch the Swish App.
The staging environment can be configured to return URLs launching either swish-sandbox or a web interface mocking the swish responses. The URLs are consutructed in a way so that you should not need to process it before launching an app request on your platform.Once the Swish intent is handled, the app should call getPaymentResponse in order to obtain the payment status. Swish Flow

Get Swish URL

Provides a valid Swish URL for this payment.

ParameterDescription
paymentTokenA valid payment token from your backend.
callbackUrlA valid URL for returning to the application.
receiveOnThe dispatch queue used when invoking the result callback handler. Defaults to main.
onResultResult callback handler.
Copy
Copied
SveaAppWallet.shared.getSwishUrl(paymentToken: paymentToken, callbackUrl: URL) { [weak self] result in
    switch result {
    case .success(let swishUrl):
        // Using swish url open Swish if installed.
        UIApplication.shared.open(swishUrl. options: [:], completionHandler: nil])
    case .failure(let error):
        print("Could not get swish url, got error: \(error)")
    }
}

onSuccess

Returned when a URL to used to launch swish is successfully generated

onFailure

Returned when an error occurs.

Possible errors

Copy
Copied
case noPaymentTokenProvided     // No payment token was found
case failedToGetSwishUrl        // The request could not be completed.

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 noPaymentTokenProvided             // No payment token was found
case failedToConfirmPaymentStatus       // Payment failed