Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

paddle-sdk

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paddle-sdk - npm Package Compare versions

Comparing version 2.5.1 to 3.0.0

4

package.json
{
"name": "paddle-sdk",
"description": "The Paddle.com Node.js SDK",
"version": "2.5.1",
"version": "3.0.0",
"main": "sdk.js",

@@ -21,3 +21,3 @@ "types": "sdk.d.ts",

"engines": {
"node": ">=10.0.0"
"node": ">=14.0.0"
},

@@ -24,0 +24,0 @@ "files": [

@@ -24,3 +24,6 @@ export = PaddleSDK;

publicKey: string;
server: string;
options: {
sandbox?: boolean;
server?: string;
};
/**

@@ -43,2 +46,8 @@ * Execute a HTTP request

/**
* Get the used server URL. Some of the requests go to Checkout server, while most will go to Vendor server.
*
* @private
*/
private _serverURL;
/**
* Get the list of required headers for an API request

@@ -87,2 +96,14 @@ *

/**
* Get the plan based on its ID
*
* @method
* @param {number} [planId]
* @returns {Promise}
* @fulfil {object} - The requested plan
*
* @example
* const plan = await client.getProductPlan(123);
*/
getProductPlan(planId?: number): Promise<any>;
/**
* Get the current list of all users or users for a subscription plan

@@ -206,2 +227,14 @@ *

/**
* Get subscription details
*
* @method
* @param {number} subscriptionID
* @returns {Promise}
* @fulfill {object} - Details of a single subscription
*
* @example
* const result = await client.getSubscriptionPlan(123);
*/
getSubscriptionPlan(subscriptionID: number): Promise<any>;
/**
* Update (upgrade/downgrade) the plan of a subscription

@@ -225,3 +258,3 @@ *

* @param {number} subscriptionID
* @param {Object} postData { quantity, price, planID, currency }
* @param {Object} postData { quantity, price, planID, currency, prorate, keepModifiers, billImmediately }
* @returns {Promise}

@@ -247,2 +280,18 @@ * @fulfill {object} - The result of the operation

/**
* Get the list of all users
*
* @method
* @param {Object} options { page, resultsPerPage, state, planId }
* @returns {Promise}
* @fulfil {object} - The users list
*
* @example
* const users = await client.getUsers();
* const users = await client.getUsers({ state: 'active' });
*
* @note
* If you have a large amount of active users, you will need to create paginated calls to this function.
*/
getUsers(options?: any): Promise<any>;
/**
* Generate a custom pay link

@@ -266,2 +315,14 @@ *

generatePayLink(body: any): Promise<any>;
/**
* Get details of Checkout Order
*
* @method
* @param {string} ID of the Checkout order
* @returns {Promise}
* @fulfil {object} - Details of the Checkout order
*
* @example
* const result = await client.getOrderDetails('219233-chre53d41f940e0-58aqh94971');
*/
getOrderDetails(checkoutId: any): Promise<any>;
}

@@ -7,5 +7,8 @@ const crypto = require('crypto');

const SANDBOX_URL = 'https://sandbox-vendors.paddle.com/api/2.0';
const SERVER_URL = 'https://vendors.paddle.com/api/2.0';
const VENDOR_SANDBOX_URL = 'https://sandbox-vendors.paddle.com/api/2.0';
const VENDOR_SERVER_URL = 'https://vendors.paddle.com/api/2.0';
const CHECKOUT_SANDBOX_URL = 'https://sandbox-checkout.paddle.com/api/1.0';
const CHECKOUT_SERVER_URL = 'https://checkout.paddle.com/api/1.0';
class PaddleSDK {

@@ -30,5 +33,3 @@ /**

this.publicKey = publicKey || 'MISSING';
this.server =
(options && options.server) ||
(options && options.sandbox ? SANDBOX_URL : SERVER_URL);
this.options = options;
}

@@ -47,4 +48,16 @@

*/
_request(path, { body = {}, headers = {}, form = true, json = false } = {}) {
const url = this.server + path;
_request(
path,
{
body = {},
headers = {},
form = true,
json = false,
returnFirstItem = false,
checkoutAPI = false,
} = {}
) {
const url = this._serverURL(checkoutAPI) + path;
// Requests to Checkout API are using only GET,
const method = checkoutAPI ? 'GET' : 'POST';
const fullBody = Object.assign(body, this._getDefaultBody());

@@ -54,10 +67,12 @@

headers: this._getDefaultHeaders(headers),
method: 'POST',
method,
};
if (form) {
options.form = fullBody;
if (method !== 'GET') {
if (form) {
options.form = fullBody;
}
if (json) {
options.json = fullBody;
}
}
if (json) {
options.json = fullBody;
}
// console.log('options', options);

@@ -70,3 +85,7 @@

if (body.success) {
return body.response || body;
const response = body.response || body;
if (returnFirstItem && Array.isArray(response)) {
return response[0];
}
return response;
}

@@ -91,2 +110,20 @@

/**
* Get the used server URL. Some of the requests go to Checkout server, while most will go to Vendor server.
*
* @private
*/
_serverURL(checkoutAPI = false) {
return (
(this.options && this.options.server) ||
(checkoutAPI &&
(this.options && this.options.sandbox
? CHECKOUT_SANDBOX_URL
: CHECKOUT_SERVER_URL)) ||
(this.options && this.options.sandbox
? VENDOR_SANDBOX_URL
: VENDOR_SERVER_URL)
);
}
/**
* Get the list of required headers for an API request

@@ -156,2 +193,20 @@ *

/**
* Get the plan based on its ID
*
* @method
* @param {number} [planId]
* @returns {Promise}
* @fulfil {object} - The requested plan
*
* @example
* const plan = await client.getProductPlan(123);
*/
getProductPlan(planId) {
return this._request('/subscription/plans', {
body: { plan: planId },
returnFirstItem: true,
});
}
/**
* Get the current list of all users or users for a subscription plan

@@ -170,3 +225,3 @@ *

return this._request('/subscription/users', {
body: { plan: planID },
body: planID ? { plan: planID } : {},
});

@@ -331,2 +386,22 @@ }

/**
* Get subscription details
*
* @method
* @param {number} subscriptionID
* @returns {Promise}
* @fulfill {object} - Details of a single subscription
*
* @example
* const result = await client.getSubscriptionPlan(123);
*/
getSubscriptionPlan(subscriptionID) {
return this._request('/subscription/users', {
body: {
subscription_id: subscriptionID,
},
returnFirstItem: true,
});
}
/**
* Update (upgrade/downgrade) the plan of a subscription

@@ -359,3 +434,3 @@ *

* @param {number} subscriptionID
* @param {Object} postData { quantity, price, planID, currency }
* @param {Object} postData { quantity, price, planID, currency, prorate, keepModifiers, billImmediately }
* @returns {Promise}

@@ -368,3 +443,11 @@ * @fulfill {object} - The result of the operation

updateSubscription(subscriptionID, postData) {
const { quantity, price, planID, currency } = postData;
const {
quantity,
price,
planID,
currency,
prorate,
keepModifiers,
billImmediately,
} = postData;
const body = {

@@ -385,2 +468,11 @@ subscription_id: subscriptionID,

}
if (keepModifiers) {
body.keep_modifiers = keepModifiers;
}
if (billImmediately) {
body.bill_immediately = billImmediately;
}
if (prorate) {
body.prorate = prorate;
}

@@ -410,2 +502,39 @@ return this._request('/subscription/users/update', {

/**
* Get the list of all users
*
* @method
* @param {Object} options { page, resultsPerPage, state, planId }
* @returns {Promise}
* @fulfil {object} - The users list
*
* @example
* const users = await client.getUsers();
* const users = await client.getUsers({ state: 'active' });
*
* @note
* If you have a large amount of active users, you will need to create paginated calls to this function.
*/
getUsers(options = {}) {
const {
page = 1,
resultsPerPage = 200,
state = null,
planId = null,
} = options;
const body = {
page,
results_per_page: resultsPerPage,
};
if (state) {
body.state = state;
}
if (planId) {
body.plan_id = planId;
}
return this._request('/subscription/users', { body });
}
/**
* Generate a custom pay link

@@ -435,4 +564,21 @@ *

}
/**
* Get details of Checkout Order
*
* @method
* @param {string} ID of the Checkout order
* @returns {Promise}
* @fulfil {object} - Details of the Checkout order
*
* @example
* const result = await client.getOrderDetails('219233-chre53d41f940e0-58aqh94971');
*/
getOrderDetails(checkoutId) {
return this._request(`/order?checkout_id=${checkoutId}`, {
checkoutAPI: true,
});
}
}
module.exports = PaddleSDK;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc