1
1
'use strict'
2
2
3
- const SANDBOX_BASE_URL = 'https://sandbox-vendors.paddle.com/api/'
4
- const BASE_URL = 'https://vendors.paddle.com/api/'
3
+ const VENDORS_SANDBOX_BASE_URL = 'https://sandbox-vendors.paddle.com/api/'
4
+ const VENDORS_BASE_URL = 'https://vendors.paddle.com/api/'
5
5
6
- const VERSION_1 = 1.0
7
- const VERSION_2 = 2.0
6
+ const CHECKOUT_SANDBOX_BASE_URL = 'https://sandbox-checkout.paddle.com/api/'
7
+ const CHECKOUT_BASE_URL = 'https://checkout.paddle.com/api/'
8
+
9
+ const VERSION_1 = '1.0'
10
+ const VERSION_2 = '2.0'
8
11
9
12
const PATH_CANCEL_SUBSCRIPTION = `${ VERSION_2 } /subscription/users_cancel`
10
13
const PATH_LIST_USERS = `${ VERSION_2 } /subscription/users`
@@ -21,14 +24,13 @@ module.exports = class {
21
24
} = { } ) {
22
25
this . _vendorId = vendorId
23
26
this . _authCode = authCode
27
+ this . _vendorsBaseUrl = useSandbox ? VENDORS_SANDBOX_BASE_URL : VENDORS_BASE_URL
24
28
this . _baseUrl = useSandbox ? SANDBOX_BASE_URL : BASE_URL
25
29
}
26
30
27
31
async init ( { connectTimeout = 5_000 , readTimeout = 20_000 , retries = 0 } = { } ) {
28
32
if ( ! this . _got ) {
29
33
this . _got = ( await import ( 'got' ) ) . default . extend ( {
30
- prefixUrl : this . _baseUrl ,
31
- method : 'POST' ,
32
34
retry : {
33
35
limit : retries
34
36
} ,
@@ -55,7 +57,7 @@ module.exports = class {
55
57
* @returns
56
58
*/
57
59
async refundFullPayment ( { order_id } ) {
58
- return this . _returnResponseIf200 ( this . _request ( PATH_LIST_USERS , {
60
+ return this . _returnResponseIf200 ( this . _request ( this . _vendorsBaseUrl + PATH_LIST_USERS , {
59
61
form : {
60
62
vendor_id : this . _vendorId ,
61
63
vendor_auth_code : this . _authCode ,
@@ -83,7 +85,7 @@ module.exports = class {
83
85
if ( perPage ) {
84
86
form . results_per_page = perPage
85
87
}
86
- return this . _returnResponseIf200 ( this . _request ( PATH_LIST_USERS , {
88
+ return this . _returnResponseIf200 ( this . _request ( this . _vendorsBaseUrl + PATH_LIST_USERS , {
87
89
form
88
90
} ) )
89
91
}
@@ -100,13 +102,13 @@ module.exports = class {
100
102
subscription_id
101
103
}
102
104
103
- return this . _returnResponseIf200 ( this . _request ( PATH_LIST_USERS , {
105
+ return this . _returnResponseIf200 ( this . _request ( this . _vendorsBaseUrl + PATH_LIST_USERS , {
104
106
form
105
107
} ) )
106
108
. catch ( ( e ) => {
107
109
if ( e . message . includes ( '119' ) ) {
108
110
form . state = 'deleted'
109
- return this . _returnResponseIf200 ( this . _request ( PATH_LIST_USERS , {
111
+ return this . _returnResponseIf200 ( this . _request ( this . _vendorsBaseUrl + PATH_LIST_USERS , {
110
112
form
111
113
} ) )
112
114
} else {
@@ -155,7 +157,7 @@ module.exports = class {
155
157
if ( plan ) {
156
158
form . plan = plan
157
159
}
158
- return this . _returnResponseIf200 ( this . _request ( PATH_LIST_PLANS , {
160
+ return this . _returnResponseIf200 ( this . _request ( this . _vendorsBaseUrl + PATH_LIST_PLANS , {
159
161
form
160
162
} ) )
161
163
}
@@ -165,7 +167,7 @@ module.exports = class {
165
167
* @returns
166
168
*/
167
169
async listProducts ( ) {
168
- return this . _returnResponseIf200 ( this . _request ( PATH_LIST_PRODUCTS , {
170
+ return this . _returnResponseIf200 ( this . _request ( this . _vendorsBaseUrl + PATH_LIST_PRODUCTS , {
169
171
form : {
170
172
vendor_id : this . _vendorId ,
171
173
vendor_auth_code : this . _authCode
@@ -180,7 +182,7 @@ module.exports = class {
180
182
* @returns
181
183
*/
182
184
async updateSubscriptionPlan ( { subscription_id } , planId ) {
183
- return this . _returnResponseIf200 ( this . _request ( PATH_UPDATE_USERS , {
185
+ return this . _returnResponseIf200 ( this . _request ( this . _vendorsBaseUrl + PATH_UPDATE_USERS , {
184
186
form : {
185
187
vendor_id : this . _vendorId ,
186
188
vendor_auth_code : this . _authCode ,
@@ -199,7 +201,7 @@ module.exports = class {
199
201
* @returns
200
202
*/
201
203
async updatePostcode ( { subscription_id } , postcode ) {
202
- return this . _returnResponseIf200 ( this . _request ( this . _baseUrl , {
204
+ return this . _returnResponseIf200 ( this . _request ( this . _vendorsBaseUrl + this . _vendorsBaseUrl , {
203
205
form : {
204
206
vendor_id : this . _vendorId ,
205
207
vendor_auth_code : this . _authCode ,
@@ -215,7 +217,7 @@ module.exports = class {
215
217
* @returns
216
218
*/
217
219
async cancelSubscription ( { subscription_id } ) {
218
- return this . _returnResponseIf200 ( this . _request ( PATH_CANCEL_SUBSCRIPTION , {
220
+ return this . _returnResponseIf200 ( this . _request ( this . _vendorsBaseUrl + PATH_CANCEL_SUBSCRIPTION , {
219
221
form : {
220
222
vendor_id : this . _vendorId ,
221
223
vendor_auth_code : this . _authCode ,
0 commit comments