Skip to content

Commit

Permalink
Multiple fixes.
Browse files Browse the repository at this point in the history
- Use 'Bearer' as token type.
- Fix set expires_at token field.
- Fix repo - delete token.
  • Loading branch information
mtvbrianking committed Aug 12, 2019
1 parent f73627b commit 4e5b0b0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function up()
$table->increments('id');
$table->text('access_token');
$table->text('refresh_token')->nullable();
$table->string('token_type')->default('access_token');
$table->string('token_type')->default('Bearer');
$table->timestamps();
$table->timestamp('expires_at')->nullable();
$table->timestamp('deleted_at')->nullable();
Expand Down
4 changes: 2 additions & 2 deletions src/Products/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function transact($external_id, $party_id, $amount, $payer_message = '',
$this->client->request('POST', $resource, [
'headers' => [
'X-Reference-Id' => $payment_ref,
'X-Callback-Url' => $this->getClientRedirectUri(),
// 'X-Callback-Url' => $this->getClientRedirectUri(),
'X-Target-Environment' => $this->getEnvironment(),
],
'json' => [
Expand All @@ -173,7 +173,7 @@ public function transact($external_id, $party_id, $amount, $payer_message = '',

return $payment_ref;
} catch (RequestException $ex) {
throw new CollectionRequestException('Unable to transact (request pay).', 0, $ex);
throw new CollectionRequestException('Request to pay transaction - unsuccessful.', 0, $ex);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/Repositories/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Bmatovu\MtnMomo\Repositories;

use Carbon\Carbon;
use Bmatovu\MtnMomo\Models\Token;
use Bmatovu\OAuthNegotiator\Repositories\TokenRepositoryInterface;

Expand All @@ -26,6 +27,9 @@ public function __constructor()
*/
public function create(array $attributes)
{
$attributes['token_type'] = 'Bearer';
$attributes['expires_at'] = Carbon::now()->addSeconds($attributes['expires_in']);

return Token::create($attributes);
}

Expand Down Expand Up @@ -62,6 +66,6 @@ public function update($access_token, array $attributes)
*/
public function delete($access_token)
{
Token::destory($access_token);
Token::where('access_token', $access_token)->delete();
}
}
6 changes: 1 addition & 5 deletions src/Traits/TokenUtilTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ public function isExpired()
return false;
}

if ($this->expires_at->isFuture()) {
return false;
}

return true;
return $this->expires_at->isPast();
}
}

0 comments on commit 4e5b0b0

Please sign in to comment.