#sxe-auth and capture
1 messages · Page 1 of 1 (latest)
Hi
is this what you are looking for https://stripe.com/docs/payments/capture-later ?
I think so, I want to capture later,
but if I don't want to capture it anymore, refund it back to user.
The process will be this:
if you don't want to capture then you could cancel it https://stripe.com/docs/api/payment_intents/cancel
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
- User buys one, or more items.
- User pays.
- Server checks if the products are out of stock or not. (via php &mysqli queries)
- If not out of stock => confirm payment.
- If out of stock => instantly deliver the payment back. (do not allow it)
yes that doable with capture later and you can either capture or cancel the Payment Intent
Are there any fees for the cancel the payment?
no
where did you find this?
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
\Stripe\Stripe::setApiKey('x');
\Stripe\PaymentIntent::create([
'amount' => 1099,
'currency' => 'ron',
'payment_method_types' => ['card'],
'capture_method' => 'manual',
'payment_method' => '{{PAYMENT_METHOD_ID}}',
]);
this should come from you creating a payment method by collecting card details https://stripe.com/docs/payments/accept-a-payment-synchronously#web-collect-card-details from your customer
What do you mean by checkout.js?
sorry I'm a bit lost are we still talking about capture later?
the docs you sent are not for capture later
this is the normal flow of accepting directly a payment
I have a question.
On the hold docs, it tells this>
\Stripe\PaymentIntent::create([
'amount' => 1099,
'currency' => 'ron',
'payment_method_types' => ['card'],
'capture_method' => 'manual',
]);
but on capture later, it adds the payment_method too.
Should I use the Hold method, or capture_later method ?
yes it's doable also this way
I think Hold suits the best.
both work
Can I cancel the paymentintent even if it's on hold, right?
yes
the only difference in those two approaches is with how you collect the payment method, either you collect it before creating the PaymentIntent and you pass the payment_method id for the Payment Intent or you first create the PaymentIntent and then use the client_secret with Stripe Elements on the front-end to collect the payment method
You cannot cancel this PaymentIntent because it has a status of canceled. Only a PaymentIntent with one of the following statuses may be canceled: requires_payment_method, requires_capture, requires_confirmation, requires_action, processing.
when I m testing it with insufficient_funds
card
sounds self explanatory, the PaymentIntent was already canceled and you tried to cancel it again?
But why was it cancelled in the first place?
if you look at the PaymentIntent in the dashboard, at the bottom of the page there is a timeline of events and API requests that will likely answer that
I could tell you if you shared the pi_xxx ID
pi_3KvfFELKPu9R0yzS06lionIG
it's cancelled because your PHP code called the API to cancel it already : https://dashboard.stripe.com/test/logs/req_6vhoSKhbkYqxQz
probably your code does the same thing twice or gets called multiple times or something, hard to say but you can debug it
Yes, you're right. No, my code doesn't do the thing twice, but, I tested this:
There are 10 items on stock.
An user grabs 10 on his bag.
These 10 items are still available for anyone.
But, an user, purchased 1 item, and paid it => there are 9 items remained available on stock.
But the initial user had 10 items on his bag, while he was on payment page.
And he paid for 10 items.
PHP saw that he wants to pay for more items that there are on stock.
And cancelled it.
I was a bit confuse why it cancelled twice.
Uncaught (Status 400) (Request req_bkOZuNGYaatHBH) This PaymentIntent could not be captured because it has a status of requires_payment_method. Only a PaymentIntent with one of the following statuses may be captured: requires_capture.
I get this error, when I enter on the payment page, without inserting card infos or pressing submit.
yep, makes sense right?
how can you capture if if you haven't begun processing the payment yet? If you have code trying to do that(capture immediately) then that code shouldn't be running.
But only captures I'm trying to make are on webhook.php
The payment page has only create.php
Which does not have any capture
Only the ' 'capture_method' => 'manual',
' on create method.
you must be mistaken then, sorry. You can only get that error and that request ID if are running code to capture the PaymentIntent so you need to carefully debug and add logs.
Hmm
$intent->capture(['amount_to_capture' => $Price*100]);
We're talking about this, right?
yes
Is something wront my create methodf?
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => $Price*100,
'currency' => 'ron',
'payment_method_types' => ['card'],
'capture_method' => 'manual',
'metadata' => [
'UserID' => $_SESSION['ID'],
'DiscountAplicat' => $DiscountAplicatrow1008,
'Transport' => $Transportrow1008,
'NumeTransport' => $NumeTransportrow1008,
'PrenumeTransport' => $PrenumeTransportrow1008,
'Localitatea' => $Localitatearow1008,
'Adresa' => $Adresarow1008,
'Email' => $Emailrow1008,
'Telefon' => $Telefonrow1008,
'AdresaTransport' => $AdresaTransportrow1008
]
]);
nope, seems perfectly fine to me
Note : This is part of create.php
I am not submitting yet the payment (I'm not pressing the submit button) with credit card infos
all I can tell you is you should add some logs or breakpoints etc and figure out why that call to ->capture happens when you don't expect it
I jst removed the ->capture from code, let's see what happens.
ty!
Can retrieve generate same error as capture?
it can generate errors, but not that specific one This PaymentIntent could not be captured because it has a status of <status> , no.
So, I've removed the
$intent = \Stripe\PaymentIntent::retrieve($intent_id);
$intent->capture(['amount_to_capture' => $Price*100]);
}
=> no more errors.
Interesting.
cool!
looking again, probably you ran that code regardless of the event type in your webhook handler maybe?
But the problem is that I don't run the webook.php
Error generates even if I press the button "Proceed to payment"
like your endpoint listens to payment_intent.created, do you always just run that code? (in which case you shouldn't)
and the page of where I put the infos in the form appear./
yeah you don't run webhook.php though, it's triggered by Stripe sending you an event.
or maybe I'm wrong and it's not related to webhooks — I don't know, I don't have the context on the code you're writing, but maybe that's one option
I don't run that code in payment_intent.created or on another else events
ok never mind then!
This is the part of code.
webhook.php only.
try {
$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
echo '⚠️ Webhook error while parsing basic request.';
http_response_code(400);
exit();
}
if ($endpoint_secret) {
// Only verify the event if there is an endpoint secret defined
// Otherwise use the basic decoded event
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
echo '⚠️ Webhook error while validating signature.';
http_response_code(400);
exit();
}
}
$intent_id = $event->data->object->id;
$stripe = new \Stripe\StripeClient(
'x'
);
$payment_intent = $stripe->paymentIntents->retrieve($intent_id,
['expand' => ['payment_method']]
);