Git Product home page Git Product logo

paddle-node-sdk's People

Contributors

alecsammon avatar dependabot[bot] avatar vifer avatar vijayasingam-paddle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

paddle-node-sdk's Issues

[Feature]: add error handling example

Tell us about your feature request

Add an example to handle a particular error response, for instance 409 conflict

What problem are you looking to solve?

Properly handle a particular error response

Additional context

No response

How important is this suggestion to you?

Nice to have

[Bug]: casting event SubscriptionPriceNotification to Price throw error

What happened?

Getting casting error from SubscriptionPriceNotification to Price

Type 'SubscriptionPriceNotification' is missing the following properties from type 'Price': createdAt, updatedAt, product

Steps to reproduce

  1. Cast from SubscriptionPriceNotification to Price

What did you expect to happen?

SubscriptionPriceNotification becomes a Price entity for storage purposes

Logs

Type 'SubscriptionPriceNotification' is missing the following properties from type 'Price': createdAt, updatedAt, product

[Feature]: Way to test webhook signature

Tell us about your feature request

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.

What problem are you looking to solve?

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.

Additional context

No response

How important is this suggestion to you?

Important

[Feature]: Expose hasMore and add estimatedTotal to Collection

Tell us about your feature request

Expose hasMore and add estimatedTotal to Collection to align with pagination (https://developer.paddle.com/api-reference/about/pagination).

export abstract class Collection<T, C> implements AsyncIterable<C> {
private hasMore: boolean = true;
private nextLink: string;
private data: C[] = [];

What problem are you looking to solve?

Facilitate pagination in application.

Additional context

No response

How important is this suggestion to you?

Nice to have

[Bug]: Webhook time validation error

What happened?

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.

Steps to reproduce

Simply test the webhook in sandbox mode.

What did you expect to happen?

webhooks-validator.ts

Verify that it fails to validate the date; if the MAX_VALID_TIME_DIFFERENCE is increased from 5 to 10 it works normally.

Logs

No response

[Feature]: Support Cloudflare

Tell us about your feature request

Tweak paddle-node-sdk so that it runs on Cloudflare.

What problem are you looking to solve?

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.

Additional context

No response

How important is this suggestion to you?

Critical

[Feature]: Add createdAt and updatedAt to Price and PriceNotification

Tell us about your feature request

Add createdAt and updatedAt to Price and PriceNotification to align with align with API and webhooks documentation.

What problem are you looking to solve?

Synchronize and reconcile application database with Paddle.

Additional context

No response

How important is this suggestion to you?

Important

[Bug]: getPaymentMethodChangeTransaction throws error because unitPriceOverrides is undefined

What happened?

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.

Steps to reproduce

  1. Create a basic product with a price that does not have any overwrites.
  2. Create a subscription.
  3. Init Paddle using new Paddle(apiKey).
  4. Run paddle.subscriptions.getPaymentMethodChangeTransaction(subId).
  5. Observe the error.

What did you expect to happen?

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;

Logs

[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)

[Bug]: `EventName` not accessible with Supabase Edge Functions.

What happened?

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'

Steps to reproduce

  1. Create a supabase webhook
  2. Import the Paddle SDK and EventName enum
  3. Try the webhook

What did you expect to happen?

Access the EventName in Paddle SDK on Edge Functions.

Edit

I don't know if EventName is the only exported thing that's concerned (haven't tested other exports yet).

[Bug]: Not supported to run in Cloudflare Worker Edge environment

What happened?

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".

Steps to reproduce

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',
    },
  ],
})

What did you expect to happen?

I hope to use @paddle/paddle-node-sdk in an edge environment.

Logs

⨯ 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

[Feature]: Add updatedAt to Product and ProductNotification

Tell us about your feature request

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.

export class Product {
public readonly id: string;
public readonly name: string;
public readonly type: CatalogType | null;
public readonly description: string | null;
public readonly taxCategory: TaxCategory;
public readonly imageUrl: string | null;
public readonly customData: CustomData | null;
public readonly status: Status;
public readonly createdAt: string;
public readonly importMeta: ImportMeta | null;
public readonly prices: Price[] | null;

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"
  }
}

export class ProductNotification {
public readonly id: string;
public readonly name: string;
public readonly type: CatalogType | null;
public readonly description: string | null;
public readonly taxCategory: TaxCategory;
public readonly imageUrl: string | null;
public readonly customData: CustomData | null;
public readonly status: Status;
public readonly createdAt: string;
public readonly importMeta: ImportMetaNotification | null;

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"
  }
}

What problem are you looking to solve?

Synchronize and reconcile application database with Paddle.

Additional context

No response

How important is this suggestion to you?

Important

[Feature]: Stop polluting stdout (via lots of console.log calls)

Tell us about your feature request

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.

What problem are you looking to solve?

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
});

Additional context

No response

How important is this suggestion to you?

Nice to have

[Bug]: Issue with Authentication Header Format When Using paddle-node-sdk

What happened?

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

Steps to reproduce

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);

}
}

What did you expect to happen?

No response

Logs

No response

[Feature]: Provide way to delete all sandbox data

Tell us about your feature request

Provide a way to delete all sandbox data.

What problem are you looking to solve?

  • Getting back to a clean slate with a sandbox that has accumulated many exploratory and experimental objects.
  • Not having to use fake emails after running out of real emails developing and testing new customer notifications.

Additional context

No response

How important is this suggestion to you?

Important

[Bug]: The punycode module is deprecated

What happened?

[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

Steps to reproduce

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.

What did you expect to happen?

I would like to have a clear console without deprecation warning.

Logs

No response

[Bug]: casting event ProductNotification to Product throw error

What happened?

Getting casting error from ProductNotification to Product

Property 'prices' is missing in type 'ProductNotification' but required in type 'Product'.ts

Steps to reproduce

  1. Cast from ProductNotification to Product

What did you expect to happen?

ProductNotification becomes a Product entity for storage purposes

Logs

Property 'prices' is missing in type 'ProductNotification' but required in type 'Product'.ts

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.