Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add endpoints about ThreeDSecureRequest object. #63

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "payjp",
"version": "2.2.5",
"version": "2.3.0",
"description": "PAY.JP node.js bindings",
"main": "built/index.js",
"types": "built/index.d.ts",
Expand Down
32 changes: 31 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
import Statements from './statement';
import Terms from "./term";
import Balances from "./balance";
import ThreeDSecureRequests from "./threeDSecureRequest";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

クラス名に合わせてファイルもthreeDSecureRequests(末尾のsつける)がいいんじゃないですかね。
本来は他のリソースもそうすべきに見える

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

振る舞いに変更は無いので一旦このPRではこのままにしておきたいです。
別 PR で対処させてください。


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 {
(apikey: string, options?: PayjpOptions): Payjp;
}
Expand All @@ -33,6 +34,7 @@
statements: Statements,
terms: Terms,
balances: Balances,
three_d_secure_requests: ThreeDSecureRequests,
}

export interface PayjpOptions {
Expand Down Expand Up @@ -237,6 +239,8 @@
url: string
}

type ThreeDSecureStatus = null | 'unverified' | 'verified' | 'attempted' | 'failed' | 'error';

export interface Charge {
object: "charge",
amount: number,
Expand All @@ -263,8 +267,8 @@
platform_fee_rate?: string | null,
total_platform_fee?: number,
tenant?: string | null,
product?: any,

Check warning on line 270 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (14)

Unexpected any. Specify a different type

Check warning on line 270 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (16)

Unexpected any. Specify a different type

Check warning on line 270 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (18)

Unexpected any. Specify a different type

Check warning on line 270 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (20)

Unexpected any. Specify a different type
three_d_secure_status: string | null,
three_d_secure_status: ThreeDSecureStatus,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

three_d_secure_statusプロパティは現状chargeとcardにあります。cardも合わせてもらえますか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fbee108
card 付けるの忘れてました。ありがとうございます。
修正しました✍

term_id: string | null,
}

Expand Down Expand Up @@ -544,6 +548,31 @@
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 All @@ -563,11 +592,11 @@

export interface ResponseError {
status?: number | undefined,
response?: { body?: PayjpError, [propName: string]: any } | undefined,

Check warning on line 595 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (14)

Unexpected any. Specify a different type

Check warning on line 595 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (16)

Unexpected any. Specify a different type

Check warning on line 595 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (18)

Unexpected any. Specify a different type

Check warning on line 595 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (20)

Unexpected any. Specify a different type
message: string,
timeout?: number,

[propName: string]: any,

Check warning on line 599 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (14)

Unexpected any. Specify a different type

Check warning on line 599 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (16)

Unexpected any. Specify a different type

Check warning on line 599 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (18)

Unexpected any. Specify a different type

Check warning on line 599 in src/index.ts

View workflow job for this annotation

GitHub Actions / testing (20)

Unexpected any. Specify a different type
}
}

Expand Down Expand Up @@ -605,6 +634,7 @@
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]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queryのassertionも足したいですね

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

75a6974
追加しました✍

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');
});
});
});

});
Loading