Problem/Motivation

I've noticed that the "authorized" and "completed" dates are being displayed as "12/31/1969 - 19:33" for all of my completed orders. The value I see in my database for each of those dates is "2022", which doesn't correspond to the actual time value for the transaction. The issue appears to be that the response from Square returns formatted dates (like "2022-08-06T17:14:42.283Z") for the values of authorized_at and captured_at, instead of Unix time stamp values.

Steps to reproduce

Process an order.
Display the payment summary.

Proposed resolution

Convert the date-time values returned from Square to Unix time stamp values and store the converted values with the payment transaction. Would this work (in file src/Plugin/Commerce/PaymentGateway/Square.php)?

294          $payment->setAuthorizedTime(strtotime($payment_response->getPayment()->getCreatedAt()));
295          if ($capture) {
296            $payment->setCompletedTime(strtotime($payment_response->getPayment()->getCreatedAt()));
297          }
298          else {
299            $expires = $this->time->getRequestTime() + (3600 * 24 * 6) - 5;
300            $payment->setExpiresTime($expires);
301          }

Comments

sah62 created an issue. See original summary.

sah62’s picture

StatusFileSize
new1.01 KB

I've been running the attached patch for a while now and it seems to correct the problem.

sah62’s picture

Status: Active » Needs review
hardik_patel_12’s picture

Thanks, @sah62 for the patch.

The patch at #2 looks fine to me and it's working fine for new orders.

msupko’s picture

StatusFileSize
new928 bytes

I'm not really sure we need to set these values at all. If we don't call these methods, Commerce will automatically set these timestamps for us. Here's a patch that just removes this logic.

jsacksick’s picture

Yes, we shouldn't be setting those values:

Payment::presave() has the following code:

 
 if ($state == 'authorization' && $original_state != 'authorization') {
      if (empty($this->getAuthorizedTime())) {
        $this->setAuthorizedTime(\Drupal::time()->getRequestTime());
      }
    }
    if ($state == 'completed' && $original_state != 'completed') {
      if (empty($this->getCompletedTime())) {
        $this->setCompletedTime(\Drupal::time()->getRequestTime());
      }
    }

  • jsacksick committed f67445ae on 8.x-1.x
    Issue #3302231 by sah62, msupko, jsacksick: Invalid Payment Authorized...
jsacksick’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.