-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPayPal.ts
74 lines (54 loc) · 1.74 KB
/
PayPal.ts
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {PayPalRequest} from "./PayPalRequest";
import {PayPalEnvironment} from './models';
export class PayPal {
constructor(protected conf: PayPalEnvironment) {
}
api(api: string) {
return new PayPalRequest(this.conf, api);
}
products(id?: string) {
return this.api(this.getApiUrl('/catalogs/products', id));
}
plans(id?: string) {
return new PayPalPlanRequest(this.conf, this.getApiUrl('/billing/plans', id))
}
subscriptions(id?: string) {
return new PayPalSubscriptionRequest(this.conf, this.getApiUrl('/billing/subscriptions', id));
}
protected getApiUrl(api: string, optPath?: string) {
return optPath ? `${api}/${optPath}` : api;
}
}
export class PayPalPlanRequest extends PayPalRequest {
constructor(protected conf: PayPalEnvironment, protected url: string) {
super(conf, url);
}
activate() {
return this.appendUrl('/activate');
}
deactivate() {
return this.appendUrl('/deactivate');
}
updatePricingSchemes() {
return this.appendUrl('/update-pricing-schemes');
}
}
export class PayPalSubscriptionRequest extends PayPalRequest {
constructor(protected conf: PayPalEnvironment, protected url: string) {
super(conf, url);
}
activate() {
return this.appendUrl('/activate');
}
cancel() {
return this.appendUrl('/cancel');
}
suspend() {
return this.appendUrl('/suspend');
}
// You can upgrade or downgrade a subscription by changing the plan and/or quantity of the subscription.
// Changing from one plan to another is allowed only across plans within the same product.
revise() {
return this.appendUrl('/revise');
}
}