Skip to content

Commit

Permalink
Getnet 😍 Magento
Browse files Browse the repository at this point in the history
- Implementa x-seller-id em todos os cabeçalhos
- Corrige a formatação do GUID do payment_id
  • Loading branch information
elisei committed Jul 29, 2024
1 parent 93b13e3 commit e12acd5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Gateway/Http/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,12 @@ public function sendGetRequest($transferObject, $path, $request)

$data = [];
$uri = $this->config->getApiUrl($storeId);
$sellerId = $this->config->getMerchantGatewaySellerId($storeId);
$headers = [
'Authorization' => 'Bearer '.$auth,
'Content-Type' => 'application/json',
'x-transaction-channel-entry' => 'MG',
'x-seller-id' => $sellerId,
];
$uri .= $path;

Expand Down
25 changes: 24 additions & 1 deletion Gateway/Request/Card/Data/Payment/PaymentDataRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ public function build(array $buildSubject)
$method = 'CREDIT_AUTHORIZATION';
}

$paymentId = $this->encrytor->hash($order->getOrderIncrementId(), 0);

$paymentId = $this->convertToGuid($paymentId);

$result[CardInitSchemaDataRequest::DATA][self::PAYMENT] = [
self::PAYMENT_ID => $this->encrytor->hash($order->getOrderIncrementId(), 0),
self::PAYMENT_ID => $paymentId,
self::PAYMENT_METHOD => $method,
self::TRANSACTION_TYPE => $transactionType,
self::NUMBER_INSTALLMENTS => $installment,
Expand All @@ -192,6 +196,25 @@ public function build(array $buildSubject)
return $result;
}

/**
* Convert to Guid.
*
* @param string $hex
*
* @return array
*/
public function convertToGuid($hex) {
if (strlen($hex) === 32 && ctype_xdigit($hex)) {
return substr($hex, 0, 8) . '-' .
substr($hex, 8, 4) . '-' .
substr($hex, 12, 4) . '-' .
substr($hex, 16, 4) . '-' .
substr($hex, 20, 12);
} else {
throw new InvalidArgumentException("O valor fornecido não é um hexadecimal válido de 32 caracteres.");
}
}

/**
* Data for CC.
*
Expand Down
6 changes: 6 additions & 0 deletions Model/ApiManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,12 @@ public function sendPostRequest($path, $request, $additional = null)

$data = [];
$uri = $this->configBase->getApiUrl($storeId);
$sellerId = $this->configBase->getMerchantGatewaySellerId($storeId);
$headers = [
'Authorization' => 'Bearer '.$auth,
'Content-Type' => 'application/json',
'x-transaction-channel-entry' => 'MG',
'x-seller-id' => $sellerId,
];

if ($additional) {
Expand Down Expand Up @@ -283,10 +285,12 @@ public function sendGetByParam($path, $request)

$data = [];
$uri = $this->configBase->getApiUrl($storeId);
$sellerId = $this->configBase->getMerchantGatewaySellerId($storeId);
$headers = [
'Authorization' => 'Bearer '.$auth,
'Content-Type' => 'application/json',
'x-transaction-channel-entry' => 'MG',
'x-seller-id' => $sellerId,
];
$uri .= $path;

Expand Down Expand Up @@ -342,10 +346,12 @@ public function sendGetRequest($path, $request)

$data = [];
$uri = $this->configBase->getApiUrl($storeId);
$sellerId = $this->configBase->getMerchantGatewaySellerId($storeId);
$headers = [
'Authorization' => 'Bearer '.$auth,
'Content-Type' => 'application/json',
'x-transaction-channel-entry' => 'MG',
'x-seller-id' => $sellerId,
];
$uri .= $path;

Expand Down

0 comments on commit e12acd5

Please sign in to comment.