From e12acd58053ed6659da6f5a2cfcf3bdef3a14d3a Mon Sep 17 00:00:00 2001 From: Elisei Date: Mon, 29 Jul 2024 10:30:38 -0300 Subject: [PATCH] =?UTF-8?q?Getnet=20=F0=9F=98=8D=20Magento=20-=20Implement?= =?UTF-8?q?a=20x-seller-id=20em=20todos=20os=20cabe=C3=A7alhos=20-=20Corri?= =?UTF-8?q?ge=20a=20formata=C3=A7=C3=A3o=20do=20GUID=20do=20payment=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gateway/Http/Api.php | 2 ++ .../Card/Data/Payment/PaymentDataRequest.php | 25 ++++++++++++++++++- Model/ApiManagement.php | 6 +++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Gateway/Http/Api.php b/Gateway/Http/Api.php index 9f480ab..886a06a 100644 --- a/Gateway/Http/Api.php +++ b/Gateway/Http/Api.php @@ -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; diff --git a/Gateway/Request/Card/Data/Payment/PaymentDataRequest.php b/Gateway/Request/Card/Data/Payment/PaymentDataRequest.php index 9d27a78..1611bad 100644 --- a/Gateway/Request/Card/Data/Payment/PaymentDataRequest.php +++ b/Gateway/Request/Card/Data/Payment/PaymentDataRequest.php @@ -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, @@ -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. * diff --git a/Model/ApiManagement.php b/Model/ApiManagement.php index 42e2809..2dfb549 100644 --- a/Model/ApiManagement.php +++ b/Model/ApiManagement.php @@ -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) { @@ -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; @@ -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;