-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add 3DS session support and update to cards endpoint
Includes card changes to use `multi_use` and new endpoint with /payments prefix. Add support for Create a 3DS session. BREAKING CHANGE: requireda`multi_use` field when creating a card
- Loading branch information
Showing
9 changed files
with
128 additions
and
5 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
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
File renamed without changes.
34 changes: 34 additions & 0 deletions
34
src/Payments/ThreeDSecureSessions/ThreeDSecureSessions.spec.ts
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,34 @@ | ||
import nock from 'nock' | ||
import { Duffel } from '../../index' | ||
|
||
const duffel = new Duffel({ token: 'mockToken' }) | ||
describe('ThreeDSecureSessions', () => { | ||
afterEach(() => { | ||
nock.cleanAll() | ||
}) | ||
|
||
it('should create a 3DS session record when `create` is called', async () => { | ||
const MOCK_ID = '3ds_00009hthhsUZ8W4LxQgkjb' | ||
nock(/(.*)/) | ||
.post('/payments/three_d_secure_sessions') | ||
.reply(200, { | ||
data: { | ||
id: MOCK_ID, | ||
liveMode: false, | ||
expiresAt: '2024-01-01T00:00:00', | ||
status: 'ready_for_payment', | ||
resourceId: 'off_00009hthhsUZ8W4LxQgkjb', | ||
clientId: 'tds_57aa862f8bf7', | ||
cardId: 'tcd_00009hthhsUZ8W4LxQgkjb', | ||
}, | ||
}) | ||
|
||
const response = await duffel.three_d_secure_sessions.create({ | ||
resource_id: 'off_00009hthhsUZ8W4LxQgkjb', | ||
card_id: 'tcd_00009hthhsUZ8W4LxQgkjb', | ||
services: [{ quantity: 1, id: 'ser_00009UhD4ongolulWd9123' }], | ||
exception: 'secure_corporate_payment', | ||
}) | ||
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,65 @@ | ||
import { Resource } from '../../Resource' | ||
import { DuffelResponse } from '../../types' | ||
|
||
interface Service { | ||
/** | ||
* The quantity of the service ID to pay for | ||
*/ | ||
quantity: number | ||
/** | ||
* The ID of the service to pay for | ||
*/ | ||
id: string | ||
} | ||
|
||
interface ThreeDSecureSessionParameters { | ||
/** | ||
* The offer ID, order ID, order change ID or quote ID intended to pay | ||
*/ | ||
resource_id: string | ||
|
||
/** | ||
* The services inteded to pay | ||
*/ | ||
services: Service[] | ||
|
||
/** | ||
* The card ID | ||
*/ | ||
card_id: string | ||
|
||
/** | ||
* The exception name for the 3DS session | ||
*/ | ||
exception: string | ||
} | ||
|
||
interface ThreeDSecureSessionRecord { | ||
id: string | ||
resource_id: string | ||
card_id: string | ||
live_mode: boolean | ||
expires_at: string | ||
status: string | ||
client_id: string | ||
} | ||
|
||
export class ThreeDSecureSessions extends Resource { | ||
/** | ||
* Endpoint path | ||
*/ | ||
path: string | ||
|
||
constructor(args: any) { | ||
super(args) | ||
this.path = 'payments/three_d_secure_sessions' | ||
} | ||
|
||
/** | ||
* Create a Duffel ThreeDSecureSession record | ||
*/ | ||
public create = async ( | ||
data: ThreeDSecureSessionParameters, | ||
): Promise<DuffelResponse<ThreeDSecureSessionRecord>> => | ||
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 './ThreeDSecureSessions' |
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,2 @@ | ||
export * from './Cards' | ||
export * from './ThreeDSecureSessions' |
This file was deleted.
Oops, something went wrong.
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