Facebook
From Little Peccary, 2 Years ago, written in PHP.
">

A PHP Error was encountered

Severity: Notice

Message: Trying to access array offset on value of type bool

Filename: view/view.php

Line Number: 33

from

A PHP Error was encountered

Severity: Notice

Message: Trying to access array offset on value of type bool

Filename: view/view.php

Line Number: 33

- view diff
Embed
Download Paste or View Raw
Hits: 142
  1. //Do you mind answering 3 quick problem solving questions here in chat?
  2.  
  3. // Question 1, look at the code below. Pls tell me the bug?
  4.  
  5. $tx_list = Transaction::whereIn('method', Transaction::$retail_types)
  6.                         ->whereStatus('pending')
  7.                         ->where('created_at', '<', date("Y-m-d 14:00:00", strtotime("-3 days")));
  8.  
  9. foreach($tx_list as $tx){
  10.         $service->callbackRetailPaid($tx->xendit_external_id, 'COMPLETED');
  11. }
  12.  
  13. // Answer 1:
  14.  
  15. The problem is in the date comparison in the query, date("Y-m-d 14:00:00", strtotime("-3 days")) function will return date in string but type of created at is timestamp, this is the problem here.
  16.  
  17. /*
  18. Question 2:
  19. Looking at the code above, seems like it gets all transactions that were created 3 days ago....
  20. How can we change that so we get all transactions that were created 3 days ago excluding weekend (saturday, sunday)?
  21. E.g: Transactions that were created on Monday will be picked up Thursday at 2pm,
  22. but Transactions that were created on Friday should be picked up the following Wed at 2pm
  23.  
  24. $tx_list = Transaction::whereIn('method', Transaction::$retail_types)
  25.                         ->whereStatus('pending')
  26.                         ->where('created_at', '<', \Carbon\Carbon::parse(strtotime(now()->subWeekDays(3)->format('Y-m-d 14:00:00')))->timezone('Europe/Amsterdam'));
  27.  
  28. use carbon now instead to create date time 3 days before for comparison
  29.  
  30. foreach($tx_list as $tx){
  31.         $service->callbackRetailPaid($tx->xendit_external_id, 'COMPLETED');
  32. }
  33.  
  34. 3. Bonus: How to only pick up transactions 3 business days ago (excluding weekends and USA public holiday)?
  35. */