This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from ohmybrew/76-multi-plans
Multi Billing Plan Support
- Loading branch information
Showing
39 changed files
with
985 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace OhMyBrew\ShopifyApp\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Plan extends Model | ||
{ | ||
// Types of plans | ||
const PLAN_RECURRING = 1; | ||
const PLAN_ONETIME = 2; | ||
|
||
/** | ||
* The attributes that should be casted to native types. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'type' => 'int', | ||
'test' => 'bool', | ||
'on_install' => 'bool', | ||
'capped_amount' => 'float', | ||
'price' => 'float', | ||
]; | ||
|
||
/** | ||
* Get charges. | ||
* | ||
* @return \Illuminate\Database\Eloquent\Collection | ||
*/ | ||
public function charges() | ||
{ | ||
return $this->hasMany('OhMyBrew\ShopifyApp\Models\Charge'); | ||
} | ||
|
||
/** | ||
* Returns the plan type as a string (for API). | ||
* | ||
* @param bool $plural Return the plural form or not. | ||
* | ||
* @return string | ||
*/ | ||
public function typeAsString($plural = false) | ||
{ | ||
$type = null; | ||
switch ($this->type) { | ||
case self::PLAN_ONETIME: | ||
$type = 'application_charge'; | ||
break; | ||
default: | ||
case self::PLAN_RECURRING: | ||
$type = 'recurring_application_charge'; | ||
break; | ||
} | ||
|
||
return $plural ? "{$type}s" : $type; | ||
} | ||
|
||
/** | ||
* Checks if this plan has a trial. | ||
* | ||
* @return bool | ||
*/ | ||
public function hasTrial() | ||
{ | ||
return $this->trial_days !== null && $this->trial_days > 0; | ||
} | ||
|
||
/** | ||
* Checks if this plan should be presented on install. | ||
* | ||
* @return bool | ||
*/ | ||
public function isOnInstall() | ||
{ | ||
return (bool) $this->on_install; | ||
} | ||
|
||
/** | ||
* Checks if the plan is a test. | ||
* | ||
* @return bool | ||
*/ | ||
public function isTest() | ||
{ | ||
return (bool) $this->test; | ||
} | ||
} |
Oops, something went wrong.