Add a card

Creating card information object

As the user enters their card information, create a CardInformation object.

Adding a card

info

If a card needs to be 3DSecure enrolled, then a web view will be shown to the user.
The Svea App Wallet SDK will automatically dismiss this view once the information is processed.

The 3DSecure session is valid for 20 minutes.

ParameterDescription
cardA CardInformation object.
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
let cardInformation = CardInformation(
    cardNumber: "XXXXXXXXXXXXXXXX",
    expirationDate: CardDate(
        month: "12",
        year: "20"
    ),
    label: "My card",
    securityCode: "XXX"
)

SveaAppWallet.shared.add(card: cardInformation) { [weak self] result in
    switch result {
    case .success(let paymentMethod):
            print("Card successfully added \(paymentMethod)")
    case .failure(let error):
            print("Card could not be added, got error \(error)")
    }
}
Copy
Copied
let cardInformation = CardInformation(
    cardNumber: "XXXXXXXXXXXXXXXX",
    expirationDate: CardDate(
        month: "12",
        year: "20"
    ),
    label: "My card",
    securityCode: "XXX"
)

SveaWalletClient.shared.add(card: cardInformation) { [weak self] result in
    switch result {
    case .onSuccess(let paymentMethod):
            print("Card successfully added \(paymentMethod)")
    case .onFailure(let error):
            print("Card could not be added, got error \(error)")
    }
}

onSuccess

Returned if the card was successfully added, including the card information in a PaymentMethod

Please note

The initial, unmasked card information added by the user should never be saved in your systems.

onFailure

Returned if the card cannot be added.

Possible errors

Copy
Copied
case noUserTokenProvided    // A user token was not provided.
case invalidCardNumber      // The card number is not valid.
case invalidMonth           // The month value is bigger than 12 or smaller than 1.
case invalidYear            // The year value is not 2 digits.
case monthInThePast         // The selected year is valid, but the month has passed.
case yearInThePast          // The selected year has passed.
case invalidSecurityCode    // Invalid security code.
case failedToAddCard        // Something went wrong while adding a card.
case unknownError           // An unknown error occurred.

Test cards

In the stage environment test cards are expected. Use one of the test card numbers from the list below together with an expire date in the future and random cvc code.

Note

These test cards should only be used in stage. Real card information should only be used in production.

MastercardVisaAmex
53921273320105334916423239778102373577924279157
55630158723674674539135129670408349280060805312
5590714784028392430783655278077634343434343434
54987291627720674556713187886682