-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rules attribute to Invoice resource
- Loading branch information
1 parent
dcc71ce
commit 2857de3
Showing
5 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace StarkBank\Invoice; | ||
use StarkCore\Utils\API; | ||
use StarkCore\Utils\Checks; | ||
use StarkCore\Utils\SubResource; | ||
|
||
|
||
class Rule extends SubResource | ||
{ | ||
|
||
public $key; | ||
public $value; | ||
|
||
/** | ||
# Invoice\Rule object | ||
The Invoice\Rule object modifies the behavior of Invoice objects when passed as an argument upon their creation. | ||
## Parameters (required): | ||
- key [string]: Rule to be customized, describes what Invoice behavior will be altered. ex: "allowedTaxIds" | ||
- value [list of string]: Value of the rule. ex: ["012.345.678-90", "45.059.493/0001-73"] | ||
*/ | ||
function __construct(array $params) | ||
{ | ||
$this->key = Checks::checkParam($params, "key"); | ||
$this->value = Checks::checkParam($params, "value"); | ||
|
||
Checks::checkParams($params); | ||
} | ||
|
||
public static function parseRules($rules) { | ||
if (is_null($rules)){ | ||
return null; | ||
} | ||
$parsedRules = []; | ||
foreach($rules as $rule) { | ||
if($rule instanceof Rule) { | ||
array_push($parsedRules, $rule); | ||
continue; | ||
} | ||
$parsedRule = function ($array) { | ||
$ruleMaker = function ($array) { | ||
return new Rule($array); | ||
}; | ||
return API::fromApiJson($ruleMaker, $array); | ||
}; | ||
array_push($parsedRules, $parsedRule($rule)); | ||
} | ||
return $parsedRules; | ||
} | ||
} |
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