From 659dc8d58e9503cb4f822779419af4d93f45b6b9 Mon Sep 17 00:00:00 2001 From: nonz250 Date: Mon, 11 Nov 2024 16:20:35 +0900 Subject: [PATCH] feat: add endpoints about ThreeDSecureRequest object. --- src/index.ts | 28 +++++++++++++++++++++++ src/threeDSecureRequest.ts | 24 ++++++++++++++++++++ test/threeDSecureRequest.spec.js | 39 ++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/threeDSecureRequest.ts create mode 100644 test/threeDSecureRequest.spec.js diff --git a/src/index.ts b/src/index.ts index 585024f..f6e150e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ import Transfers from './transfer'; import Statements from './statement'; import Terms from "./term"; import Balances from "./balance"; +import ThreeDSecureRequests from "./threeDSecureRequest"; namespace Payjp { export interface PayjpStatic { @@ -33,6 +34,7 @@ namespace Payjp { statements: Statements, terms: Terms, balances: Balances, + three_d_secure_requests: ThreeDSecureRequests, } export interface PayjpOptions { @@ -546,6 +548,31 @@ namespace Payjp { bank_info: null | BankInfo } + export interface ThreeDSecureRequest { + object: 'three_d_secure_request', + id: string, + resource_id: string, + livemode: boolean, + created: number, + state: 'created' | 'in_progress' | 'result_received' | 'finished', + started_at: null | number, + result_received_at: null | number, + finished_at: null | number, + expired_at: null | number, + tenant_id: null | string, + three_d_secure_status: ThreeDSecureStatus, + } + + export interface ThreeDSecureRequestCreationOptions { + resource_id: string, + tenant_id?: string, + } + + export interface ThreeDSecureRequestListOptions extends ListOptions { + resource_id?: string, + tenant_id?: string, + } + export interface Deleted { deleted: boolean, id: string, @@ -607,6 +634,7 @@ const Payjp: Payjp.PayjpStatic = function (apikey: string, options: Payjp.PayjpO statements: new Statements(payjpConfig), terms: new Terms(payjpConfig), balances: new Balances(payjpConfig), + three_d_secure_requests: new ThreeDSecureRequests(payjpConfig), }; } diff --git a/src/threeDSecureRequest.ts b/src/threeDSecureRequest.ts new file mode 100644 index 0000000..c745286 --- /dev/null +++ b/src/threeDSecureRequest.ts @@ -0,0 +1,24 @@ +import Resource from './resource'; +import * as I from './index'; + +export default class ThreeDSecureRequests extends Resource { + resource: string; + + constructor(payjp) { + super(payjp); + this.resource = 'three_d_secure_requests'; + } + + list(query: I.ThreeDSecureRequestListOptions = {}): Promise> { + return this.request('GET', this.resource, query); + } + + create(query: I.ThreeDSecureRequestCreationOptions): Promise { + return this.request('POST', this.resource, query); + } + + retrieve(id: string): Promise { + return this.request('GET', `${this.resource}/${id}`); + } + +} diff --git a/test/threeDSecureRequest.spec.js b/test/threeDSecureRequest.spec.js new file mode 100644 index 0000000..4cdaa95 --- /dev/null +++ b/test/threeDSecureRequest.spec.js @@ -0,0 +1,39 @@ +const assert = require('assert'); +const Payjp = require('../built'); +const config = require('./config'); + +const payjp = Payjp(config.apikey, config); +payjp.three_d_secure_requests.request = (...args) => Promise.resolve(args); + +describe('ThreeDSecureRequest Resource', () => { + describe('list', () => { + it('Sends the correct request', () => { + return payjp.three_d_secure_requests.list().then(([_method, _endpoint]) => { + assert(_method === 'GET'); + assert(_endpoint === 'three_d_secure_requests'); + }); + }); + }); + + describe('create', () => { + it('Sends the correct request', () => { + const query = { + resource_id: 'car_xxxxxxxxxxxxxxxxxxxxxxxxx' + }; + return payjp.three_d_secure_requests.create(query).then(([_method, _endpoint]) => { + assert(_method === 'POST'); + assert(_endpoint === 'three_d_secure_requests'); + }); + }); + }); + + describe('retrieve', () => { + it('Sends the correct request', () => { + return payjp.three_d_secure_requests.retrieve('id123').then(([_method, _endpoint]) => { + assert(_method === 'GET'); + assert(_endpoint === 'three_d_secure_requests/id123'); + }); + }); + }); + +});