STPCard

public class STPCard : NSObject, STPAPIResponseDecodable, STPPaymentOption, STPSourceProtocol

Representation of a user’s credit card details that have been tokenized with the Stripe API

  • The last 4 digits of the card.

    Declaration

    Swift

    @objc
    public internal(set) var last4: String { get }
  • For cards made with Apple Pay, this refers to the last 4 digits of the “Device Account Number” for the tokenized card. For regular cards, it will be nil.

    Declaration

    Swift

    @objc
    public internal(set) var dynamicLast4: String? { get }
  • Whether or not the card originated from Apple Pay.

    Declaration

    Swift

    @objc
    public var isApplePayCard: Bool { get }
  • The card’s expiration month. 1-indexed (i.e. 1 == January)

    Declaration

    Swift

    @objc
    public internal(set) var expMonth: Int { get }
  • The card’s expiration year.

    Declaration

    Swift

    @objc
    public internal(set) var expYear: Int { get }
  • The cardholder’s name.

    Declaration

    Swift

    @objc
    public internal(set) var name: String? { get }
  • The cardholder’s address.

    Declaration

    Swift

    @objc
    public internal(set) var address: STPAddress? { get }
  • The issuer of the card.

    Declaration

    Swift

    @objc
    public internal(set) var brand: STPCardBrand { get }
  • The funding source for the card (credit, debit, prepaid, or other)

    Declaration

    Swift

    @objc
    public internal(set) var funding: STPCardFundingType { get }
  • Two-letter ISO code representing the issuing country of the card.

    Declaration

    Swift

    @objc
    public internal(set) var country: String? { get }
  • This is only applicable when tokenizing debit cards to issue payouts to managed accounts. You should not set it otherwise. The card can then be used as a transfer destination for funds in this currency.

    Declaration

    Swift

    @objc
    public internal(set) var currency: String? { get }
  • Returns a string representation for the provided card brand; i.e. STPCard.string(from brand: .visa) == "Visa".

    Declaration

    Swift

    @objc(stringFromBrand:)
    public class func string(from brand: STPCardBrand) -> String

    Parameters

    brand

    the brand you want to convert to a string

    Return Value

    A string representing the brand, suitable for displaying to a user.

  • This parses a string representing a card’s brand into the appropriate STPCardBrand enum value, i.e. STPCard.brand(from string: "American Express") == .amex. The string values themselves are specific to Stripe as listed in the Stripe API documentation.

    Declaration

    Swift

    @objc(brandFromString:)
    public class func brand(from string: String) -> STPCardBrand

    Parameters

    string

    a string representing the card’s brand as returned from the Stripe API

    Return Value

    an enum value mapped to that string. If the string is unrecognized, returns STPCardBrandUnknown.

  • Create an STPCard from a Stripe API response.

    Declaration

    Swift

    @available(*, deprecated, message: "You cannot directly instantiate an STPCard. You should only use one that has been returned from an STPAPIClient callback.")
    @objc(initWithID:brand:last4:expMonth:expYear:funding:)
    public init(
      id cardID: String,
      brand: STPCardBrand,
      last4: String,
      expMonth: Int,
      expYear: Int,
      funding: STPCardFundingType
    )

    Parameters

    cardID

    The Stripe ID of the card, e.g. card_185iQx4JYtv6MPZKfcuXwkOx

    brand

    The brand of the card (e.g. “Visa”. To obtain this enum value from a string, use STPCardBrand.brand(from string:string);

    last4

    The last 4 digits of the card, e.g. 4242

    expMonth

    The card’s expiration month, 1-indexed (i.e. 1 = January)

    expYear

    The card’s expiration year

    funding

    The card’s funding type (credit, debit, or prepaid). To obtain this enum value from a string, use STPCardBrand.funding(from string:).

    Return Value

    an STPCard instance populated with the provided values.

  • This parses a string representing a card’s funding type into the appropriate STPCardFundingType enum value, i.e. STPCard.funding(from string:"prepaid") == .prepaid.

    Declaration

    Swift

    @objc(fundingFromString:)
    public class func funding(from string: String) -> STPCardFundingType

    Parameters

    string

    a string representing the card’s funding type as returned from the Stripe API

    Return Value

    an enum value mapped to that string. If the string is unrecognized, returns STPCardFundingTypeOther.

  • Declaration

    Swift

    @objc
    public var stripeID: String
  • Declaration

    Swift

    internal(set) public var allResponseFields: [AnyHashable : Any] { get }

STPAPIResponseDecodable

STPPaymentOption

Deprecated methods

  • A set of key/value pairs associated with the card object. @deprecated Metadata is no longer returned to clients using publishable keys. Retrieve them on your server using yoursecret key instead.

    Declaration

    Swift

    @available(*, deprecated, message: "Metadata is no longer returned to clients using publishable keys. Retrieve them on your server using yoursecret key instead.")
    @objc
    public private(set) var metadata: [String : String]? { get }
  • The Stripe ID for the card.

    Declaration

    Swift

    @available(*, deprecated, message: "Use stripeID (defined in STPSourceProtocol﹚")
    @objc
    public var cardId: String? { get }
  • The first line of the cardholder’s address

    Declaration

    Swift

    @available(*, deprecated, message: "Use address.line1")
    @objc
    public var addressLine1: String? { get }
  • The second line of the cardholder’s address

    Declaration

    Swift

    @available(*, deprecated, message: "Use address.line2")
    @objc
    public var addressLine2: String? { get }
  • The city of the cardholder’s address

    Declaration

    Swift

    @available(*, deprecated, message: "Use address.city")
    @objc
    public var addressCity: String? { get }
  • The state of the cardholder’s address

    Declaration

    Swift

    @available(*, deprecated, message: "Use address.state")
    @objc
    public var addressState: String? { get }
  • The zip code of the cardholder’s address

    Declaration

    Swift

    @available(*, deprecated, message: "Use address.postalCode")
    @objc
    public var addressZip: String? { get }
  • The country of the cardholder’s address

    Declaration

    Swift

    @available(*, deprecated, message: "Use address.country")
    @objc
    public var addressCountry: String? { get }