Skip to content

Commit

Permalink
Merge pull request #16 from wedevBr/feature/billet
Browse files Browse the repository at this point in the history
Feature/billet
  • Loading branch information
adeildo-jr authored Oct 6, 2023
2 parents 47ba844 + 74f17bc commit beebc82
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Clients/CelcoinBAASBillet.php
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,
]);
}
}
45 changes: 45 additions & 0 deletions src/Rules/BAAS/Billet.php
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'],
];
}
}
37 changes: 37 additions & 0 deletions src/Types/BAAS/Billet.php
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);
}
}
25 changes: 25 additions & 0 deletions src/Types/BAAS/BilletDebtor.php
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);
}
}
18 changes: 18 additions & 0 deletions src/Types/BAAS/BilletDiscount.php
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);
}
}
19 changes: 19 additions & 0 deletions src/Types/BAAS/BilletInstruction.php
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);
}
}
18 changes: 18 additions & 0 deletions src/Types/BAAS/BilletReceiver.php
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);
}
}
20 changes: 20 additions & 0 deletions src/Types/BAAS/BilletSplit.php
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);
}
}
Loading

0 comments on commit beebc82

Please sign in to comment.