github.com/stripe/stripe-go/v76@v76.25.0/card.go (about)

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  package stripe
     8  
     9  import (
    10  	"encoding/json"
    11  	"github.com/stripe/stripe-go/v76/form"
    12  	"strconv"
    13  )
    14  
    15  // If `address_line1` was provided, results of the check: `pass`, `fail`, `unavailable`, or `unchecked`.
    16  type CardAddressLine1Check string
    17  
    18  // List of values that CardAddressLine1Check can take
    19  const (
    20  	CardAddressLine1CheckFail        CardAddressLine1Check = "fail"
    21  	CardAddressLine1CheckPass        CardAddressLine1Check = "pass"
    22  	CardAddressLine1CheckUnavailable CardAddressLine1Check = "unavailable"
    23  	CardAddressLine1CheckUnchecked   CardAddressLine1Check = "unchecked"
    24  )
    25  
    26  // If `address_zip` was provided, results of the check: `pass`, `fail`, `unavailable`, or `unchecked`.
    27  type CardAddressZipCheck string
    28  
    29  // List of values that CardAddressZipCheck can take
    30  const (
    31  	CardAddressZipCheckFail        CardAddressZipCheck = "fail"
    32  	CardAddressZipCheckPass        CardAddressZipCheck = "pass"
    33  	CardAddressZipCheckUnavailable CardAddressZipCheck = "unavailable"
    34  	CardAddressZipCheckUnchecked   CardAddressZipCheck = "unchecked"
    35  )
    36  
    37  // A set of available payout methods for this card. Only values from this set should be passed as the `method` when creating a payout.
    38  type CardAvailablePayoutMethod string
    39  
    40  // List of values that CardAvailablePayoutMethod can take
    41  const (
    42  	CardAvailablePayoutMethodInstant  CardAvailablePayoutMethod = "instant"
    43  	CardAvailablePayoutMethodStandard CardAvailablePayoutMethod = "standard"
    44  )
    45  
    46  // Card brand. Can be `American Express`, `Diners Club`, `Discover`, `Eftpos Australia`, `JCB`, `MasterCard`, `UnionPay`, `Visa`, or `Unknown`.
    47  type CardBrand string
    48  
    49  // List of values that CardBrand can take
    50  const (
    51  	CardBrandAmericanExpress CardBrand = "American Express"
    52  	CardBrandDiscover        CardBrand = "Discover"
    53  	CardBrandDinersClub      CardBrand = "Diners Club"
    54  	CardBrandJCB             CardBrand = "JCB"
    55  	CardBrandMasterCard      CardBrand = "MasterCard"
    56  	CardBrandUnknown         CardBrand = "Unknown"
    57  	CardBrandUnionPay        CardBrand = "UnionPay"
    58  	CardBrandVisa            CardBrand = "Visa"
    59  )
    60  
    61  // If a CVC was provided, results of the check: `pass`, `fail`, `unavailable`, or `unchecked`. A result of unchecked indicates that CVC was provided but hasn't been checked yet. Checks are typically performed when attaching a card to a Customer object, or when creating a charge. For more details, see [Check if a card is valid without a charge](https://support.stripe.com/questions/check-if-a-card-is-valid-without-a-charge).
    62  type CardCVCCheck string
    63  
    64  // List of values that CardCVCCheck can take
    65  const (
    66  	CardCVCCheckFail        CardCVCCheck = "fail"
    67  	CardCVCCheckPass        CardCVCCheck = "pass"
    68  	CardCVCCheckUnavailable CardCVCCheck = "unavailable"
    69  	CardCVCCheckUnchecked   CardCVCCheck = "unchecked"
    70  )
    71  
    72  // Card funding type. Can be `credit`, `debit`, `prepaid`, or `unknown`.
    73  type CardFunding string
    74  
    75  // List of values that CardFunding can take
    76  const (
    77  	CardFundingCredit  CardFunding = "credit"
    78  	CardFundingDebit   CardFunding = "debit"
    79  	CardFundingPrepaid CardFunding = "prepaid"
    80  	CardFundingUnknown CardFunding = "unknown"
    81  )
    82  
    83  // If the card number is tokenized, this is the method that was used. Can be `android_pay` (includes Google Pay), `apple_pay`, `masterpass`, `visa_checkout`, or null.
    84  type CardTokenizationMethod string
    85  
    86  // List of values that CardTokenizationMethod can take
    87  const (
    88  	CardTokenizationMethodAndroidPay CardTokenizationMethod = "android_pay"
    89  	CardTokenizationMethodApplePay   CardTokenizationMethod = "apple_pay"
    90  )
    91  
    92  // cardSource is a string that's used to build card form parameters. It's a
    93  // constant just to make mistakes less likely.
    94  const cardSource = "source"
    95  
    96  // Delete a specified source for a given customer.
    97  type CardParams struct {
    98  	Params   `form:"*"`
    99  	Account  *string `form:"-"` // Included in URL
   100  	Token    *string `form:"-"` // Included in URL
   101  	Customer *string `form:"-"` // Included in URL
   102  	// The name of the person or business that owns the bank account.
   103  	AccountHolderName *string `form:"account_holder_name"`
   104  	// The type of entity that holds the account. This can be either `individual` or `company`.
   105  	AccountHolderType *string `form:"account_holder_type"`
   106  	// City/District/Suburb/Town/Village.
   107  	AddressCity *string `form:"address_city"`
   108  	// Billing address country, if provided when creating card.
   109  	AddressCountry *string `form:"address_country"`
   110  	// Address line 1 (Street address/PO Box/Company name).
   111  	AddressLine1 *string `form:"address_line1"`
   112  	// Address line 2 (Apartment/Suite/Unit/Building).
   113  	AddressLine2 *string `form:"address_line2"`
   114  	// State/County/Province/Region.
   115  	AddressState *string `form:"address_state"`
   116  	// ZIP or postal code.
   117  	AddressZip *string `form:"address_zip"`
   118  	// Required when adding a card to an account (not applicable to customers or recipients). The card (which must be a debit card) can be used as a transfer destination for funds in this currency.
   119  	Currency *string `form:"currency"`
   120  	// Card security code. Highly recommended to always include this value, but it's required only for accounts based in European countries.
   121  	CVC *string `form:"cvc"`
   122  	// Applicable only on accounts (not customers or recipients). If you set this to `true` (or if this is the first external account being added in this currency), this card will become the default external account for its currency.
   123  	DefaultForCurrency *bool `form:"default_for_currency"`
   124  	// Specifies which fields in the response should be expanded.
   125  	Expand []*string `form:"expand"`
   126  	// Two digit number representing the card's expiration month.
   127  	ExpMonth *string `form:"exp_month"`
   128  	// Four digit number representing the card's expiration year.
   129  	ExpYear *string `form:"exp_year"`
   130  	// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to `metadata`.
   131  	Metadata map[string]string `form:"metadata"`
   132  	// Cardholder name.
   133  	Name *string `form:"name"`
   134  	// The card number, as a string without any separators.
   135  	Number *string          `form:"number"`
   136  	Owner  *CardOwnerParams `form:"owner"`
   137  	// ID is used when tokenizing a card for shared customers
   138  	ID string `form:"*"`
   139  }
   140  
   141  // AppendToAsCardSourceOrExternalAccount appends the given CardParams as either a
   142  // card or external account.
   143  //
   144  // It may look like an AppendTo from the form package, but it's not, and is
   145  // only used in the special case where we use `card.New`. It's needed because
   146  // we have some weird encoding logic here that can't be handled by the form
   147  // package (and it's special enough that it wouldn't be desirable to have it do
   148  // so).
   149  //
   150  // This is not a pattern that we want to push forward, and this largely exists
   151  // because the cards endpoint is a little unusual. There is one other resource
   152  // like it, which is bank account.
   153  func (p *CardParams) AppendToAsCardSourceOrExternalAccount(body *form.Values, keyParts []string) {
   154  	// Rather than being called in addition to `AppendTo`, this function
   155  	// *replaces* `AppendTo`, so we must also make sure to handle the encoding
   156  	// of `Params` so metadata and the like is included in the encoded payload.
   157  	form.AppendToPrefixed(body, p.Params, keyParts)
   158  
   159  	if p.DefaultForCurrency != nil {
   160  		body.Add(
   161  			form.FormatKey(append(keyParts, "default_for_currency")),
   162  			strconv.FormatBool(BoolValue(p.DefaultForCurrency)),
   163  		)
   164  	}
   165  
   166  	if p.Token != nil {
   167  		if p.Account != nil {
   168  			body.Add(form.FormatKey(append(keyParts, "external_account")), StringValue(p.Token))
   169  		} else {
   170  			body.Add(form.FormatKey(append(keyParts, cardSource)), StringValue(p.Token))
   171  		}
   172  	}
   173  
   174  	if p.Number != nil {
   175  		body.Add(form.FormatKey(append(keyParts, cardSource, "object")), "card")
   176  		body.Add(form.FormatKey(append(keyParts, cardSource, "number")), StringValue(p.Number))
   177  	}
   178  	if p.CVC != nil {
   179  		body.Add(
   180  			form.FormatKey(append(keyParts, cardSource, "cvc")),
   181  			StringValue(p.CVC),
   182  		)
   183  	}
   184  	if p.Currency != nil {
   185  		body.Add(
   186  			form.FormatKey(append(keyParts, cardSource, "currency")),
   187  			StringValue(p.Currency),
   188  		)
   189  	}
   190  	if p.ExpMonth != nil {
   191  		body.Add(
   192  			form.FormatKey(append(keyParts, cardSource, "exp_month")),
   193  			StringValue(p.ExpMonth),
   194  		)
   195  	}
   196  	if p.ExpYear != nil {
   197  		body.Add(
   198  			form.FormatKey(append(keyParts, cardSource, "exp_year")),
   199  			StringValue(p.ExpYear),
   200  		)
   201  	}
   202  	if p.Name != nil {
   203  		body.Add(
   204  			form.FormatKey(append(keyParts, cardSource, "name")),
   205  			StringValue(p.Name),
   206  		)
   207  	}
   208  	if p.AddressCity != nil {
   209  		body.Add(
   210  			form.FormatKey(append(keyParts, cardSource, "address_city")),
   211  			StringValue(p.AddressCity),
   212  		)
   213  	}
   214  	if p.AddressCountry != nil {
   215  		body.Add(
   216  			form.FormatKey(append(keyParts, cardSource, "address_country")),
   217  			StringValue(p.AddressCountry),
   218  		)
   219  	}
   220  	if p.AddressLine1 != nil {
   221  		body.Add(
   222  			form.FormatKey(append(keyParts, cardSource, "address_line1")),
   223  			StringValue(p.AddressLine1),
   224  		)
   225  	}
   226  	if p.AddressLine2 != nil {
   227  		body.Add(
   228  			form.FormatKey(append(keyParts, cardSource, "address_line2")),
   229  			StringValue(p.AddressLine2),
   230  		)
   231  	}
   232  	if p.AddressState != nil {
   233  		body.Add(
   234  			form.FormatKey(append(keyParts, cardSource, "address_state")),
   235  			StringValue(p.AddressState),
   236  		)
   237  	}
   238  	if p.AddressZip != nil {
   239  		body.Add(
   240  			form.FormatKey(append(keyParts, cardSource, "address_zip")),
   241  			StringValue(p.AddressZip),
   242  		)
   243  	}
   244  }
   245  
   246  // AddExpand appends a new field to expand.
   247  func (p *CardParams) AddExpand(f string) {
   248  	p.Expand = append(p.Expand, &f)
   249  }
   250  
   251  // AddMetadata adds a new key-value pair to the Metadata.
   252  func (p *CardParams) AddMetadata(key string, value string) {
   253  	if p.Metadata == nil {
   254  		p.Metadata = make(map[string]string)
   255  	}
   256  
   257  	p.Metadata[key] = value
   258  }
   259  
   260  type CardOwnerParams struct {
   261  	// Owner's address.
   262  	Address *AddressParams `form:"address"`
   263  	// Owner's email address.
   264  	Email *string `form:"email"`
   265  	// Owner's full name.
   266  	Name *string `form:"name"`
   267  	// Owner's phone number.
   268  	Phone *string `form:"phone"`
   269  }
   270  type CardListParams struct {
   271  	ListParams `form:"*"`
   272  	Account    *string `form:"-"` // Included in URL
   273  	Customer   *string `form:"-"` // Included in URL
   274  }
   275  
   276  // AppendTo implements custom encoding logic for CardListParams
   277  // so that we can send the special required `object` field up along with the
   278  // other specified parameters.
   279  func (p *CardListParams) AppendTo(body *form.Values, keyParts []string) {
   280  	if p.Account != nil || p.Customer != nil {
   281  		body.Add(form.FormatKey(append(keyParts, "object")), "card")
   282  	}
   283  }
   284  
   285  type CardNetworks struct {
   286  	// The preferred network for co-branded cards. Can be `cartes_bancaires`, `mastercard`, `visa` or `invalid_preference` if requested network is not valid for the card.
   287  	Preferred string `json:"preferred"`
   288  }
   289  
   290  // You can store multiple cards on a customer in order to charge the customer
   291  // later. You can also store multiple debit cards on a recipient in order to
   292  // transfer to those cards later.
   293  //
   294  // Related guide: [Card payments with Sources](https://stripe.com/docs/sources/cards)
   295  type Card struct {
   296  	APIResource
   297  	// The account this card belongs to. This attribute will not be in the card object if the card belongs to a customer or recipient instead.
   298  	Account *Account `json:"account"`
   299  	// City/District/Suburb/Town/Village.
   300  	AddressCity string `json:"address_city"`
   301  	// Billing address country, if provided when creating card.
   302  	AddressCountry string `json:"address_country"`
   303  	// Address line 1 (Street address/PO Box/Company name).
   304  	AddressLine1 string `json:"address_line1"`
   305  	// If `address_line1` was provided, results of the check: `pass`, `fail`, `unavailable`, or `unchecked`.
   306  	AddressLine1Check CardAddressLine1Check `json:"address_line1_check"`
   307  	// Address line 2 (Apartment/Suite/Unit/Building).
   308  	AddressLine2 string `json:"address_line2"`
   309  	// State/County/Province/Region.
   310  	AddressState string `json:"address_state"`
   311  	// ZIP or postal code.
   312  	AddressZip string `json:"address_zip"`
   313  	// If `address_zip` was provided, results of the check: `pass`, `fail`, `unavailable`, or `unchecked`.
   314  	AddressZipCheck CardAddressZipCheck `json:"address_zip_check"`
   315  	// A set of available payout methods for this card. Only values from this set should be passed as the `method` when creating a payout.
   316  	AvailablePayoutMethods []CardAvailablePayoutMethod `json:"available_payout_methods"`
   317  	// Card brand. Can be `American Express`, `Diners Club`, `Discover`, `Eftpos Australia`, `JCB`, `MasterCard`, `UnionPay`, `Visa`, or `Unknown`.
   318  	Brand CardBrand `json:"brand"`
   319  	// Two-letter ISO code representing the country of the card. You could use this attribute to get a sense of the international breakdown of cards you've collected.
   320  	Country string `json:"country"`
   321  	// Three-letter [ISO code for currency](https://stripe.com/docs/payouts). Only applicable on accounts (not customers or recipients). The card can be used as a transfer destination for funds in this currency.
   322  	Currency Currency `json:"currency"`
   323  	// The customer that this card belongs to. This attribute will not be in the card object if the card belongs to an account or recipient instead.
   324  	Customer *Customer `json:"customer"`
   325  	// If a CVC was provided, results of the check: `pass`, `fail`, `unavailable`, or `unchecked`. A result of unchecked indicates that CVC was provided but hasn't been checked yet. Checks are typically performed when attaching a card to a Customer object, or when creating a charge. For more details, see [Check if a card is valid without a charge](https://support.stripe.com/questions/check-if-a-card-is-valid-without-a-charge).
   326  	CVCCheck CardCVCCheck `json:"cvc_check"`
   327  	// Whether this card is the default external account for its currency.
   328  	DefaultForCurrency bool `json:"default_for_currency"`
   329  	Deleted            bool `json:"deleted"`
   330  	// Description is a succinct summary of the card's information.
   331  	//
   332  	// Please note that this field is for internal use only and is not returned
   333  	// as part of standard API requests.
   334  	// A high-level description of the type of cards issued in this range. (For internal use only and not typically available in standard API requests.)
   335  	Description string `json:"description"`
   336  	// (For tokenized numbers only.) The last four digits of the device account number.
   337  	DynamicLast4 string `json:"dynamic_last4"`
   338  	// Two-digit number representing the card's expiration month.
   339  	ExpMonth int64 `json:"exp_month"`
   340  	// Four-digit number representing the card's expiration year.
   341  	ExpYear int64 `json:"exp_year"`
   342  	// Uniquely identifies this particular card number. You can use this attribute to check whether two customers who've signed up with you are using the same card number, for example. For payment methods that tokenize card information (Apple Pay, Google Pay), the tokenized number might be provided instead of the underlying card number.
   343  	//
   344  	// *As of May 1, 2021, card fingerprint in India for Connect changed to allow two fingerprints for the same card---one for India and one for the rest of the world.*
   345  	Fingerprint string `json:"fingerprint"`
   346  	// Card funding type. Can be `credit`, `debit`, `prepaid`, or `unknown`.
   347  	Funding CardFunding `json:"funding"`
   348  	// Unique identifier for the object.
   349  	ID string `json:"id"`
   350  	// IIN is the card's "Issuer Identification Number".
   351  	//
   352  	// Please note that this field is for internal use only and is not returned
   353  	// as part of standard API requests.
   354  	// Issuer identification number of the card. (For internal use only and not typically available in standard API requests.)
   355  	IIN string `json:"iin"`
   356  	// Issuer is a bank or financial institution that provides the card.
   357  	//
   358  	// Please note that this field is for internal use only and is not returned
   359  	// as part of standard API requests.
   360  	// The name of the card's issuing bank. (For internal use only and not typically available in standard API requests.)
   361  	Issuer string `json:"issuer"`
   362  	// The last four digits of the card.
   363  	Last4 string `json:"last4"`
   364  	// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
   365  	Metadata map[string]string `json:"metadata"`
   366  	// Cardholder name.
   367  	Name     string        `json:"name"`
   368  	Networks *CardNetworks `json:"networks"`
   369  	// String representing the object's type. Objects of the same type share the same value.
   370  	Object string `json:"object"`
   371  	// For external accounts that are cards, possible values are `new` and `errored`. If a payout fails, the status is set to `errored` and [scheduled payouts](https://stripe.com/docs/payouts#payout-schedule) are stopped until account details are updated.
   372  	Status string `json:"status"`
   373  	// If the card number is tokenized, this is the method that was used. Can be `android_pay` (includes Google Pay), `apple_pay`, `masterpass`, `visa_checkout`, or null.
   374  	TokenizationMethod CardTokenizationMethod `json:"tokenization_method"`
   375  }
   376  
   377  // CardList is a list of Cards as retrieved from a list endpoint.
   378  type CardList struct {
   379  	APIResource
   380  	ListMeta
   381  	Data []*Card `json:"data"`
   382  }
   383  
   384  // UnmarshalJSON handles deserialization of a Card.
   385  // This custom unmarshaling is needed because the resulting
   386  // property may be an id or the full struct if it was expanded.
   387  func (c *Card) UnmarshalJSON(data []byte) error {
   388  	if id, ok := ParseID(data); ok {
   389  		c.ID = id
   390  		return nil
   391  	}
   392  
   393  	type card Card
   394  	var v card
   395  	if err := json.Unmarshal(data, &v); err != nil {
   396  		return err
   397  	}
   398  
   399  	*c = Card(v)
   400  	return nil
   401  }