Skip to content

Commit

Permalink
Merge UpStream
Browse files Browse the repository at this point in the history
  • Loading branch information
tonypartridge committed Sep 11, 2023
2 parents 64b65a5 + be145c8 commit eb0500b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: PHP Pipeline

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

strategy:
max-parallel: 2
matrix:
php-versions: ['8.2']

name: PHP ${{ matrix.php-versions }}

steps:
- uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@master
with:
php-version: ${{ matrix.php-versions }}
coverage: xdebug

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
run: ./vendor/bin/pest
15 changes: 14 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@ All notable changes to `Laravel Xero` will be documented in this file.

## Version 1.1.3

- Update keep-alive for multi-tenant use, and storeToken where id when using tenant_id in the class
- Update keep-alive for multi-tenant use, and storeToken where id when using tenant_id in the class

## Version 1.1.4

- Added support for Laravel 10

## Version 1.1.5

- applied fix for returning access token

## Version 1.1.6

- Update Xero.php expiry check to use the accessor instead of expired_in column
- Fixed failing test for getting access token
8 changes: 4 additions & 4 deletions src/Xero.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function connect(): RedirectResponse|Application|Redirector
public function getTokenData(): XeroToken|null
{
if ($this->tenant_id) {
$token = XeroToken::where('id', '=', $this->tenant_id)->first();
$token = XeroToken::where('tenant_id', '=', $this->tenant_id)->first();
} else {
$token = XeroToken::first();
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public function getAccessToken($redirectWhenNotConnected = true): string

$now = now()->addMinutes(5);

if ($token->expires_in < $now) {
if ($token->expires < $now) {
return $this->renewExpiringToken($token);
}

Expand All @@ -172,7 +172,7 @@ public function renewExpiringToken($token)

$resultCode = $this->dopost(self::$tokenUrl, $params);

$this->storeToken($resultCode);
$this->storeToken($resultCode, ['tenant_id' => $token->tenant_id]);

return $resultCode['access_token'];
}
Expand Down Expand Up @@ -245,7 +245,7 @@ protected function storeToken($token, $tenantData = null)
];

if ($this->tenant_id) {
$where = ['id' => $this->tenant_id];
$where = ['tenant_id' => $this->tenant_id];
} elseif ($tenantData !== null) {
$data = array_merge($data, $tenantData);
$where = ['tenant_id' => $data['tenant_id']];
Expand Down
5 changes: 3 additions & 2 deletions tests/XeroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Dcblogdev\Xero\Models\XeroToken;
use Dcblogdev\Xero\Xero;
use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector;
use Illuminate\Support\Facades\Http;

beforeEach(function () {
$this->XeroMock = Mockery::mock(Xero::class);
Expand Down Expand Up @@ -106,7 +106,8 @@
XeroToken::create([
'id' => 0,
'access_token' => '1234',
'expires_in' => now()->addMinutes(15),
'expires_in' => now()->addMinutes(25),
'updated_at' => strtotime('+1 day'),
'scopes' => 'contacts'
]);

Expand Down

0 comments on commit eb0500b

Please sign in to comment.