PaddleHQ / paddle-js-wrapper

Wrapper to load Paddle.js as a module and use TypeScript definitions when working with methods.
Apache License 2.0
28 stars 4 forks source link

[Bug]: 500 unknown error #48

Closed vitalik1921 closed 3 weeks ago

vitalik1921 commented 4 weeks ago

What happened?

Sorry guys, I don't see any other way to get support or any human response. I want to prepare my platform for production. I always get 500, trying to use the sandbox.

Steps to reproduce

"use client";

import { Paddle, initializePaddle } from "@paddle/paddle-js";
import Dashboard from "../../components/layouts/Dashboard";
import { Plan } from "./component/Plan";
import { useEffect, useState } from "react";

export default function Page() {
  const [paddle, setPaddle] = useState<Paddle>();

  useEffect(() => {
    initializePaddle({
      environment: "sandbox",
      token: "test_xxx",
      eventCallback: function (data) {
        console.log(data);
      },
    }).then((paddleInstance: Paddle | undefined) => {
      if (paddleInstance) {
        setPaddle(paddleInstance);
      }
    });
  }, []);

  const handleCheckout = (productId: string) => () => {
    paddle?.Checkout.open({
      customer: {
        email: "sam@example.com",
        address: {
          countryCode: "US",
          postalCode: "10021",
        },
      },
      items: [
        {
          priceId: productId,
          quantity: 1,
        },
      ],
    });
  };

  return (
    <Dashboard>
      <div className="flex justify-center gap-4">
        <Plan onSelect={handleCheckout("pri_xxx")} />
        <Plan onSelect={handleCheckout("pri_xxx")} />
        <Plan onSelect={handleCheckout("pri_xxx")} />
      </div>
    </Dashboard>
  );
}

What did you expect to happen?

No response

How are you integrating?

Next.js

Logs

4.dc2786c1.chunk.js:1 
 POST https://sandbox-checkout-service.paddle.com/transaction-checkout 500 (Internal Server Error)
4.dc2786c1.chunk.js:1 Transaction checkout failed to be created.
page.tsx:16 
{}
page.tsx:16 
{type: 'checkout.error', code: 'validation', detail: 'Something went wrong | API Error: Transaction checkout failed to be created.', documentation_url: 'https://developer.paddle.com/api-reference'}
code
: 
"validation"
detail
: 
"Something went wrong | API Error: Transaction checkout failed to be created."
documentation_url
: 
"https://developer.paddle.com/api-reference"
type
: 
"checkout.error"
[[Prototype]]
: 
Object
vifer commented 3 weeks ago

Hi @vitalik1921

Could you please provide us with a request-id that could help us understand where the issue might be coming from? In the meantime could you also make sure you have set a default payment link please.

Thank you for reaching out to us.

vitalik1921 commented 3 weeks ago

Hey! Now I see the problem. I have "Paddle Initialization failed. Please check the inputs" in the console, but only on hard refresh, after the next refresh of the page everything works fine. So there is no requestId -

The log:

TypeError: paddle.Initialize is not a function. (In 'paddle.Initialize(_objectSpread2({}, rest))', 'paddle.Initialize' is undefined)
_callee$
tryCatch
(anonymous function)
asyncGeneratorStep
_next

I see that the paddle.js is was not downloaded for the first time, but uploaded after the page refresh

vitalik1921 commented 3 weeks ago

Hey! Sorry, totally my fault. I haven't checked that in the code there was a previous version of Paddle integrated