#vell2x_webhooks

1 messages ¡ Page 1 of 1 (latest)

grizzled bearBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1235229519829270579

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

heavy moon
#

We don't have separate webhook events for payments via billing portal

#

You should expect the same events except for specific checkout ones like checkout.sessions.*

warped boughBOT
celest lichen
#

Is it possible to only allow the billing portal to ping Charge.succeededand not the checkout?

silk wigeon
#

Unfortunately not, any charge that succeeds will send out that event. Can you tell me more about your usecase and why you want to differentiate like this?

celest lichen
#

The app provides more information about the user so the server is throwing an error but the payment still goes through. So the payment is going through but the database is not being updated

#

Is there a meta data I can send with the portal

#

I cant find the page since the dashboard was updated

silk wigeon
#

What error is being thrown? Can you send me the text of that error?

#

Is this your server throwing an error from the payment? Or are we throwing an error somewhere?

celest lichen
#

I see the issue. From the app I send the Job ID via meta data. So without the Job ID it cant find the user, that is why the payment goes through but the database is not being updated

silk wigeon
#

How are you setting that metadata? The customer portal shouldn't get rid of metadata if you are setting it on an invoice or payment intent

celest lichen
#

I am sending it with the Object using the Metadata

#

I have a try catch block so maybe I can add a function to find user without job ID in the catch block

silk wigeon
#

As in you are setting that on creation, or updating after the payment? Or something else?
And where specifically are you not seeing this metadata later? Is this in some the charge.succeeded events or an API call?

celest lichen
#

case 'checkout.session.completed':
const checkoutCompleted = event.data.object;
// Then define and call a method to handle the successful Checkout Session Completed.

  var string = JSON.stringify(checkoutCompleted);
  console.log("String: " + string);

  // Convert JSON string to JavaScript object
  var obj = JSON.parse(string, (key, value) => {
    console.log("Value: " + value);
    return value;
  });

  console.log("MetaData: " + checkoutCompleted.metadata);

  var metastring = JSON.stringify(checkoutCompleted.metadata);
  console.log("String: " + metastring);

  // Convert JSON string to JavaScript object
  var meta = JSON.parse(metastring, (key, value) => {
    console.log("Value: " + value);
    return value;
  });

  try {
    const userId = await getUserIdByCustomerId(checkoutCompleted.customer);
    console.log('Cus: ' + userId);
    const job = await getJobByUserIdAndJobId(userId, meta.jobid);
    console.log('Job: ' + job);
    console.log('Job JobID: ' + job.jobid)

    if (job) {
      // Compare payment information with job details
      console.log("")
      if (meta.jobid === job.jobid && checkoutCompleted.mode === 'subscription') {
        // Update payment status in the Firebase database
        console.log('Payment status updated in the Firebase database');

      } else if(meta.jobid === job.jobid && checkoutCompleted.mode === 'payment') {
        // Update payment status in the Firebase database
      } else {
        console.log('Payment information does not match job details');
      }
    } else {
      console.log('Job not found in the Firebase database');
    }
  } catch (error) {
    console.error('Error:', error);
  }
  console.log("Checkout Completed");
  break;
silk wigeon