-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
267e23c
commit 2f0f6f8
Showing
6 changed files
with
365 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
error_reporting(E_ALL); | ||
ini_set('display_errors', 1); | ||
|
||
require '../vendor/autoload.php'; | ||
|
||
use \ChicoRei\Packages\Cielo\Cielo; | ||
use \ChicoRei\Packages\Cielo\Merchant; | ||
use \ChicoRei\Packages\Cielo\Util; | ||
|
||
$merchant = Merchant::create([ | ||
'id' => 'ID', | ||
'key' => 'KEY', | ||
]); | ||
|
||
$cielo = new Cielo($merchant, true); | ||
|
||
try { | ||
$response = $cielo->cardBin()->query('506775'); | ||
|
||
$arrayResponse = $response->toArray(); | ||
var_dump(Util::cleanArray($arrayResponse)); | ||
} catch (Exception $e) { | ||
echo 'Code: ' . $e->getCode() . PHP_EOL; | ||
echo 'Message: ' . $e->getMessage() . PHP_EOL; | ||
} |
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,51 @@ | ||
<?php | ||
|
||
namespace ChicoRei\Packages\Cielo\Handler; | ||
|
||
use ChicoRei\Packages\Cielo\Client; | ||
use ChicoRei\Packages\Cielo\Exception\CieloAPIException; | ||
use ChicoRei\Packages\Cielo\Exception\CieloClientException; | ||
use ChicoRei\Packages\Cielo\Request\CardBinRequest; | ||
use ChicoRei\Packages\Cielo\Response\CardBinResponse; | ||
use RuntimeException; | ||
|
||
class CardBinHandler | ||
{ | ||
/** | ||
* @var Client | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @param Client $client | ||
*/ | ||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* Query Card Bin | ||
* | ||
* @param string|array|CardBinRequest $payload | ||
* @return CardBinResponse | ||
* @throws CieloAPIException | ||
* @throws CieloClientException | ||
*/ | ||
public function query($payload): CardBinResponse | ||
{ | ||
if (is_string($payload)) { | ||
$payload = CardBinRequest::create(['bin' => $payload]); | ||
} elseif (is_array($payload)) { | ||
$payload = CardBinRequest::create($payload); | ||
} | ||
|
||
if (!$payload instanceof CardBinRequest) { | ||
throw new RuntimeException('Payload must be a string, an array or an instance of CardBinRequest'); | ||
} | ||
|
||
$response = $this->client->sendQueryApiRequest($payload); | ||
|
||
return CardBinResponse::create($response); | ||
} | ||
} |
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,65 @@ | ||
<?php | ||
|
||
namespace ChicoRei\Packages\Cielo\Request; | ||
|
||
class CardBinRequest extends CieloRequest | ||
{ | ||
/** | ||
* Bin | ||
* | ||
* @var string|null | ||
*/ | ||
public $bin; | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getBin(): ?string | ||
{ | ||
return $this->bin; | ||
} | ||
|
||
/** | ||
* @param string|null $bin | ||
* @return CardBinRequest | ||
*/ | ||
public function setBin(?string $bin): CardBinRequest | ||
{ | ||
$this->bin = $bin; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getMethod(): string | ||
{ | ||
return 'GET'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getPath(): string | ||
{ | ||
return sprintf('/1/cardBin/%s', $this->getBin()); | ||
} | ||
|
||
/** | ||
* @return array|null | ||
*/ | ||
public function getPayload(): ?array | ||
{ | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns array representation of object | ||
* | ||
* @return array | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return ['Bin' => $this->getBin()]; | ||
} | ||
} |
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,199 @@ | ||
<?php | ||
|
||
namespace ChicoRei\Packages\Cielo\Response; | ||
|
||
use ChicoRei\Packages\Cielo\CieloObject; | ||
|
||
class CardBinResponse extends CieloObject | ||
{ | ||
/** | ||
* Status | ||
* | ||
* @var string|null | ||
*/ | ||
public $status; | ||
|
||
/** | ||
* Provider | ||
* | ||
* @var string|null | ||
*/ | ||
public $provider; | ||
|
||
/** | ||
* Card Type | ||
* | ||
* @var string|null | ||
*/ | ||
public $cardType; | ||
|
||
/** | ||
* Foreign Card | ||
* | ||
* @var bool|null | ||
*/ | ||
public $foreignCard; | ||
|
||
/** | ||
* Corporate Card | ||
* | ||
* @var bool|null | ||
*/ | ||
public $corporateCard; | ||
|
||
/** | ||
* Issuer | ||
* | ||
* @var string|null | ||
*/ | ||
public $issuer; | ||
|
||
/** | ||
* Issuer Code | ||
* | ||
* @var string|null | ||
*/ | ||
public $issuerCode; | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getStatus(): ?string | ||
{ | ||
return $this->status; | ||
} | ||
|
||
/** | ||
* @param string|null $status | ||
* @return CardBinResponse | ||
*/ | ||
public function setStatus(?string $status): CardBinResponse | ||
{ | ||
$this->status = $status; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getProvider(): ?string | ||
{ | ||
return $this->provider; | ||
} | ||
|
||
/** | ||
* @param string|null $provider | ||
* @return CardBinResponse | ||
*/ | ||
public function setProvider(?string $provider): CardBinResponse | ||
{ | ||
$this->provider = $provider; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getCardType(): ?string | ||
{ | ||
return $this->cardType; | ||
} | ||
|
||
/** | ||
* @param string|null $cardType | ||
* @return CardBinResponse | ||
*/ | ||
public function setCardType(?string $cardType): CardBinResponse | ||
{ | ||
$this->cardType = $cardType; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return bool|null | ||
*/ | ||
public function getForeignCard(): ?bool | ||
{ | ||
return $this->foreignCard; | ||
} | ||
|
||
/** | ||
* @param bool|null $foreignCard | ||
* @return CardBinResponse | ||
*/ | ||
public function setForeignCard(?bool $foreignCard): CardBinResponse | ||
{ | ||
$this->foreignCard = $foreignCard; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return bool|null | ||
*/ | ||
public function getCorporateCard(): ?bool | ||
{ | ||
return $this->corporateCard; | ||
} | ||
|
||
/** | ||
* @param bool|null $corporateCard | ||
* @return CardBinResponse | ||
*/ | ||
public function setCorporateCard(?bool $corporateCard): CardBinResponse | ||
{ | ||
$this->corporateCard = $corporateCard; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getIssuer(): ?string | ||
{ | ||
return $this->issuer; | ||
} | ||
|
||
/** | ||
* @param string|null $issuer | ||
* @return CardBinResponse | ||
*/ | ||
public function setIssuer(?string $issuer): CardBinResponse | ||
{ | ||
$this->issuer = $issuer; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
public function getIssuerCode(): ?string | ||
{ | ||
return $this->issuerCode; | ||
} | ||
|
||
/** | ||
* @param string|null $issuerCode | ||
* @return CardBinResponse | ||
*/ | ||
public function setIssuerCode(?string $issuerCode): CardBinResponse | ||
{ | ||
$this->issuerCode = $issuerCode; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'Status' => $this->getStatus(), | ||
'Provider' => $this->getProvider(), | ||
'CardType' => $this->getCardType(), | ||
'ForeignCard' => $this->getForeignCard(), | ||
'CorporateCard' => $this->getCorporateCard(), | ||
'Issuer' => $this->getIssuer(), | ||
'IssuerCode' => $this->getIssuerCode(), | ||
]; | ||
} | ||
} |