Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SubscriptionRequests trait. #17

Merged
merged 6 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Models/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

use Illuminate\Database\Eloquent\Model;
use Payavel\Subscription\Database\Factories\SubscriptionFactory;
use Payavel\Subscription\Models\Traits\SubscriptionRequests;

class Subscription extends Model
{
use SubscriptionRequests;

/**
* The attributes that aren't mass assignable.
*
Expand Down
30 changes: 30 additions & 0 deletions src/Models/Traits/ConfiguresSubscriptionGateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Payavel\Subscription\Models\Traits;

use Payavel\Subscription\SubscriptionGateway;

trait ConfiguresSubscriptionGateway
{
/**
* The subscription's pre-configured gateway.
*
* @var \Payavel\Subscription\SubscriptionGateway
*/
private $subscriptionGateway;

/**
* Retrieve the subscription's configured gateway.
*
* @return \Payavel\Subscription\SubscriptionGateway
*/
public function getGatewayAttribute()
{
if (! isset($this->subscriptionGateway)) {
$this->subscriptionGateway = (new SubscriptionGateway)
->provider($this->provider_id);;
}

return $this->subscriptionGateway;
}
}
18 changes: 18 additions & 0 deletions src/Models/Traits/SubscriptionRequests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Payavel\Subscription\Models\Traits;

trait SubscriptionRequests
{
use ConfiguresSubscriptionGateway;

/**
* Fetch the Subscription details.
*
* @return \Payavel\Subscription\SubscriptionResponse
*/
public function fetch()
{
return $this->gateway->getAgreement($this);
}
}