#Lucas974 - invoices
1 messages · Page 1 of 1 (latest)
Hello! To clarify, you want the email address the customer provided during Checkout?
If so, the most typical flow is that you get the Customer ID from the Checkout Session's customer property, retrieve that Customer from the API, and then that object will have the email address.
where is the customer id ?
Below what I received:
Webhook event received: {
id: 'evt_1Mii12GxboHalNogeV3RNVqR',
object: 'event',
api_version: '2022-11-15',
created: 1678124404,
data: {
object: {
id: 'cs_test_a1t7eK0DiTCzSdGqzI8sFGAeunSIZG7b3fAl04nMFQohOb3Z19HWlJcMmq',
object: 'checkout.session',
after_expiration: null,
allow_promotion_codes: false,
amount_subtotal: 4900,
amount_total: 4900,
automatic_tax: [Object],
billing_address_collection: 'auto',
cancel_url: 'https://stripe.com',
client_reference_id: null,
consent: null,
consent_collection: [Object],
created: 1678124373,
currency: 'eur',
custom_fields: [],
custom_text: [Object],
customer: null,
customer_creation: 'if_required',
customer_details: [Object],
customer_email: null,
expires_at: 1678210773,
invoice: null,
invoice_creation: [Object],
livemode: false,
locale: 'auto',
metadata: {},
mode: 'payment',
payment_intent: 'pi_3Mii10GxboHalNog16wVQAff',
payment_link: 'plink_1MihzyGxboHalNog9ctVwjRr',
payment_method_collection: 'always',
payment_method_options: {},
payment_method_types: [Array],
payment_status: 'paid',
phone_number_collection: [Object],
recovered_from: null,
setup_intent: null,
shipping_address_collection: null,
shipping_options: [],
status: 'complete',
submit_type: 'auto',
subscription: null,
success_url: 'https://stripe.com',
total_details: [Object],
url: null,
shipping_cost: null,
shipping_details: null
}
},
livemode: false,
pending_webhooks: 1,
request: { id: null, idempotency_key: null },
type: 'checkout.session.completed'
}
Oh, looks like you're not using Customers. Ah, this Checkout Session was generated using a Payment Link. Gotcha. In that case you want to retrieve the Payment Intent and expand the payment_method; you should be able to find it there.
If I want to allow user on the frontend to pay and receive his invoice just after payment, do you have a way to do that?
Yeah, you can set invoice_creation.enabled to true when you create the Payment Link. Details are here: https://stripe.com/docs/payment-links/api#post-payment-invoices
Now I get this listening the payment_intent.succeeded:
Webhook event received: {
id: 'evt_3MiiGlGxboHalNog194zW1pD',
object: 'event',
api_version: '2022-11-15',
created: 1678125380,
data: {
object: {
id: 'pi_3MiiGlGxboHalNog1GoMmCgP',
object: 'payment_intent',
amount: 4900,
amount_capturable: 0,
amount_details: [Object],
amount_received: 4900,
application: null,
application_fee_amount: null,
automatic_payment_methods: null,
canceled_at: null,
cancellation_reason: null,
capture_method: 'automatic',
client_secret: 'pi_3MiiGlGxboHalNog1GoMmCgP_secret_kuHDVU4RRFkFuZXC8kiR6c03G',
confirmation_method: 'automatic',
created: 1678125379,
currency: 'eur',
customer: null,
description: null,
invoice: null,
last_payment_error: null,
latest_charge: 'ch_3MiiGlGxboHalNog1JCGhvsJ',
livemode: false,
metadata: {},
next_action: null,
on_behalf_of: null,
payment_method: 'pm_1MiiGkGxboHalNogARDQqldL',
payment_method_options: [Object],
payment_method_types: [Array],
processing: null,
receipt_email: null,
review: null,
setup_future_usage: null,
shipping: null,
source: null,
statement_descriptor: null,
statement_descriptor_suffix: null,
status: 'succeeded',
transfer_data: null,
transfer_group: null
}
},
livemode: false,
pending_webhooks: 2,
request: {
id: 'req_7djmnkKvhBsejH',
idempotency_key: '16632084-15f2-42ae-8a91-3ed0e13cd464'
},
type: 'payment_intent.succeeded'
}
Where is the customer_id?
There is no Customer ID. You need to expand the payment_method on that Payment Intent.
To clarify, is your goal to email them a Stripe-generated Invoice for the payment?
I wish to build an app using 2 parts: backend and frontend.
The backend, will listen using a webhook to payment succeeded, then add customer email to database.
The frontend, I just want to use payment link, user pay, they get the invoice from stripe just after payment, no ?
Gotcha. Yeah, if you configure the Payment Link to generate an Invoice Stripe will send it to the email address provided during Checkout.
For the email-in-database part you can retrieve the Payment Intent with the Payment Method expanded and get the email from there.
You do need to make an API call to do that though, there's no way to expand ahead of time before receiving the Event.
I need to call an API, that's OK, I can use fetch for that, but in argument which data he needs to get the right email address. I don't understand well this part.
You need to do this from your server using your secret key. You can't do it client-side. You should use one of our server-side libraries to do this, not fetch.
The steps are:
- Your server receives the
payment_intent.succeededEvent - Your server retrieves the
payment_intentspecified in that Event with thepayment_methodexpanded - You access the email address under the Payment Method in the response
The docs for retrieving the Payment Intent are here: https://stripe.com/docs/api/payment_intents/retrieve
The docs for expansion are here: https://stripe.com/docs/api/expanding_objects
merci
and to use these api
I need to install stripe sdk?
doing npm install stripe?
We recommend installing the Stripe library for the language you're using, yes. It will make things easier. It's not required though, you can access the API directly without it.
But yes, it would be npm install --save stripe
okay
I did this:
require('dotenv').config();
const stripe = require('stripe')(process.env.SK_STRIPE);
const express = require('express');
const app = express();
const https = require('https');
const fs = require('fs');
const PORT = process.env.PORT;
app.post('/webhook', express.json(), (req, res) => {
const event = req.body;
console.log('Webhook event received:', event);
res.status(200).send('Webhook received successfully');
const paymentIntent = await stripe.paymentIntents.retrieve(
'????'
);
});
What to put here? => ????
Sorry, I can't write your code for you. Did you have a look at the docs I provided above?
You basically need to add in there both which Payment Intent you want to retrieve and what you want to expand.
ok
There are some more examples here: https://stripe.com/docs/expand
I know i need to retrieve payment_method
But honestly I don't know how to achieve this
:/
This would be the call to retrieve the payment intent https://stripe.com/docs/api/payment_intents/retrieve
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
And Rubeus sent the expand doc to show you that you can include expand: ['payment_method'] to get that full object back with the payment intent response
oh, now it works!
thank you so much @proven tangle !
Merci encore!
And regarding the payment link, I added invoice.
In test mode, I don't receive the invoice, normal?
Yes, in test mode most emails are turned off by default though you can get some if you add your account's exact email address as the one for the invoice
So you may be able to see that email if you do that
Otherwise your dashboard's page for that invoice should let you send out an email for that invoice regardless of address
Lucas974 - invoices
and is there a way to have this invoice, give a way to user, to download in one clic his invoice?
We provide an invoice download URL in the invoice object that we send to you, so you can pass that link to your user
https://stripe.com/docs/api/invoices/object#invoice_object-invoice_pdf
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.