PaperTiger.TestTokens (PaperTiger v1.1.2)

Copy Markdown View Source

Pre-defined Stripe test tokens that are always available in PaperTiger.

Stripe provides special test tokens like pm_card_visa and tok_visa that work without creating payment methods from card details. PaperTiger must provide these same tokens so that library users don't have to change their code when switching between real Stripe and PaperTiger.

Supported Payment Method Tokens (pmcard*)

By Card Brand

  • pm_card_visa - Visa (4242424242424242)
  • pm_card_visa_debit - Visa Debit
  • pm_card_mastercard - Mastercard (5555555555554444)
  • pm_card_mastercard_debit - Mastercard Debit
  • pm_card_mastercard_prepaid - Mastercard Prepaid
  • pm_card_amex - American Express (378282246310005)
  • pm_card_discover - Discover (6011111111111117)
  • pm_card_diners - Diners Club (3056930009020004)
  • pm_card_jcb - JCB (3566002020360505)
  • pm_card_unionpay - UnionPay (6200000000000005)

Special Behavior Cards

  • pm_card_chargeDeclined - Always declines
  • pm_card_chargeDeclinedInsufficientFunds - Declines with insufficient funds
  • pm_card_chargeDeclinedFraudulent - Declines as fraudulent

Supported Token Tokens (tok_*)

  • tok_visa, tok_mastercard, tok_amex, etc. (same brands as pmcard*)

Usage

These tokens are automatically loaded when PaperTiger starts.

Summary

Functions

Loads all pre-defined test tokens into PaperTiger stores.

Materializes a fresh PaymentMethod from a predefined pm_card_* test token.

Returns a list of all supported pmcard* token IDs.

Returns true when the given ID is one of Stripe's predefined pm_card_* test payment method tokens.

Returns a list of all supported tok_* token IDs.

Functions

load()

@spec load() :: {:ok, map()}

Loads all pre-defined test tokens into PaperTiger stores.

Called automatically on PaperTiger startup. Returns {:ok, stats} with counts of loaded tokens.

materialize_payment_method(id, attrs \\ %{})

@spec materialize_payment_method(String.t(), map()) ::
  {:ok, map()} | {:error, :not_found}

Materializes a fresh PaymentMethod from a predefined pm_card_* test token.

Stripe treats these fixtures as reusable tokens in attach/setup flows: each use yields an ordinary PaymentMethod instance that can be attached to one customer without consuming the named fixture globally.

payment_method_ids()

@spec payment_method_ids() :: [String.t()]

Returns a list of all supported pmcard* token IDs.

test_payment_method_id?(id)

@spec test_payment_method_id?(term()) :: boolean()

Returns true when the given ID is one of Stripe's predefined pm_card_* test payment method tokens.

token_ids()

@spec token_ids() :: [String.t()]

Returns a list of all supported tok_* token IDs.