-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathStripeObject.js
More file actions
52 lines (44 loc) · 1.16 KB
/
Copy pathStripeObject.js
File metadata and controls
52 lines (44 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const stripeObjs = require("./stripeObjects.json");
class StripeObject {
constructor(type) {
const obj = stripeObjs.objects.find((o) => o.type === type);
if (!obj) {
throw new Error(
`Unknown type: ${type} passed to StripeObject. This type is not supported.`
);
}
this.id = obj.id;
this.product = obj.product;
this.name = obj.name;
this.type = obj.type;
this.description = obj.description;
this.canIterate = obj.canIterate;
this.methodName = obj.methodName;
this.methodArgs = obj.methodArgs;
}
objectPath(stripe) {
let path = null;
if (this.product) {
path = stripe[this.product][this.name];
} else {
path = stripe[this.name];
}
return path;
}
node(createContentDigest, payload) {
const node = {
...payload,
id: payload.id || `Stripe${this.type}${this.id}`,
parent: null,
children: [],
internal: {
type: `Stripe${this.type}`,
content: JSON.stringify(payload),
contentDigest: createContentDigest(payload),
description: this.description,
},
};
return node;
}
}
module.exports = StripeObject;