#sxe-card
1 messages · Page 1 of 1 (latest)
Hi.
Sounds like you aren't passing an expiration year when it is required?
Unfortunatelly not. It's an error which is being generated when I acces the payment page.
Without confirming the payment yet.
I think so, yes.
Actually, I'm passing the expiration year on this:
$brand = $event->data->card->brand;
$exp_month = $event->data->card->exp_month;
$exp_year = $event->data->card->exp_year;
$last4 = $event->data->card->last4;
On my webhook.php
Where are you seeing this error triggered?
Before the event types.
On my php.log
If I would put those infos inside a event type,
failed (i think)
It wouldn't generate any error.
Currently they are out of any kind of event type.
I'm a bit confused. Can you share your full code snippet here?
Yes
\Stripe\Stripe::setApiKey('x');
$endpoint_secret = 'x';
$payload = @file_get_contents('php://input');
$event = null;
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']]
);
$amount_received = $event->data->object->amount_received;
$amount_capturable = $event->data->object->amount_capturable;
$Currency = $event->data->object->currency;
$UserIDMetadata = $payment_intent['metadata']['UserID'];
$DiscountAplicat = $payment_intent['metadata']['DiscountAplicat'];
$Transport = $payment_intent['metadata']['Transport'];
$Localitatea = $payment_intent['metadata']['Localitatea'];
$brand = $event->data->card->brand;
$exp_month = $event->data->card->exp_month;
$exp_year = $event->data->card->exp_year;
$last4 = $event->data->card->last4;
if ($event->type == 'payment_intent.amount_capturable_updated')
{
$stripe->paymentIntents->capture(
$intent_id,
[]
);
}
if ($event->type == 'payment_intent.payment_failed')
{
........ some php queries
}
if ($event->type == 'payment_intent.succeeded')
{
... php queries
}
if ($event->type == 'payment_intent.canceled')
{
php queries
}
So this isn't going to work
Why?
Are you only listening for payment_intent.succeeded?
I will listen for every type, because I'm inserting in database what last 4, exp month, year, brand was used to pay.
was used to pay but failed, or canceled, or was succesflly
Then you need an if statement for each different event. Right now you are going to attempt to grab the exp_month etc. on every single event which not all of them will contain.
If you log out the event that you receive each time you will see what I'm saying
You can't just attempt to grab $event->data->card->exp_month from every event
Not all of them will have that property
bismark had to step out for a bit and I am around to answer questions. What is your question? I can try to help you out but my out-of-stripe advice might have to be very limited
Glad to hear! Have a good day yourself!
Hi.
I'm still getting these errors on intent payment succesfull
on event*
Attempt to read property "last4" on null
if ($event->type == 'payment_intent.succeeded')
{
$brand = $event->data->card->brand;
$exp_month = $event->data->card->exp_month;
$exp_year = $event->data->card->exp_year;
$last4 = $event->data->card->last4;```
Do you have the event ID for the event you saw that error on?
pi_3KwWtOLKPu9R0yzS0jHDCK0G
Also, amount_capturable shows me 0.
Actually, it shows me 0 because it should show me 0. I need to look for amount_captured
I am talking about the event itself, something like evt_123456789?
Apologies for dropping off this thread for a bit.
And that is interesting if you can see all of the other card info but not last4, trying to think of why that may be.
I can't see nothing about card info
Neither the exp or brand
"id": "evt_3KwVLFLKPu9R0yzS1H8j8gtH",
Ah, it looks like $event->data->card is not the right path to the card property
I think you will want something like $event->data->object->charges[0]->payment_method_details->card
For any type of event?
You may need to do a bit of playing around to figure out that path yourself. The card info is on the first charge in that payment intent's list of charges
No, for this event specifically, you will need to figure this out for each type of event that you are looking at.
$payment_intent = $stripe->paymentIntents->retrieve($intent_id,
['expand' => ['payment_method']]
);
Couldn't I make something like
$cardbrand = $payment_intent['payment_method']['brand'] ?
You can do something like that but it would be more like
$cardbrand = $payment_intent['payment_method']['card']['brand']
https://stripe.com/docs/api/payment_methods/object#payment_method_object-card-brand
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Should I do this?
instead of
$brand = $event->data->card->brand;
You can do that as well if you would like. It might be easier to grab that data from the charge on the event itself as that would save you from making an extra API call