Pay with Invoice

Important

Introduced in Android version 2.6.0 and iOS version 3.4.0

To pay with an invoice the app must require a BankId token using the getBankIdUrlForPayment method, providing a payment token.

After obtaining this URL, the app should use it to create an intent and launch the BankId App.
The URLs are constructed in a way so that you should not need to process it before launching BankID from your app.

Once the BankId intent is handled, the app should call getPaymentResponse in order to obtain the payment status. Invoice Flow

Get BankId Url

Provides a valid BankId token for this payment.

ParameterDescription
paymentTokenA payment token provider by the partner's backend
redirectUrlA 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.getBankIdUrlForPayment(paymentToken: paymentToken, redirectUrl: URL) { [weak self] result in
    switch result {
    case .success(let bankIdUrl):
        // Using this bankId URL open BankId if installed.
        UIApplication.shared.open(bankIdUrl. options: [:], completionHandler: nil])
    case .failure(let error):
        print("Could not get bankId url, got error \(error)")
    }
}

onSuccess

Returned when a BankId token is successfully generated.

onFailure

Returned when an error occurs.

Possible errors

Copy
Copied
case noPaymentTokenProvided       // No payment token was found
case failedToGetBankIdUrl         //The bankId url could not be fetched

Get payment response

Returns the status of an invoice payment.

ParameterDescription
onResultResult callback handler.

onSuccess

Returned when a BankId payment is successfully completed.

onFailure

Returned when an error occurs.

Possible errors

Copy
Copied
case failedToPay                     // Failed to pay using invoice.
case failedToConfirmPayment          // Failed to get payment status

Test invoice payments with BankID

We provide two options for testing invoice payments with BankID in the stage environment. BankID mock will be used by default for new projects.

BankID mock

BankID mock is a web app that that simulates the BankID client. When configured for BankID mock, the example code above will open BankID mock in the default browser, and you will get options to test different scenarios.

BankID mock

Complete BankID session

Press one of the buttons to complete the BankID session and simulate a specific scenario:

  • WebPay Approved will sign the BankID session with a test person that WebPay will approve credit for.
    • When testing private invoice payment, this option will result in a successful payment.
    • When testing company invoice payment, the payment will be approved or denied depending on the company org.no that was used when adding the company invoice.
  • WebPay Denied (private invoice) will sign the BankID session with a test person that WebPay will deny credit for.
  • Cancel will cancel the BankID session and no credit check will be made.

Note that the browser tab will stay open until you close it.

Test with redirectUrl

If you entered a redirectUrl to your application you will get the option to use it when completing the BankID session.

Note that some browsers will not work properly with this option

Test with delay

You can simulate either a delayed callback from the BankID server or a delayed redirect from the BankID client. This can be useful if you want to test your implementation for race conditions.

To use the client BankID redirect delay you must also provide the redirectUrl. A server delay does not require the redirectUrl, but you can use it for more precise timing.

Get a BankID for test

The official BankID for test can be used for a more realistic test. Follow the link for instructions on how to set it up, then contact Svea to activate it.

If you are testing private invoice then you can use any of the personal numbers (person.no) bellow when setting up a BankID for test to get the desired result. They can also be used when testing company invoices, but they will not affect the result.

ResultPerson.noNameStreetc/oZip codeCityTelephone
Approved4605092222Tess, T PerssonTestgatan 1c/o Eriksson, Erik99999Stan08 – 111 111 11
Denied4610081111Tess, T PerssonTestgatan 1c/o Eriksson, Erik99999Stan08 – 111 111 11
Abuse4606082222Tess, T PerssonTestgatan 1c/o Eriksson, Erik99999Stan08 – 111 111 11
Limit4611071111Tess, T PerssonTestgatan 1c/o Eriksson, Erik99999Stan08 – 111 111 11