-
Notifications
You must be signed in to change notification settings - Fork 2
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 #16 from wedevBr/feature/billet
Feature/billet
- Loading branch information
Showing
9 changed files
with
423 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace WeDevBr\Celcoin\Clients; | ||
|
||
use Illuminate\Http\Client\RequestException; | ||
use Illuminate\Support\Facades\Validator; | ||
use WeDevBr\Celcoin\Common\CelcoinBaseApi; | ||
use WeDevBr\Celcoin\Rules\BAAS\Billet as BilletRules; | ||
use WeDevBr\Celcoin\Types\BAAS\Billet; | ||
|
||
class CelcoinBAASBillet extends CelcoinBaseApi | ||
{ | ||
const CREATE_BILLET_URL = '/api-integration-baas-webservice/v1/charge'; | ||
const GET_BILLET_URL = '/api-integration-baas-webservice/v1/charge/%s'; | ||
|
||
/** | ||
* @throws RequestException | ||
*/ | ||
public function createBillet(Billet $billet) | ||
{ | ||
$data = Validator::validate($billet->toArray(), BilletRules::rules()); | ||
return $this->post(self::CREATE_BILLET_URL, $data); | ||
} | ||
|
||
/** | ||
* @throws RequestException | ||
*/ | ||
public function getBillet($transaction_id = null, $external_id = null) | ||
{ | ||
return $this->get(self::GET_BILLET_URL, [ | ||
'transactionId' => $transaction_id, | ||
'externalId' => $external_id, | ||
]); | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
namespace WeDevBr\Celcoin\Rules\BAAS; | ||
|
||
use WeDevBr\Celcoin\Enums\ClientFinalityEnum; | ||
|
||
class Billet | ||
{ | ||
public static function rules(): array | ||
{ | ||
return [ | ||
'externalId' => ['required'], | ||
'merchantCategoryCode' => ['sometimes', 'required'], | ||
'expirationAfterPayment' => ['boolean'], | ||
'duedate' => ['required', 'date'], | ||
'amount' => ['required', 'decimal:0,2'], | ||
'key' => ['sometimes', 'nullable'], | ||
'debtor' => ['required', 'array'], | ||
'debtor.name' => ['required'], | ||
'debtor.document' => ['required', 'numeric'], | ||
'debtor.postalCode' => ['required', 'numeric'], | ||
'debtor.publicArea' => ['required'], | ||
'debtor.number' => ['required', 'numeric'], | ||
'debtor.complement' => ['nullable'], | ||
'debtor.neighborhood' => ['required'], | ||
'debtor.city' => ['required'], | ||
'debtor.state' => ['required'], | ||
'receiver.document' => ['required','numeric'], | ||
'receiver.account' => ['required','numeric'], | ||
'instructions' => ['sometimes', 'array'], | ||
'instructions.discounts' => ['required_with:instructions','array'], | ||
'instructions.discounts.*.amount' => ['nullable','decimal:0,2'], | ||
'instructions.discounts.*.modality' => ['nullable'], | ||
'instructions.discounts.*.limitDate' => ['nullable', 'date'], | ||
'instructions.fine' => ['nullable','decimal:0,2'], | ||
'instructions.interest' => ['nullable','decimal:0,2'], | ||
'split' => ['sometimes', 'array'], | ||
'split.*.account' => ['nullable', 'numeric'], | ||
'split.*.document' => ['nullable', 'numeric'], | ||
'split.*.percent' => ['nullable', 'decimal:0,2'], | ||
'split.*.amount' => ['nullable', 'decimal:0,2'], | ||
'split.*.aggregatePayment' => ['nullable', 'boolean'], | ||
]; | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace WeDevBr\Celcoin\Types\BAAS; | ||
|
||
use WeDevBr\Celcoin\Types\Data; | ||
|
||
class Billet extends Data | ||
{ | ||
public string $externalId; | ||
public ?string $merchantCategoryCode; | ||
public int $expirationAfterPayment; | ||
public string $duedate; | ||
public float $amount; | ||
public ?string $key; | ||
/** | ||
* @var BilletDebtor | ||
*/ | ||
public BilletDebtor $debtor; | ||
/** | ||
* @var BilletReceiver | ||
*/ | ||
public BilletReceiver $receiver; | ||
/** | ||
* @var array<BilletInstruction | null> | ||
*/ | ||
public ?array $instructions; | ||
/** | ||
* @var array<BilletSplit | null> | ||
*/ | ||
public ?array $split; | ||
|
||
|
||
public function __construct(array $data = []) | ||
{ | ||
parent::__construct($data); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace WeDevBr\Celcoin\Types\BAAS; | ||
|
||
use WeDevBr\Celcoin\Enums\ClientFinalityEnum; | ||
use WeDevBr\Celcoin\Types\Data; | ||
use WeDevBr\Celcoin\Types\PIX\Debtor; | ||
|
||
class BilletDebtor extends Data | ||
{ | ||
public string $name; | ||
public string $document; | ||
public string $postalCode; | ||
public string $publicArea; | ||
public string $number; | ||
public ?string $complement; | ||
public string $neighborhood; | ||
public string $city; | ||
public string $state; | ||
|
||
public function __construct(array $data = []) | ||
{ | ||
parent::__construct($data); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace WeDevBr\Celcoin\Types\BAAS; | ||
|
||
use WeDevBr\Celcoin\Types\Data; | ||
|
||
class BilletDiscount extends Data | ||
{ | ||
|
||
public float $amount; | ||
public string $modality; | ||
public string $limitDate; | ||
|
||
public function __construct(array $data = []) | ||
{ | ||
parent::__construct($data); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace WeDevBr\Celcoin\Types\BAAS; | ||
|
||
use WeDevBr\Celcoin\Types\Data; | ||
|
||
class BilletInstruction extends Data | ||
{ | ||
|
||
public ?float $fine; | ||
public ?float $interest; | ||
public ?BilletDiscount $discount; | ||
|
||
public function __construct(array $data = []) | ||
{ | ||
$data['discount'] = new BilletDiscount($data['discount']); | ||
parent::__construct($data); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace WeDevBr\Celcoin\Types\BAAS; | ||
|
||
use WeDevBr\Celcoin\Enums\ClientFinalityEnum; | ||
use WeDevBr\Celcoin\Types\Data; | ||
use WeDevBr\Celcoin\Types\PIX\Debtor; | ||
|
||
class BilletReceiver extends Data | ||
{ | ||
public string $document; | ||
public string $account; | ||
|
||
public function __construct(array $data = []) | ||
{ | ||
parent::__construct($data); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace WeDevBr\Celcoin\Types\BAAS; | ||
|
||
use WeDevBr\Celcoin\Types\Data; | ||
|
||
class BilletSplit extends Data | ||
{ | ||
|
||
public string $account; | ||
public string $document; | ||
public ?float $percent; | ||
public ?float $amount; | ||
public bool $aggregatePayment = false; | ||
|
||
public function __construct(array $data = []) | ||
{ | ||
parent::__construct($data); | ||
} | ||
} |
Oops, something went wrong.