-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cards tokenisation endpoint
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import nock from 'nock' | ||
import { Duffel } from '../../index' | ||
|
||
const duffel = new Duffel({ token: 'mockToken' }) | ||
describe('Cards', () => { | ||
afterEach(() => { | ||
nock.cleanAll() | ||
}) | ||
|
||
it('should create a card record when `create` is called', async () => { | ||
const MOCK_ID = 'tcd_00009hthhsUZ8W4LxQgkjb' | ||
nock(/(.*)/) | ||
.post('/vault/cards') | ||
.reply(200, { data: { id: MOCK_ID, liveMode: false } }) | ||
|
||
const response = await duffel.cards.create({ | ||
address_city: 'London', | ||
address_country_code: 'GB', | ||
address_line_1: '1 Downing St', | ||
address_postal_code: 'EC2A 4RQ', | ||
address_region: 'London', | ||
brand: 'visa', | ||
expiry_month: '03', | ||
expiry_year: '30', | ||
name: 'Neil Armstrong', | ||
number: '4242424242424242', | ||
cvc: '123', | ||
}) | ||
expect(response.data.id).toBe(MOCK_ID) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Client } from '../../Client' | ||
import { Resource } from '../../Resource' | ||
import { DuffelResponse } from '../../types' | ||
|
||
export type CardBrand = | ||
| 'visa' | ||
| 'mastercard' | ||
| 'uatp' | ||
| 'american_express' | ||
| 'diners_club' | ||
| 'jcb' | ||
|
||
interface CardParameters { | ||
/** | ||
* The first line of the card owner's address | ||
*/ | ||
address_line_1: string | ||
|
||
/** | ||
* The card owner's postal code (or zip code) | ||
*/ | ||
address_postal_code: string | ||
/** | ||
* The card owner's city | ||
*/ | ||
address_city: string | ||
/** | ||
* The card owner's region or state | ||
*/ | ||
address_region: string | ||
/** | ||
* The ISO 3166-1 alpha-2 code for the card owner's country | ||
*/ | ||
address_country_code: string | ||
/** | ||
* The brand or the type of the card | ||
*/ | ||
brand: CardBrand | ||
/** | ||
* The month that the card expires in as a two-digit string, e.g. "01" | ||
*/ | ||
expiry_month: string | ||
/** | ||
* The year that the card expires in as a two-digit string, e.g. "28" | ||
*/ | ||
expiry_year: string | ||
/** | ||
* The card owner's name | ||
*/ | ||
name: string | ||
/** | ||
* The card number | ||
*/ | ||
number: string | ||
/** | ||
* The card verification code | ||
*/ | ||
cvc: string | ||
} | ||
|
||
interface CardRecord { | ||
id: string | ||
live_mode: boolean | ||
} | ||
|
||
export class Cards extends Resource { | ||
/** | ||
* Endpoint path | ||
*/ | ||
path: string | ||
|
||
// basePath must be 'https://api.duffel.cards' | ||
constructor(client: Client) { | ||
super(client) | ||
this.path = 'vault/cards' | ||
} | ||
|
||
/** | ||
* Create a Duffel card record | ||
*/ | ||
public create = async ( | ||
data: CardParameters, | ||
): Promise<DuffelResponse<CardRecord>> => | ||
this.request({ method: 'POST', path: this.path, data }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Cards' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Cards' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters