|
| 1 | +import { Client } from '../../Client' |
| 2 | +import { Resource } from '../../Resource' |
| 3 | +import { DuffelResponse } from '../../types' |
| 4 | + |
| 5 | +export type CardBrand = |
| 6 | + | 'visa' |
| 7 | + | 'mastercard' |
| 8 | + | 'uatp' |
| 9 | + | 'american_express' |
| 10 | + | 'diners_club' |
| 11 | + | 'jcb' |
| 12 | + |
| 13 | +interface CardParameters { |
| 14 | + /** |
| 15 | + * The first line of the card owner's address |
| 16 | + */ |
| 17 | + address_line_1: string |
| 18 | + |
| 19 | + /** |
| 20 | + * The card owner's postal code (or zip code) |
| 21 | + */ |
| 22 | + address_postal_code: string |
| 23 | + /** |
| 24 | + * The card owner's city |
| 25 | + */ |
| 26 | + address_city: string |
| 27 | + /** |
| 28 | + * The card owner's region or state |
| 29 | + */ |
| 30 | + address_region: string |
| 31 | + /** |
| 32 | + * The ISO 3166-1 alpha-2 code for the card owner's country |
| 33 | + */ |
| 34 | + address_country_code: string |
| 35 | + /** |
| 36 | + * The brand or the type of the card |
| 37 | + */ |
| 38 | + brand: CardBrand |
| 39 | + /** |
| 40 | + * The month that the card expires in as a two-digit string, e.g. "01" |
| 41 | + */ |
| 42 | + expiry_month: string |
| 43 | + /** |
| 44 | + * The year that the card expires in as a two-digit string, e.g. "28" |
| 45 | + */ |
| 46 | + expiry_year: string |
| 47 | + /** |
| 48 | + * The card owner's name |
| 49 | + */ |
| 50 | + name: string |
| 51 | + /** |
| 52 | + * The card number |
| 53 | + */ |
| 54 | + number: string |
| 55 | + /** |
| 56 | + * The card verification code |
| 57 | + */ |
| 58 | + cvc: string |
| 59 | +} |
| 60 | + |
| 61 | +interface CardRecord { |
| 62 | + id: string |
| 63 | + live_mode: boolean |
| 64 | +} |
| 65 | + |
| 66 | +export class Cards extends Resource { |
| 67 | + /** |
| 68 | + * Endpoint path |
| 69 | + */ |
| 70 | + path: string |
| 71 | + |
| 72 | + // basePath must be 'https://api.duffel.cards' |
| 73 | + constructor(client: Client) { |
| 74 | + super(client) |
| 75 | + this.path = 'vault/cards' |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Create a Duffel card record |
| 80 | + */ |
| 81 | + public create = async ( |
| 82 | + data: CardParameters, |
| 83 | + ): Promise<DuffelResponse<CardRecord>> => |
| 84 | + this.request({ method: 'POST', path: this.path, data }) |
| 85 | +} |
0 commit comments