Skip to content

Commit

Permalink
ensure correct expires_at timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
njoguamos committed Mar 12, 2024
1 parent 5e42e3b commit 2a1d99c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Commands/PesapalAuthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public function handle(): int
if($response->ok()) {
PesapalToken::create([
'access_token' => $response->json(key: 'token'),
'expires_at' => Carbon::parse(time: $response->json(key: 'expiryDate'), tz: 'UTC')
// The 'expiryDate' is in UTC timezone, so it is first parsed with the UTC timezone.
// Then, the timezone is converted to the application's timezone using the 'tz' method.
'expires_at' => Carbon::parse(time: $response->json(key: 'expiryDate'), tz: 'UTC')->tz(config(key: 'app.timezone'))
]);

$this->comment(string: 'A fresh access token has been retrieved and saved to the database.');
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function getEnvironmentSetUp($app): void
{
config()->set('app.key', 'base64:E3SoAOQeMq0UyI7aBZzBPTSAXqp485oM6xqxOtvKhDA=');
config()->set('database.default', 'testing');
config()->set('app.timezone', 'Africa/Nairobi');
// @see https://developer.pesapal.com/api3-demo-keys.txt
config()->set('pesapal.pesapal_live', false);
config()->set('pesapal.consumer_key', 'qkio1BGGYAXTu2JOfm7XSXNruoZsrqEW');
Expand Down

0 comments on commit 2a1d99c

Please sign in to comment.