|
2 | 2 | * Stripe-related business logic that works across React Native and Web |
3 | 3 | */ |
4 | 4 |
|
| 5 | +/** |
| 6 | + * Represents a Stripe card payment method |
| 7 | + */ |
5 | 8 | export interface StripeCard { |
| 9 | + /** Card brand (e.g., 'visa', 'mastercard', 'american express') */ |
6 | 10 | brand: string; |
| 11 | + /** Last 4 digits of the card number */ |
7 | 12 | last4?: string; |
| 13 | + /** Expiration month (1-12) */ |
8 | 14 | exp_month?: number; |
| 15 | + /** Expiration year (4 digits) */ |
9 | 16 | exp_year?: number; |
10 | 17 | } |
11 | 18 |
|
| 19 | +/** |
| 20 | + * Represents a Stripe US bank account payment method |
| 21 | + */ |
12 | 22 | export interface StripeUSBankAccount { |
| 23 | + /** Name of the bank */ |
13 | 24 | bank_name: string; |
| 25 | + /** Last 4 digits of the account number */ |
14 | 26 | last4: string; |
15 | 27 | } |
16 | 28 |
|
| 29 | +/** |
| 30 | + * Represents a Stripe payment method object as returned by the API |
| 31 | + */ |
17 | 32 | export interface StripePaymentMethod { |
18 | 33 | data: { |
| 34 | + /** Type of payment method */ |
19 | 35 | type: 'card' | 'us_bank_account'; |
| 36 | + /** Card details if type is 'card' */ |
20 | 37 | card?: StripeCard; |
| 38 | + /** US bank account details if type is 'us_bank_account' */ |
21 | 39 | us_bank_account?: StripeUSBankAccount; |
22 | 40 | }; |
23 | 41 | } |
24 | 42 |
|
| 43 | +/** |
| 44 | + * Represents a default payment method from Stripe customer invoice settings |
| 45 | + */ |
25 | 46 | export interface StripeDefaultPaymentMethod { |
| 47 | + /** Payment method ID */ |
26 | 48 | id: string; |
| 49 | + /** Type of payment method */ |
27 | 50 | type: 'card' | 'us_bank_account'; |
| 51 | + /** Stripe object type */ |
28 | 52 | object?: string; |
| 53 | + /** Card details if type is 'card' */ |
29 | 54 | card?: StripeCard; |
| 55 | + /** US bank account details if type is 'us_bank_account' */ |
30 | 56 | us_bank_account?: StripeUSBankAccount; |
31 | 57 | } |
32 | 58 |
|
| 59 | +/** |
| 60 | + * Represents a Stripe customer object as returned by the API |
| 61 | + */ |
33 | 62 | export interface StripeCustomer { |
34 | 63 | data: { |
| 64 | + /** Invoice settings containing default payment method */ |
35 | 65 | invoice_settings?: { |
| 66 | + /** Default payment method for invoices */ |
36 | 67 | default_payment_method?: StripeDefaultPaymentMethod; |
37 | 68 | }; |
| 69 | + /** Legacy card sources (deprecated in favor of payment methods) */ |
38 | 70 | sources?: { |
| 71 | + /** Array of card sources */ |
39 | 72 | data: Array<StripeCard & { id?: string; object?: string }>; |
40 | 73 | }; |
41 | 74 | }; |
42 | 75 | } |
43 | 76 |
|
| 77 | +/** |
| 78 | + * Normalized payment method object used internally in the application |
| 79 | + */ |
44 | 80 | export interface CustomerDefaultPaymentMethod { |
| 81 | + /** Whether this is a payment method (true) or legacy source (false) */ |
45 | 82 | isPaymentMethod: boolean; |
| 83 | + /** Formatted display label for the payment method */ |
46 | 84 | label: string; |
| 85 | + /** Last 4 digits of the card or account */ |
47 | 86 | last4: string; |
| 87 | + /** Expiration month (for cards only) */ |
48 | 88 | expMonth?: number; |
| 89 | + /** Expiration year (for cards only) */ |
49 | 90 | expYear?: number; |
| 91 | + /** Bank name (for US bank accounts only) */ |
50 | 92 | bankName?: string; |
| 93 | + /** Card brand (for cards only) */ |
51 | 94 | brand?: string; |
| 95 | + /** Payment method or source ID */ |
52 | 96 | id: string; |
| 97 | + /** Stripe object type */ |
53 | 98 | object: string; |
54 | 99 | } |
55 | 100 |
|
| 101 | +/** |
| 102 | + * Helper class containing Stripe-related business logic and formatting utilities |
| 103 | + */ |
56 | 104 | export class StripeHelpers { |
57 | 105 | /** |
58 | 106 | * Returns a formatted card brand label. Abbreviates "American Express" to "Amex". |
|
0 commit comments