paddlehq / paddle-node-sdk Goto Github PK
View Code? Open in Web Editor NEWNode.js SDK for working with the Paddle API in server-side apps.
Home Page: https://developer.paddle.com/
License: Apache License 2.0
Node.js SDK for working with the Paddle API in server-side apps.
Home Page: https://developer.paddle.com/
License: Apache License 2.0
Add an example to handle a particular error response, for instance 409 conflict
Properly handle a particular error response
No response
Nice to have
Getting casting error from SubscriptionPriceNotification to Price
Type 'SubscriptionPriceNotification' is missing the following properties from type 'Price': createdAt, updatedAt, product
SubscriptionPriceNotification becomes a Price entity for storage purposes
Type 'SubscriptionPriceNotification' is missing the following properties from type 'Price': createdAt, updatedAt, product
I'd like to test my paddle webhooks locally while using the unmarshal function of the sdk.
It would be great to have a way to put that function into test mode, or providing some other way to test handling the event while in development.
In development I have the problem of not really having a way to sign my test requests so that I can use the unmarshal function.
No response
Important
Expose hasMore
and add estimatedTotal
to Collection
to align with pagination (https://developer.paddle.com/api-reference/about/pagination).
paddle-node-sdk/src/internal/base/collection.ts
Lines 5 to 8 in 2fb1bb5
Facilitate pagination in application.
No response
Nice to have
Hi,
Thank you for the library. Recently, I have been having a problem validating the webhook signature: it was working fine a few days ago, but now it rejects all requests. I have checked the details and see that the failure occurs in this date-related code. I would like to know if there has been any recent change in the webhook functionality.
Simply test the webhook in sandbox mode.
Verify that it fails to validate the date; if the MAX_VALID_TIME_DIFFERENCE is increased from 5 to 10 it works normally.
No response
Tweak paddle-node-sdk
so that it runs on Cloudflare.
paddle-node-sdk does not run on Cloudflare because it imports crypto
without a node:
prefix. Node.js compatibility in Cloudflare requires the node:
prefix per https://developers.cloudflare.com/workers/runtime-apis/nodejs/
paddle-node-sdk
is cjs and node:crypto
on Cloudflare seems to be esm. Cjs must use a dynamic import to import esm.
No response
Critical
Add createdAt
and updatedAt
to Price
and PriceNotification
to align with align with API and webhooks documentation.
Synchronize and reconcile application database with Paddle.
No response
Important
Hi! When fetching a Price from the API that does not have unit_price_overrides
set, it returns an error and the current operation fails.
This happened to me when trying to use paddle.subscriptions.getPaymentMethodChangeTransaction(subId)
, it returns an error instead of the transaction but when I put a ?
before price.unit_price_overrides
in entities/price/price.js
, it works just fine.
new Paddle(apiKey)
.paddle.subscriptions.getPaymentMethodChangeTransaction(subId)
.The error should not be thrown. Instead, in /dist/entities/price/price.js
price.unit_price_overrides
being undefined should be handled properly, for example using ?
:
/* ... */
class Price {
constructor(price) {
/* ... */
this.unitPrice = new index_1.Money(price.unit_price);
this.unitPriceOverrides = price.unit_price_overrides?.map((unit_price_override) => new index_1.UnitPriceOverride(unit_price_override));
this.quantity = new index_1.PriceQuantity(price.quantity);
/* ... */
}
}
exports.Price = Price;
[Paddle] [LOG] [Request] GET https://sandbox-api.paddle.com/subscriptions/sub_01hs8tbydenhgakmxxxxxxxxxx/update-payment-method-transaction Transaction ID: 6762xxxx-xxxx-xxxx-xxxx-a8e914acxxxx
[Paddle] [LOG] [Response] GET https://sandbox-api.paddle.com/subscriptions/sub_01hs8tbydenhgakmxxxxxxxxxx/update-payment-method-transaction 200 Transaction ID: 6762xxxx-xxxx-xxxx-xxxx-a8e914acxxxx Request ID: 4ba7xxxx-xxxx-xxxx-xxxx-xxxx796ba203
Cannot read properties of undefined (reading 'map')
TypeError: Cannot read properties of undefined (reading 'map')
at new Price (/home/user/project/node_modules/@paddle/paddle-node-sdk/dist/entities/price/price.js:16:62)
at new TransactionItem (/home/user/project/node_modules/@paddle/paddle-node-sdk/dist/entities/transaction/transaction-item.js:7:46)
at /home/user/project/node_modules/@paddle/paddle-node-sdk/dist/entities/transaction/transaction.js:23:54
at Array.map (<anonymous>)
at new Transaction (/home/user/project/node_modules/@paddle/paddle-node-sdk/dist/entities/transaction/transaction.js:23:40)
at SubscriptionsResource.<anonymous> (/home/user/project/node_modules/@paddle/paddle-node-sdk/dist/resources/subscriptions/index.js:146:20)
at Generator.next (<anonymous>)
at fulfilled (/home/user/project/node_modules/@paddle/paddle-node-sdk/dist/resources/subscriptions/index.js:19:58)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Hello, I'm using Paddle Webhooks & Supabase Edge Functions to manage my customers' billing.
I want to use this SDK in the Webhooks which work with Deno.
I tried to import this module like any other npm module through:
import { Paddle, EventName, Environment } from "npm:@paddle/[email protected]";
This doesn't work and returns:
Uncaught SyntaxError: The requested module 'npm:@paddle/[email protected]' does not provide an export named 'EventName'
EventName
enumAccess the EventName
in Paddle SDK on Edge Functions.
I don't know if EventName
is the only exported thing that's concerned (haven't tested other exports yet).
Using the Next.js 14 + TypeScript tech stack, with the API set to the edge environment, an error occurs when calling paddle.transactions.create after importing the @paddle/paddle-node-sdk package: Module build failed: UnhandledSchemeError: Reading from "node:crypto".
Reproduction code snippet:
// route.ts
import { Environment, Paddle } from '@paddle/paddle-node-sdk'
export const runtime = 'edge'
const paddle = new Paddle(process.env.PADDLE_SECRET_KEY!, {
environment: Environment.production,
})
const transaction = await paddle.transactions.create({
items: [
{
quantity: 1,
priceId: 'priceId',
},
],
})
I hope to use @paddle/paddle-node-sdk in an edge environment.
⨯ node:crypto
Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:crypto
node_modules/@paddle/paddle-node-sdk/dist/esm/internal/api/client.js
node_modules/@paddle/paddle-node-sdk/dist/esm/paddle.js
node_modules/@paddle/paddle-node-sdk/dist/esm/index.js
Add updatedAt
to Product
and ProductNotification
to align with api and webhooks. Product
and ProductNotification
seems to have createdAt
but not updatedAt
. API documents updated_at
for Product
object and list/create/get/update. Webhooks documents updated_at
for created, imported, and updated product event.
paddle-node-sdk/src/entities/product/product.ts
Lines 11 to 22 in 2fb1bb5
https://developer.paddle.com/api-reference/products/get-product
{
"data": {
"id": "pro_01h7zcgmdc6tmwtjehp3sh7azf",
"name": "ChatApp Education",
"tax_category": "standard",
"type": "standard",
"description": "Spend more time engaging with students with ChataApp Education. Includes features from our Pro plan, plus tools to help educators track student progress.",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"custom_data": {
"features": {
"crm": false,
"data_retention": true,
"reports": true
}
},
"status": "active",
"import_meta": null,
"created_at": "2024-01-16T14:38:08.3Z",
"updated_at": "2024-01-16T14:38:08.3Z"
},
"meta": {
"request_id": "69ed6193-483b-410a-bcd7-b2b873bf8a6f"
}
}
https://developer.paddle.com/webhooks/products/product-created
https://developer.paddle.com/webhooks/products/product-imported
https://developer.paddle.com/webhooks/products/product-updated
{
"event_id": "evt_01h7zcr13xte50ncas1jkgpbfk",
"event_type": "product.updated",
"occurred_at": "2024-01-25T11:49:43.241Z",
"notification_id": "ntf_01h7zcr1683yvnvxf9mn8k7vcw",
"data": {
"id": "pro_01h7zcgmdc6tmwtjehp3sh7azf",
"name": "ChatApp for Schools",
"tax_category": "standard",
"type": "standard",
"description": "Spend more time engaging with students with ChataApp Education. Includes features from our Pro plan, plus tools to help educators track student progress.",
"image_url": "https://paddle-sandbox.s3.amazonaws.com/user/10889/2nmP8MQSret0aWeDemRw_icon1.png",
"custom_data": {
"features": {
"crm": false,
"data_retention": true,
"reports": true
}
},
"status": "archived",
"import_meta": null,
"created_at": "2024-01-16T14:38:08.3Z",
"updated_at": "2024-01-25T11:49:43.241Z"
}
}
Synchronize and reconcile application database with Paddle.
No response
Important
By default, this library is very chatty and prints a lot of actions to console/stdout. This might interfere with other log output and also does not work well together with other logging systems.
Example:
const paddle = new Paddle(process.env.PADDLE_API_KEY, {
environment: Environment.sandbox,
});
const eventCollection = paddle.events.list();
for await (const event of eventCollection) {
// do nothing...
}
This leads to the following console output (IDs redacted):
[Paddle] [LOG] [Request] GET https://sandbox-api.paddle.com/events Transaction ID: [...]
[Paddle] [LOG] [Response] GET https://sandbox-api.paddle.com/events 200 Transaction ID: [...] Request ID: [...]
[Paddle] [LOG] [Request] GET https://sandbox-api.paddle.com/events Transaction ID: [...]
[Paddle] [LOG] [Response] GET https://sandbox-api.paddle.com/events 200 Transaction ID: [...] Request ID: [...]
[Paddle] [LOG] [Request] GET https://sandbox-api.paddle.com/events Transaction ID: [...]
[Paddle] [LOG] [Response] GET https://sandbox-api.paddle.com/events 200 Transaction ID: [...] Request ID: [...]
[Paddle] [LOG] [Request] GET https://sandbox-api.paddle.com/events Transaction ID: [...]
[Paddle] [LOG] [Response] GET https://sandbox-api.paddle.com/events 200 Transaction ID: [...] Request ID: [...]
[Paddle] [LOG] [Request] GET https://sandbox-api.paddle.com/events Transaction ID: [...]
[Paddle] [LOG] [Response] GET https://sandbox-api.paddle.com/events 200 Transaction ID: [...] Request ID: [...]
I do not expect other libraries to pollute stdout this much. At least when nothing goes wrong, there should be no output to console by default.
I found no way to disable it, as there is no condition to disable it in the logger class.
It would make sense to disable the console.log calls by default. Instead, some logLevel setting could be provided. Example:
const paddle = new Paddle('...', {
logLevel: 'verbose' // in this case, the current output would be fine
});
No response
Nice to have
I attempted to retrieve customer information using an email address in the sandbox environment, but I am unable to fetch the data. The initial request was successful, but when I try to execute .next() to fetch more data, I encounter the following error message.
'Error: Authentication header included, but incorrectly formatted\n'
[Edit]: Removed screenshot as it contained client token
export class PaymentServer {
paddle = new Paddle(process.env.GIZ_PADDLE_CLIENT_TOKEN, {
environment: Environment.sandbox
});
async getCustomer() {
const customerCollection = this.paddle.customers.list({ email: [authService.user.email] });
let customer;
do {
customer = await customerCollection.next();
} while (customer.data.length > 0);
}
}
No response
No response
Provide a way to delete all sandbox data.
No response
Important
[Paddle] [LOG] [Request] GET https://api.paddle.com/products Transaction ID: XXX
(node:4292) [DEP0040] DeprecationWarning: The punycode
module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ...
to show where the warning was created)
[Paddle] [LOG] [Response] GET https://api.paddle.com/products 200 Transaction ID: XXX Request ID: XXX
Follow the steps from this very Github repo (getProducts) and it will raise this warning.
It seems that it is not a bug (yet) but a warning.
I would like to have a clear console without deprecation warning.
No response
Getting casting error from ProductNotification to Product
Property 'prices' is missing in type 'ProductNotification' but required in type 'Product'.ts
ProductNotification becomes a Product entity for storage purposes
Property 'prices' is missing in type 'ProductNotification' but required in type 'Product'.ts
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.