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 }
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | fix_payment_timestamps-3302231-5.patch | 928 bytes | msupko |
| #2 | invalid-dates-3302231-2.patch | 1.01 KB | sah62 |
Comments
Comment #2
sah62 commentedI've been running the attached patch for a while now and it seems to correct the problem.
Comment #3
sah62 commentedComment #4
hardik_patel_12 commentedThanks, @sah62 for the patch.
The patch at #2 looks fine to me and it's working fine for new orders.
Comment #5
msupko commentedI'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.
Comment #6
jsacksick commentedYes, we shouldn't be setting those values:
Payment::presave()has the following code:Comment #8
jsacksick commented