Skip to content

Commit

Permalink
feat: add endpoints about ThreeDSecureRequest object.
Browse files Browse the repository at this point in the history
  • Loading branch information
nonz250 committed Nov 11, 2024
1 parent d8274c0 commit 659dc8d
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check warning on line 16 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (14)

ES2015 module syntax is preferred over namespaces

Check warning on line 16 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (16)

ES2015 module syntax is preferred over namespaces

Check warning on line 16 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (18)

ES2015 module syntax is preferred over namespaces

Check warning on line 16 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (20)

ES2015 module syntax is preferred over namespaces
export interface PayjpStatic {
Expand All @@ -33,6 +34,7 @@ namespace Payjp {
statements: Statements,
terms: Terms,
balances: Balances,
three_d_secure_requests: ThreeDSecureRequests,
}

export interface PayjpOptions {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
};
}

Expand Down
24 changes: 24 additions & 0 deletions src/threeDSecureRequest.ts
Original file line number Diff line number Diff line change
@@ -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<I.List<I.ThreeDSecureRequest>> {
return this.request('GET', this.resource, query);
}

create(query: I.ThreeDSecureRequestCreationOptions): Promise<I.ThreeDSecureRequest> {
return this.request('POST', this.resource, query);
}

retrieve(id: string): Promise<I.ThreeDSecureRequest> {
return this.request('GET', `${this.resource}/${id}`);
}

}
39 changes: 39 additions & 0 deletions test/threeDSecureRequest.spec.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
});

});

0 comments on commit 659dc8d

Please sign in to comment.