#xzel_api
1 messages ยท Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- xzel_api, 3 hours ago, 24 messages
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1247312982782771252
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
I am asking for the full intent via
expand: [ 'payment_intent', 'customer' ]
Can you clarify how you're doing this? The request you shared is a request to create a Checkout Session insubscriptionmode. There's no PaymentIntent yet
yes that is how I am doing it. I'm trying to get the line items to send to conversion API
I would ideally like to do this on the webhook but the GTag Server to Server is a mess
so I'm short cutting it rn via the return URL and was going to poll for the intent to go to paid
I guess the subscription uses invoice instead and I could expand that instead correct?
I just need the line items off some piece of data as well as confirmation the subscription has been paid
Let's pause there. What exactly are you trying to achieve?
So we have a checkout via sessions for a subscrption, that will then send off to a page via return_url: `${LOCAL_HOSTNAME}/checkout/return?session_id={CHECKOUT_SESSION_ID}`,
that page polls another status api. Once the subscrption is paid for, I would like it to return purchases data to log in the browser via GTag
Since you're using Checkout, is there a particular reason why you wouldn't just listen for checkout.session.completed events? https://docs.stripe.com/payments/checkout/fulfill-orders#fulfill
From what I understood the correct webhook to listen to was 'invoice.paid'
And its challenging to get GTag to be happy with a truly server side implementation, so I can't do this via a webhook
Hi there ๐ taking over, as my colleague needs to step away
We don't recommend provisioning services without using webhooks. Too much can go wrong in the workflow you're describing (e.g. what if the customer closes the browser after payment or your server responds unexpectedly and they don't get redirected?). With webhooks, if they fail, Stripe will retry them. With this redirect-based workflow, you get one shot to confirm the payment went through, so generally we would not recommend going that route
I am using webhooks
For this particular thing, resolving the return page while the invoice completes, so I can fire a GTag event if it completes successfully, is unrelated
The sessiion checkout gets forwarded to a page that is polling stripeClient.checkout.sessions.retrieve
to check if the session is expired, open or complete
if complete -> get data, format for gtag, fire in the browser
If they close the browser wcyd
but this is just a short term solution
Stripe doesn't seem to have any documentation on firing an event to GTag, which I need instead of Google Analytics, for other conversion APIs
for google has kind of dropped the ball with server to server GTag events and its shockingly complex
I wouldn't be doing it this way if I could use the webhook data
Got it, okay. Had to familiarize myself with Gtag, but I think I understand the problem space now. Are you only accepting card payments? Or are you accepting delayed payment methods like ACH, SEPA, BACS, etc.?
I'm pretty sure its only card for now
Also you nailed it that was exactly the issue I was trying to get at with my previous help thread
session = await stripeClient.checkout.sessions.retrieve(request.query.session_id, {
expand: [ 'invoice', 'customer' ]
});
if (session.payment_intent === null) {
throw new Error('Unable to find stripe payment_intent');
}
if (session.status === 'expired') {
return reply.code(200).send({
status: 'failure',
paymentStatus: session.status
});
} if (session.status === 'open') {
// Return ping
return reply.code(404).send({
status: 'pending',
paymentStatus: session.status
});
}
// Make sure we have a real customer type
if (session.customer === null || typeof session.customer !== 'object' || session.customer?.deleted) {
throw new Error('Unable to get customer for session.');
}
if (session.invoice === null || typeof session.invoice !== 'object') {
throw new Error('Unable to get invoice for session.');
}
const event = buildGTagPurchaseEvent(user, session, session.customer, session.invoice);
return reply.code(200).send({
status: 'success',
paymentStatus: session.status,
gtagEvent: event
});
That is basically the code I'm working with at this point
When I started this conversation I had been using payment intent and not invoice so got that fixed at least
And then I'm dumping it into this stilly event ala this
export const buildGTagPurchaseEvent = (
user: UserType,
session: Stripe.Checkout.Session,
customer: Stripe.Customer,
invoice: Stripe.Invoice
): GTagCAPIEvent => {
const event: GTagCAPIEvent = {
name: 'purchase',
user_data: {
customer_email: user.email,
// TODO: User first name and last from user
first_name: user.name ?? 'Unknown',
last_name: '',
street: customer?.address?.line1 ?? 'Unknown',
city: customer?.address?.city ?? 'Unknown',
// country: 'dynamic value',
zip_code: customer.address?.postal_code ?? 'Unknown',
region: customer?.address?.country ?? 'Unknown'
},
ecommerce: {
currency: session.currency ?? 'Unknown',
value: session.amount_total ?? 0.0,
transaction_id: invoice.id ?? 'Unknown',
tax: session.total_details?.amount_tax ?? 0.0,
items: invoice.lines.data.map(line => {
return {
item_id: line.price?.id ?? 'Unknown',
item_name: line.plan?.id ?? 'Unknown',
quantity: 1,
price: parseFloat(line.unit_amount_excluding_tax ?? '0.0')
};
})
},
debug_mode: true
};
return event;
};
And this is kinda hot garbage but I need a short term fix before I go into the bowels that is trying to get my GTag server to be happy with a server side request
We have Cards, Apple and Google Pay and Link
so should be good with any short term delay
Okay, so yeah. I think you have it pretty well figured out at this point. You can rely on the customer to be redirect to your return_url, then retrieve the Checkout Session via its' ID to ensure that the payment was successful. That way you don't have to rely on server-side code to do Gtag stuff.
In my brief look, I'm not even sure Gtag can be used server-side, but maybe there's some hackery that could get that to work.
Stripe doesn't really have any in-built support for Gtag, so you're going to be largely on your own for figuring that one out (unfortuantely)
o trust me I am very well aware of the last two lol
holy hell idk how anyone does marketing anayltics, its a mess
and dont get me started on the integrations for the conversion APIs
I'd rather do assembly programming at this point
Anyways thanks for the help!
Sure thing!