PaymentMethodToken

@objc(DTPaymentMethodToken)
@objcMembers
public class PaymentMethodToken : PaymentMethod

This class is the base token class to gather token information and process recurring payments or fast checkouts with any payment method. This class is sufficient to process payments with tokens of some payment methods (e.g. Twint). More complex payment methods require you to specify some more details in their token subclasses (e.g. card payments, PostFinance, etc.). Please refer to the list below to see if you need to call an additional token subclass for your payments.

  • Easy payment methods: Swisscom Easypay, SEPA (ELV), Twint, Apple Pay, Byjuno, SwissPass, Powerpay Invoice
  • Complex payment methods (requiring token subclass): Card payments, PayPal, PostFinance, Reka

Please refer to the Datatrans documentation to see if you can register a token during payment or require a dedicated registration.

  • The token that can be used to process recurring payments or fast checkouts.

    Declaration

    Swift

    public var token: String
  • A human readable title.

    Declaration

    Swift

    public var displayTitle: String { get }
  • For VoiceOver this title is used instead of displayTitle.

    Declaration

    Swift

    public var accessibilityTitle: String? { get }
  • This init method has to be used to initialize a payment object.

    Declaration

    Swift

    public init(type: PaymentMethodType, token: String)

    Parameters

    type

    Payment method type, e.g. PayPal or Twint

    token

    The token that can be used to process recurring payments or fast checkouts.

  • Creates a PaymentMethodToken from encoded data using the given decoder.

    Note that this function is only available from iOS 13. Earlier implementations need to use create(jsonString:).

    Declaration

    Swift

    @available(iOS 13.0, *)
    public class func create<T>(data: T.Input, decoder: T) -> PaymentMethodToken? where T : TopLevelDecoder

    Parameters

    data

    Encoded data, e.g. encoded by JSONEncoder

    decoder

    Decoder used for decoding the data, e.g. JSONDecoder

  • Creates a PaymentMethodToken from a JSON string.

    Note that this function should only be used for iOS 12 and earlier. Use create(data:decoder:) for later versions.

    Declaration

    Swift

    @available(iOS, deprecated: 13.0, message: "Use create(data:decoder:﹚ instead.")
    public class func create(jsonString: String) -> PaymentMethodToken?

    Parameters

    jsonString

    String of JSON encoded data

  • Creates a PaymentMethodToken from data encoded by the old payment library.

    Declaration

    Swift

    public class func create(legacyTokenData: Data) -> PaymentMethodToken?

    Parameters

    legacyTokenData

    Data encoded by DTRecurringPaymentMethod.data(), DTCreditCard.data(), DTPostFinanceCard.data(), DTReka.data() or DTPayPal.data().

    Return Value

    The decoded PaymentMethodToken, CardToken, PostFinanceCardToken, RekaToken or PayPalToken, if successful, nil if legacyTokenData is invalid.

  • Returns a JSON string representation of this token payment object. This is a convenience method for serialization/deserialization.

    Declaration

    Swift

    public func toJson() throws -> String?

    Return Value

    The JSON string representation

  • This function checks if the payment method token is valid. This function will also be used to tell you if data (e.g. expiry date) from the token subclasses is correct or not.

    Declaration

    Swift

    public func isValid() -> Bool
  • Refer to the NSObject protocol

    Declaration

    Swift

    override public var description: String { get }
  • Refer to the Encodable protocol

    Declaration

    Swift

    override public func encode(to encoder: Encoder) throws
  • Refer to the NSCoding protocol

    Declaration

    Swift

    public required init?(coder: NSCoder)
  • Refer to the NSCopying protocol

    Declaration

    Swift

    override public func copy(with zone: NSZone? = nil) -> Any