#ZeroThreeEight

1 messages · Page 1 of 1 (latest)

silent novaBOT
buoyant obsidian
#

👋 happy to help

sacred field
#

Hi

#

Yes

#

But the error is regarding my own code

#

Error handling chargeback: Error: Stripe: Argument "customer" must be a string, but got: [object Object] (on API request to `GET /v1/customers/{customer}`) \

#
    if (eventType === "charge.dispute.created") {
      console.log("Chargeback functie gestart");
      try {
        // Retrieve and expand the charge object to access the customer ID
        const charge = await stripe.charges.retrieve(data.charge, {
          expand: ["customer"],
        });
        const customer = await stripe.customers.retrieve(charge.customer);

        // Update database
        const id = customer.metadata.id;
        const ref = db.collection("users").doc(id);
        const get = await ref.get();
        const userData = get.data();

        console.log("Met ID: " + id);

        const updatedData = {
          ...userData,
          eindDatum: moment().format("DD-MM-YYYY"),
          isBetaald: "Chargeback",
        };
        const update = ref.update(updatedData);
        const sheet = await axios.put(
          `${process.env.SHEET_BEST_API}/id/${id}`,
          {
            ...updatedData,
          }
        );

        // Unsubscribe with subscription ID
        try {
          const subscriptionId = userData.subscriptionId;
          const deleted = await stripe.subscriptions.del(subscriptionId);
          console.log("Subscription successfully canceled");
        } catch (error) {
          console.error("Error canceling subscription:", error);
        }
      } catch (error) {
        console.error("Error handling chargeback:", error);
      }
    }

    if (eventType === "checkout.session.completed") {
      try {
        ("Checkout session completed!");
        const customer = await stripe.customers.retrieve(data.customer);

        // Add to database
        const id = customer.metadata.id;
        const ref = db.collection("users").doc(id);
        const get = await ref.get();
        const userData = get.data();

        const updatedData = {
          ...userData,```
#

Above you'll find my webhook

#

At the moment I cannot test chargebacks the development / testing area

#

And im already in production with this code

buoyant obsidian
#

you need to pass data.customer.id

sacred field
#

Where?

buoyant obsidian
#

const customer = await stripe.customers.retrieve(data.customer);

sacred field
#

That didn't work

#

Got the same error

buoyant obsidian
#

oh yes

#

there's another line

sacred field
#

The customer object isn't included in the webhook call, as it is in the checkout.session.completed (as I understood from your colleague)

buoyant obsidian
sacred field
#

I see

#

So do I need to edit one line ?

#

const customer = await stripe.customers.retrieve(charge.customer) -->
const customer = await stripe.customers.retrieve(charge.customer.id);

buoyant obsidian
#

both lines where you do stripe.customers.retrieve

sacred field
#

The checkout function works good actually if you mean that one

#

Its the dispute handler thats not working

buoyant obsidian
#

then yes

sacred field
#

Ok thank you

#

Have a nice day