Skip to content

Commit

Permalink
Merge pull request #22 from wedevBr/develop
Browse files Browse the repository at this point in the history
Prepare new release
  • Loading branch information
adeildo-jr authored Oct 6, 2023
2 parents beebc82 + 57dbc73 commit d21a6c9
Show file tree
Hide file tree
Showing 16 changed files with 317 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches: [ main, develop ]

jobs:
laravel-tests:
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @adeildo-jr
19 changes: 15 additions & 4 deletions src/Celcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use WeDevBr\Celcoin\Clients\CelcoinDDAUser;
use WeDevBr\Celcoin\Clients\CelcoinDDAWebhooks;
use WeDevBr\Celcoin\Clients\CelcoinElectronicTransactions;
use WeDevBr\Celcoin\Clients\CelcoinKyc;
use WeDevBr\Celcoin\Clients\CelcoinPIXCOB;
use WeDevBr\Celcoin\Clients\CelcoinPIXCOBV;
use WeDevBr\Celcoin\Clients\CelcoinPIXDICT;
Expand All @@ -29,6 +30,7 @@

/**
* Class Celcoin
*
* @package WeDevBr\Celcoin
*/
class Celcoin
Expand Down Expand Up @@ -218,7 +220,7 @@ public static function clientPIXDynamic(?string $mtlsPassphrase = null): Celcoin
* @param string|null $mtlsPassphrase
* @return CelcoinPIXPayment
*/
public static function clientPIXPayment(?string $mtlsPassphrase): CelcoinPIXPayment
public static function clientPIXPayment(?string $mtlsPassphrase = null): CelcoinPIXPayment
{
return new CelcoinPIXPayment($mtlsPassphrase);
}
Expand All @@ -227,7 +229,7 @@ public static function clientPIXPayment(?string $mtlsPassphrase): CelcoinPIXPaym
* @param string|null $mtlsPassphrase
* @return CelcoinPIXReceivement
*/
public static function clientPIXReceivement(?string $mtlsPassphrase): CelcoinPIXReceivement
public static function clientPIXReceivement(?string $mtlsPassphrase = null): CelcoinPIXReceivement
{
return new CelcoinPIXReceivement($mtlsPassphrase);
}
Expand All @@ -236,7 +238,7 @@ public static function clientPIXReceivement(?string $mtlsPassphrase): CelcoinPIX
* @param string|null $mtlsPassphrase
* @return CelcoinPIXReverse
*/
public static function clientPIXReverse(?string $mtlsPassphrase): CelcoinPIXReverse
public static function clientPIXReverse(?string $mtlsPassphrase = null): CelcoinPIXReverse
{
return new CelcoinPIXReverse($mtlsPassphrase);
}
Expand All @@ -245,8 +247,17 @@ public static function clientPIXReverse(?string $mtlsPassphrase): CelcoinPIXReve
* @param string|null $mtlsPassphrase
* @return CelcoinPixWebhooks
*/
public static function clientPixWebhooks(?string $mtlsPassphrase): CelcoinPixWebhooks
public static function clientPixWebhooks(?string $mtlsPassphrase = null): CelcoinPixWebhooks
{
return new CelcoinPixWebhooks($mtlsPassphrase);
}

/**
* @param string|null $mtlsPassphrase
* @return CelcoinKyc
*/
public static function clientKyc(?string $mtlsPassphrase = null): CelcoinKyc
{
return new CelcoinKyc($mtlsPassphrase);
}
}
27 changes: 27 additions & 0 deletions src/Clients/CelcoinKyc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace WeDevBr\Celcoin\Clients;

use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Validator;
use WeDevBr\Celcoin\Common\CelcoinBaseApi;
use WeDevBr\Celcoin\Rules\KYC\CreateKycRule;
use WeDevBr\Celcoin\Types\KYC\CreateKyc;

class CelcoinKyc extends CelcoinBaseApi
{
public const CREATE_KYC_ENDPOINT = '/v1/fileupload';

/**
* @throws RequestException
*/
public function createKyc(CreateKyc $data): array
{
$body = Validator::validate($data->toArray(), CreateKycRule::rules());

return $this->post(
self::CREATE_KYC_ENDPOINT,
$body
);
}
}
17 changes: 13 additions & 4 deletions src/Common/CelcoinBaseApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\RequestException;
use Illuminate\Http\File;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use WeDevBr\Celcoin\Auth\Auth;
Expand Down Expand Up @@ -85,19 +86,25 @@ protected function get(string $endpoint, array|string|null $query = null, $respo
/**
* @throws RequestException
*/
protected function post(string $endpoint, array $body = null)
protected function post(string $endpoint, array $body = [])
{
$token = $this->getToken() ?? Auth::login()->getToken();
$request = Http::withToken($token)
->withHeaders([
'accept' => 'application/json',
'content-type' => 'application/json',
'content-type' => 'application/json'
]);

if ($this->mtlsCert && $this->mtlsKey && $this->mtlsPassphrase) {
$request = $this->setRequestMtls($request);
}

foreach ($body as $field => $document) {
if ($document instanceof File) {
$request->attach($field, $document->getContent(), $document->getFileName());
}
}

return $request->post($this->getFinalUrl($endpoint), $body)
->throw()
->json();
Expand All @@ -109,7 +116,8 @@ protected function post(string $endpoint, array $body = null)
protected function put(
string $endpoint,
?array $body = null,
): mixed {
): mixed
{
$token = $this->getToken() ?? Auth::login()->getToken();
$request = Http::withToken($token)
->withHeaders([
Expand All @@ -133,7 +141,8 @@ protected function patch(
string $endpoint,
?array $body = null,
bool $asJson = false
): mixed {
): mixed
{
$body_format = $asJson ? 'json' : 'form_params';
$token = $this->getToken() ?? Auth::login()->getToken();
$request = Http::withToken($token)
Expand Down
15 changes: 15 additions & 0 deletions src/Enums/KycDocumentEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace WeDevBr\Celcoin\Enums;

enum KycDocumentEnum: string
{
case RG = 'RG';
case CNH = 'CNH';
case RNE = 'RNE';
case CARTAO_CNPJ = 'CARTAO_CNPJ';
case CONTRATO_SOCIAL = 'CONTRATO_SOCIAL';
case BALANCO = 'BALANCO';
case FATURAMENTO = 'FATURAMENTO';
case KYC_EXTERNO = 'KYC_EXTERNO';
}
1 change: 1 addition & 0 deletions src/Facades/CelcoinFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @uses Celcoin::clientPIXReceivement
* @uses Celcoin::clientPIXReverse
* @uses Celcoin::clientPixWebhooks
* @uses Celcoin::clientKyc
*
*/
class CelcoinFacade extends Facade
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/BAAS/Billet.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static function rules(): array
'expirationAfterPayment' => ['boolean'],
'duedate' => ['required', 'date'],
'amount' => ['required', 'decimal:0,2'],
'key' => ['sometimes', 'nullable'],
'key' => ['required'],
'debtor' => ['required', 'array'],
'debtor.name' => ['required'],
'debtor.document' => ['required', 'numeric'],
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/BAAS/RegisterPixKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static function rules()
{
return [
"account" => ['required', 'string'],
"keyType" => ['required', Rule::in([PixKeyTypeEnum::EVP->value])],
"keyType" => ['required', Rule::enum(PixKeyTypeEnum::class)],
"key" => ['required_unless:keyType,EVP', 'string'],
];
}
Expand Down
20 changes: 20 additions & 0 deletions src/Rules/KYC/CreateKycRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace WeDevBr\Celcoin\Rules\KYC;

use Illuminate\Validation\Rule;
use WeDevBr\Celcoin\Enums\KycDocumentEnum;

class CreateKycRule
{
public static function rules(): array
{
return [
'documentnumber' => ['required', 'digits:11,14'],
'filetype' => ['required', Rule::enum(KycDocumentEnum::class)],
'front' => ['required', 'file'],
'verse' => ['sometimes', 'file'],
'cnpj' => ['sometimes', 'same:documentnumber', 'digits:11,14'],
];
}
}
8 changes: 4 additions & 4 deletions src/Types/BillPayments/BillData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class BillData extends Data
{
public int $value;
public int $originalValue;
public int $valueWithDiscount;
public int $valueWithAdditional;
public float $value;
public float $originalValue;
public float $valueWithDiscount;
public float $valueWithAdditional;

public function __construct(array $data = [])
{
Expand Down
42 changes: 42 additions & 0 deletions src/Types/KYC/CreateKyc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace WeDevBr\Celcoin\Types\KYC;

use WeDevBr\Celcoin\Enums\KycDocumentEnum;
use WeDevBr\Celcoin\Types\Data;

class CreateKyc extends Data
{
public string $documentnumber;

public ?string $cnpj;

public KycDocumentEnum $filetype;

public KycDocument $front;

public ?KycDocument $verse = null;

public function __construct(array $data = [])
{
if (empty($data['cnpj']) && strlen($data['documentnumber']) === 14) {
$data['cnpj'] = $data['documentnumber'];
}
parent::__construct($data);
}

public function toArray(): array
{
$array = parent::toArray();

if (!empty($array['front'])) {
$array['front'] = $this->front->file;
}

if ($array['verse']) {
$array['verse'] = $this->verse->file;
}

return $array;
}
}
31 changes: 31 additions & 0 deletions src/Types/KYC/KycDocument.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace WeDevBr\Celcoin\Types\KYC;

use Illuminate\Http\File;
use WeDevBr\Celcoin\Types\Data;

class KycDocument extends Data
{
public string $fileName;
public string $contents;
public File $file;

public function __construct(File $file)
{
$data['contents'] = $file->getContent();
$data['fileName'] = $file->getFilename();
$data['file'] = $file;
parent::__construct($data);
}

public function getContents(): string
{
return $this->contents;
}

public function getFileName(): string
{
return $this->fileName;
}
}
7 changes: 7 additions & 0 deletions tests/Feature/CelcoinClientInstancesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use WeDevBr\Celcoin\Clients\CelcoinDDAUser;
use WeDevBr\Celcoin\Clients\CelcoinDDAWebhooks;
use WeDevBr\Celcoin\Clients\CelcoinElectronicTransactions;
use WeDevBr\Celcoin\Clients\CelcoinKyc;
use WeDevBr\Celcoin\Clients\CelcoinPIXCOB;
use WeDevBr\Celcoin\Clients\CelcoinPIXCOBV;
use WeDevBr\Celcoin\Clients\CelcoinPIXDICT;
Expand Down Expand Up @@ -147,4 +148,10 @@ public function testSuccessCreateInstancePIXDynamic()
$instance = Celcoin::clientPIXDynamic();
$this->assertInstanceOf(CelcoinPIXDynamic::class, $instance);
}

public function testSuccessCreateInstanceKyc()
{
$instance = Celcoin::clientKyc();
$this->assertInstanceOf(CelcoinKyc::class, $instance);
}
}
2 changes: 1 addition & 1 deletion tests/GlobalStubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ final static public function loginResponse(): PromiseInterface
Response::HTTP_OK,
);
}
}
}
Loading

0 comments on commit d21a6c9

Please sign in to comment.