#debdev
1 messages · Page 1 of 1 (latest)
hello, lets talk in this thread only, not in main channel
let me paste your other msg here too:
To make a payment first I create a customer
$customer = \Stripe\Customer::create([
'email' => $user['email'],
'name' => $user['prenom'] .' '.$user['nom'],
'phone' => $user['telephone'],
'address' => [
'line1' => $user['adresse'],
'city' => $user['ville'],
'postal_code' => $user['code_postal'],
'country' => 'FR'
]
]);
Then I create an invoice:
// Montant de la facture
\Stripe\InvoiceItem::create([
'customer' => $customer_id,
'amount' => $amount,
'currency' => "eur",
]);
// Informations de la facture
$invoiceOptions = [
'customer' => $customer_id,
'description' => $product['course_title'],
'collection_method' => 'send_invoice',
'days_until_due' => 29,
'automatic_tax' =>[
'enabled' => 'true'
],
'payment_settings' => [
'payment_method_types' => $payment_types
],
'metadata' => [
'product_id' => $product['product_id'],
'user_id' => $user_id,
'course_id' => $product['course_id'],
'course_title' => $product['course_title'],
'course_date' => $product['course_date']
]
];
$invoice = \Stripe\Invoice::create($invoiceOptions);
Then I finalizeInvoice() and retrieve the payment Intent to send client Secret to the frontend for the payment
$invoice->finalizeInvoice();
$payment_intent = \Stripe\PaymentIntent::retrieve($invoice->payment_intent);
$output = [
'clientSecret' => $payment_intent->client_secret,
];
wp_send_json($output);
I am doing those things right ? please heeelp 🙏
ok thanks
ok let's start here, can you share the Invoice ID where you see
The problem -> The amount of the invoice goes to 0 cents when it creates so no payment can be done.
ok so do you see this request: https://dashboard.stripe.com/test/logs/req_XDckb8JLNbWO4D
i do see it
you're creating an Invoice on a Customer. But it shows amount_due: 0 cause there isn't anything to invoice on the Customer. Which guide are you following to do this?
With Stripe doc, the amount goes to 0 when it creates the invoice on stripe Side. Look the first request, the amount is correct req_egAehUq3Vi7c8i
And I don't have this problem whith my company accounts and api keys (same code)
can you share the link to which doc / guide you are using ?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i don't use a specific guide, i search on stripe docs
If you want I can give you the req id with my company's API keys that went good
req_FrNPWb4LVByV5t
what I'm trying to nudge you is understand what you're building basically 🙂
You should follow a guide as I think you've missed crucial steps that your other integration is doing
Are you doing one off Invoices?
i dont understand one off invoices
If you have a good guide to propose me I wont say no 🙂
OK what business model are you integrating with Invoices? I can send the relevant guide
are you sending Invoice for customer to pay? or creating Invoice that charges them immediately?
Its a website to sell formations. I do both actually, but mainly to charge immediatly
but mainly to charge immediatly
and do you have PaymentMethods already collected? or do you intend to collect them on your page? or something else?
there's 2 approaches, one to "send invoice" and other to "charge automatically" so asking more questions to narrow down which guide is the right one for you
The payment method is collected on frontend
the user have a choice to pay en CB or sepa_debit
it's generated by StripeElements
let elements;
initialize();
$("#payment-form").submit(handleSubmit);
function initialize() {
elements = stripe.elements({
clientSecret: clientSecret,
});
const paymentElementOptions = {
layout: "tabs",
};
const paymentElement = elements.create("payment", paymentElementOptions);
paymentElement.mount("#payment-element");
}
async function handleSubmit(e) {
jQuery("#siteLoader").show();
e.preventDefault();
const url = window.location.href;
const { error } = await stripe.confirmPayment({
elements,
confirmParams: {
// Redirection paiement succès
return_url: url,
},
});```
ok great that's good that you have the PaymentMethod
(writing more)
you need this guide: https://docs.stripe.com/invoicing/integration/quickstart
What you are missing is the step for "Invoice Item creation"
Basically make sure your code is doing everything except 3 Send Invoice
Instead of that, you need:
3/ https://docs.stripe.com/api/invoices/finalize
4/ https://docs.stripe.com/api/invoices/pay
so you finalize and pay the Invoice immediately after creating it
let me know if that is clear?
Mmm, i think that is what I am doing already :
// Montant de la facture
\Stripe\InvoiceItem::create([
'customer' => $customer_id,
'amount' => $amount,
'currency' => "eur",
]);
// Informations de la facture
$invoiceOptions = [
'customer' => $customer_id,
'description' => $product['course_title'],
'collection_method' => 'send_invoice',
'days_until_due' => 29,
'payment_settings' => [
'payment_method_types' => $payment_types
],
'metadata' => [
'product_id' => $product['product_id'],
'user_id' => $user_id,
'course_id' => $product['course_id'],
'course_title' => $product['course_title'],
'course_date' => $product['course_date']
]
];
$invoice = \Stripe\Invoice::create($invoiceOptions);
return $invoice;
}
$invoice = creer_facture($customer->id,$user['user_id'],$amount, $product,$payment_types);
$invoice->finalizeInvoice();
$payment_intent = \Stripe\PaymentIntent::retrieve($invoice->payment_intent);
$output = [
'pubKey' => $pub_key,
'clientSecret' => $payment_intent->client_secret,
];
wp_send_json($output);```
can you share the request ID for the same Customer where:
1/ you added an invoice item
2/ you created an Invoice on them
?
that will help show what you're passing to our API
sure
/v1/invoiceitems req_uMnAGUclHPlrrA
/v1/invoices req_qwCm2GS2uNQghM
Now I give you the same req with my company's account (API KEYS) which is working as expected
/v1/invoiceitems req_ZenylbFVZmy7tE
/v1/invoices req_FrNPWb4LVByV5t
thanks! looking
ok thanks
ah I think this is what you're missing, from the same guide I linked you earlier
your request to create InvoiceItems is before the Invoice request
If invoice items are created before an invoice is created, set the pending_invoice_items_behavior to include when creating the invoice so that all pending invoice items are automatically added to the invoice. In this case, only add invoice items to a single customer at a time to avoid adding them to the wrong customer.
https://docs.stripe.com/invoicing/integration/quickstart#create-invoice-item
can you pass that parameter as mentioned in the guide?
im looking
🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳 🥳
Thanks a lot ! it is working
🙏
if you come to Paris, contact me and I'll buy you drinks ! 😉
haha great! I'm glad you're unblocked and thank you!