payjp 3.0.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -26,6 +26,13 @@ payjp.charges.create({
26
26
  currency: 'jpy',
27
27
  card: 'token_id_by_Checkout_or_payjp.js'
28
28
  }).then(console.log).catch(console.error);
29
+
30
+ payjp.charges.create({
31
+ amount: 1000,
32
+ currency: 'jpy',
33
+ customer: 'cus_xxx',
34
+ metadata: { user_id: 123 }
35
+ }).then(console.log).catch(console.error);
29
36
  ```
30
37
 
31
38
  Typescript
package/built/index.d.ts CHANGED
@@ -269,6 +269,7 @@ declare namespace Payjp {
269
269
  three_d_secure_status: ThreeDSecureStatus;
270
270
  email: string | null;
271
271
  phone: string | null;
272
+ is_jp: boolean;
272
273
  }
273
274
  export interface Plan {
274
275
  object: "plan";
@@ -10,6 +10,9 @@ export default class Resource {
10
10
  get apikey(): string;
11
11
  private buildHeader;
12
12
  private getCurrentDelay;
13
+ private isPlainObject;
14
+ private appendFormValue;
15
+ private serializeQuery;
13
16
  protected request<I>(method: string, endpoint: string, query?: object, headers?: object): Promise<I>;
14
17
  }
15
18
  export {};
package/built/resource.js CHANGED
@@ -26,6 +26,28 @@ class Resource {
26
26
  const delay = Math.min(initialDelay * 2 ** retryCount, maxDelay);
27
27
  return Math.ceil((delay / 2) * (1 + Math.random()));
28
28
  }
29
+ isPlainObject(value) {
30
+ return Object.prototype.toString.call(value) === "[object Object]";
31
+ }
32
+ appendFormValue(params, key, value) {
33
+ if (value === undefined) {
34
+ return;
35
+ }
36
+ if (this.isPlainObject(value)) {
37
+ for (const [nestedKey, nestedValue] of Object.entries(value)) {
38
+ this.appendFormValue(params, `${key}[${nestedKey}]`, nestedValue);
39
+ }
40
+ return;
41
+ }
42
+ params.append(key, String(value));
43
+ }
44
+ serializeQuery(query) {
45
+ const params = new URLSearchParams();
46
+ for (const [key, value] of Object.entries(query)) {
47
+ this.appendFormValue(params, key, value);
48
+ }
49
+ return params;
50
+ }
29
51
  request(method, endpoint, query = {}, headers = {}) {
30
52
  const header = Object.assign(this.buildHeader(method), headers);
31
53
  const doRequest = async () => {
@@ -37,7 +59,7 @@ class Resource {
37
59
  // Set query parameters or request body
38
60
  if (method === "GET" || method === "DELETE") {
39
61
  // For GET and DELETE, add query parameters to URL
40
- const params = new URLSearchParams(query);
62
+ const params = this.serializeQuery(query);
41
63
  const queryString = params.toString();
42
64
  if (queryString) {
43
65
  url = `${url}?${queryString}`;
@@ -45,7 +67,7 @@ class Resource {
45
67
  }
46
68
  else {
47
69
  // For POST and PUT, send as request body
48
- const body = new URLSearchParams(query);
70
+ const body = this.serializeQuery(query);
49
71
  fetchOptions.body = body.toString();
50
72
  }
51
73
  // Set timeout
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payjp",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "description": "PAY.JP node.js bindings",
5
5
  "main": "built/index.js",
6
6
  "types": "built/index.d.ts",