Search Overlay

Event Handling and Helper Functions

The Paysafe iOS SDK provides developers with methods and events for managing card form fields efficiently. These methods and events enable seamless integration of card-related functionalities into iOS applications. Below are the available methods and events along with their descriptions: 

Card Form Fields Events

Developers can subscribe to specific events to handle user interactions on card number, expiry date, and CVV fields. By implementing event handlers, developers can customize the behavior of the card form fields based on user actions, ensuring a smooth and intuitive checkout experience.

The supported events are listed below

Event Description

INVALID

Triggered when invalid input is detected in a card form field

VALID

Triggered when valid input is detected in a card form field

FOCUS

Triggered when the user focuses on the card form field

FIELD_VALUE_CHANGE

Triggered when the card form field value changes.

INVALID_CHARACTER

Triggered when an invalid character is entered.

An example is show below

field.onEvent = { event in
switch event {
case .invalid:
print("Invalid CVV entered")
case .valid:
print("Valid CVV entered")
case .focus:
print("User focused on CVV field")
case .fieldValueChange:
print("CVV field value changed")
case .invalidCharacter:
print("Invalid character entered in CVV field")
default:
break
}
}

The supported events are described by the following enum

/// PSCardFieldInputEvent
public enum PSCardFieldInputEvent {
/// Focus event
case focus
/// Valid event
case valid
/// Invalid event
case invalid
/// Field value change event
case fieldValueChange
/// Invalid character event
case invalidCharacter
}

Card Form Fields Helper Methods

All card fields define several common methods that developers can use to interact with these components. These methods facilitate functionalities such as validation, resetting, and obtaining placeholder information, enabling seamless interaction with card-related input fields within the payment processing workflow. 

Below are the method signatures along with their descriptions:

isEmpty() -> Bool

This method checks whether the card field is empty or not.

Returns true if the field is empty.

let isFieldEmpty = cardNumField.isEmpty() // Check if card number field is empty or not

isValid() -> Bool

This method verifies whether the entered card information is valid or not.

Returns true if the field contains valid values.

let isFieldValid = cardField.isValid() //Check if card number field is valid or not

resetTheme()

This method resets the theme of the card field component to its default state.

cardNumField.resetTheme() //Reset the card number field theme

reset()

This method resets the content of the card field, clearing any entered information.

cardField.reset() //Reset the card number field contents

getPlaceholder() -> String?

This method retrieves the placeholder text for the card field, if available.

if let placeholder = cardField.getPlaceholder() {

Card Form Helper Methods

PsCardForm defines several common methods that developers can use to interact with all the field components. These methods facilitate functionalities such as validation, resetting, and obtaining card brand information and recognization

areAllFieldsValid() > Bool

This method returns a Boolean value indicating whether all fields in the card form are valid.

Returns true if all the fields are valid

let isFormValid = cardForm.areAllFieldsValid() //Check if all card form fields (card number, expiry & CVV) are valid

getCardBrand() > PSCardBrand

This method retrieves the card brand from the card form.

Returns PSCardBrand enum containing card brand information

let cardBrand = cardForm.getCardBrand() //Get the card brand from the card form

onCardBrandRecognition: (PSCardBrand) -> Void?

This event is triggered when the Paysafe iOS SDK algorithm identifies a card brand in the card form.

cardForm.onCardBrandRecognition = { cardBrand in 

  print("Card brand recognition => \(cardBrand)") 

Note: The PSCardBrand enum defines the following cases:

  • .visa: Visa card
  • .mastercard: Mastercard card
  • .amex: American Express card
  • .discover: Discover card
  • .unknown: Unknown card. This doesn't mean incorrect, it's for valid (by Luhn algorithm) credit cards, but trademark icon will not be displayed in the user interface in the card number field.

resetCardDetails()

The function provides flexibility for the merchant to clear previously inserted card data in Paysafe iOS SDK fields. This is to be used when the customer is switching between paying with а saved or а new card.

cardForm.resetCardDetails()

Developers can utilize these methods and events to enhance the functionality of their iOS applications by effectively managing card form fields, validating input, and responding to card brand recognition events triggered by the SDK algorithm.