#sxe-card

1 messages · Page 1 of 1 (latest)

open token
#

Hi there, do you have a request ID for this error?

silk arch
#

Hi.

open token
#

Sounds like you aren't passing an expiration year when it is required?

silk arch
#

Unfortunatelly not. It's an error which is being generated when I acces the payment page.

#

Without confirming the payment yet.

silk arch
#

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

open token
#

Where are you seeing this error triggered?

silk arch
#

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.

open token
#

I'm a bit confused. Can you share your full code snippet here?

silk arch
#

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

}

open token
#

So this isn't going to work

silk arch
#

Why?

open token
#

Are you only listening for payment_intent.succeeded?

silk arch
#

was used to pay but failed, or canceled, or was succesflly

open token
#

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

silk arch
#

I will try.

#

Thank you.

silk arch
#

Yes, no more errors.

#

Thank you.

#

Can you give me an out-of-stripe advice?

marsh lodge
#

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

silk arch
#

nevermind, I fixed it.

#

Thank you, xoxo! Good nigght/day

marsh lodge
#

Glad to hear! Have a good day yourself!

silk arch
#

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;```
marsh lodge
#

Do you have the event ID for the event you saw that error on?

silk arch
#

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

marsh lodge
#

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.

silk arch
#

Neither the exp or brand

#

"id": "evt_3KwVLFLKPu9R0yzS1H8j8gtH",

marsh lodge
#

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

silk arch
#

For any type of event?

marsh lodge
#

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.

silk arch
#
$payment_intent = $stripe->paymentIntents->retrieve($intent_id,
  ['expand' => ['payment_method']]

);
#

Couldn't I make something like

#

$cardbrand = $payment_intent['payment_method']['brand'] ?

marsh lodge
silk arch
#

instead of

#

$brand = $event->data->card->brand;

marsh lodge
#

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

silk arch
#

Just finished testing.

#

Works fine.

#

Thank you.

#

thread can be archived