paddle-node-sdk icon indicating copy to clipboard operation
paddle-node-sdk copied to clipboard

[Bug]: `previewUpdate` endpoint returns wrong values

Open stpp2 opened this issue 11 months ago • 7 comments

What happened?

The previewUpdate endpoint is wrongly calculating credits and this affects both the Paddle UI and any API call to that endpoint. (using Paddle Billing)

When credits exist on a subscription, proration is miscalculated. This returns wrong values for future payments.

While this only affects previews rather than any live date, it's still a critical issue with the API.

Steps to reproduce

  1. Create a new subscription with a couple of recurring products.
  2. Remove one product with prorated_immediately option.
  3. Use the previewUpdate endpoint while adding another product that exceeds the current amount of available credits. ...

The number returned for the "Next payment" is wrong. (After completing the change, it does return the correct value)

What did you expect to happen?

No response

Logs


stpp2 avatar Jan 30 '25 21:01 stpp2

Hi @stpp2,

Thank you for raising this bug.

I have passed this report to the respective team. I will let you know once it is fixed.

In the meantime, please feel free to reach out to us if you need any other help.

Thank you.

vijayasingam-paddle avatar Jan 31 '25 17:01 vijayasingam-paddle

Hey @stpp2 👋

Thanks for flagging this. I'm just looking into it, but I need a bit more information from you to help troubleshoot.

This is what I think is going on:

  • You have a subscription for a customer who has a balance because of a prorated credit.
  • You're updating a subscription with an update that consumes the balance and results in a charge, using either prorated_immediately or full_immediately.
  • The totals for immediate_transaction are correct, but next_transaction and recurring_transaction_details aren't correct.

Does this sound about right?

It sounds like immediate_transaction, next_transaction, and recurring_transaction_details, might all include the credit, which is why the totals aren't correct — could you confirm?

If you have sample requests or specific examples that you'd be willing to share, that'd be really useful. You can email [email protected] if you'd prefer not to post that information publicly.

-- Michael

heymcgovern avatar Feb 03 '25 15:02 heymcgovern

Hi Michael @heymcgovern ,

Thanks for looking into this. I've also sent this to support over email but haven't heard much back.

This only happened to me in Sandbox mode so far, so there's probably no specific example I can share. That said, reproducing is quite straightforward - both via API and the Paddle UI. If you still need a specific example let me know.

It sounds like immediate_transaction, next_transaction, and recurring_transaction_details, might all include the credit, which is why the totals aren't correct — could you confirm?

Yes that sounds right. As mentioned, the bug only affects the "preview" of the next_transaction (possibly recurring_transaction_details too). Once the transaction is completed - those number seem to be correct again.

stpp2 avatar Feb 03 '25 16:02 stpp2

Perfect, thanks for this.

We're working on a fix for immediate_transaction and next_transaction previews. It should be live after it's been through testing and review. I'll pop back when that's done 📫

It looks like credit is applied to recurring_transaction_details in some cases when it shouldn't be. This is a separate bug that requires a little more digging into on our side. No timeline for this one just yet, but it's on the radar.

heymcgovern avatar Feb 04 '25 13:02 heymcgovern

Sounds great, thanks for the heads up! 🙏 The immediate_transaction and next_transaction are indeed more critical for the use-case I've tested so it'd be great if it can be fixed.

I don't recall testing recurring_transaction_details directly but it's possible that the same issue appears there too.

stpp2 avatar Feb 04 '25 14:02 stpp2

Hello @vijayasingam-paddle

Title: PATCH /subscriptions/{id}/preview returns "URL called is invalid" (404 error)

I am trying to use subscriptionPreviews.previewUpdate() to preview the cost of updating a subscription, but I keep getting a 404 URL called is invalid error.

Here is my function :

import { Environment, LogLevel, Paddle } from '@paddle/paddle-node-sdk';

const paddle = new Paddle({ apiKey: process.env.PADDLE_API_KEY, environment: Environment.sandbox, logLevel: LogLevel.verbose });

const subscriptionId = "824976"; // Example subscription ID

const payload = { prorationBillingMode: 'prorated_immediately', items: [{ quantity: 8 }] };

try { const preview = await paddle.subscriptionPreviews.previewUpdate(subscriptionId, payload); console.log("Preview Response:", preview); } catch (error) { console.error("Error:", error); }

Getting below error :

[Paddle] [LOG] [Request] PATCH /subscriptions/824976/preview Transaction ID: adc72c5b-5145-4f7c-870a-68fb36b35265 [Paddle] [LOG] [Response] PATCH /subscriptions/824976/preview 404 Transaction ID: adc72c5b-5145-4f7c-870a-68fb36b35265 Request ID: d079407a-055f-4b73-a6c1-1badbfaff483 error from update ApiError: URL called is invalid.

Can you please let me know where I am getting wrong in this ?

nayak-bhavya avatar Mar 21 '25 10:03 nayak-bhavya

Hi @nayak-bhavya, Thank you for reaching out to us.

Looking at your example subscription ID, I see that it looks like a Paddle classic subscription. Can you please let us know if you are trying to preview a Paddle Classic or billing subscription?

This Node SDK is built for Paddle billing and won't work with Paddle Classic entities.

If you are indeed a Paddle classic user, then your best bet would be to use normal API calls as this SDK will not work for you.

Thank you.

vijayasingam-paddle avatar Mar 21 '25 12:03 vijayasingam-paddle