We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 78c4f4af authored by cyattilakiss's avatar cyattilakiss Committed by GitHub

[PW-1782] Use idempotency key only for redirect payment methods (#548)

* Only add idempotency key if payment method is adyen_hpp

* Use transfer headers storing idempotency key
Use idempotency key only for adyen_hpp methods

* Add idempotency key for transactionPayment
parent 1c2f86ca
...@@ -69,8 +69,13 @@ class TransactionAuthorization implements ClientInterface ...@@ -69,8 +69,13 @@ class TransactionAuthorization implements ClientInterface
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject) public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{ {
$request = $transferObject->getBody(); $request = $transferObject->getBody();
$headers = $transferObject->getHeaders();
$requestOptions['idempotencyKey'] = $request['reference']; $requestOptions = [];
if (!empty($headers['idempotencyKey'])) {
$requestOptions['idempotencyKey'] = $headers['idempotencyKey'];
}
// call lib // call lib
$service = new \Adyen\Service\Payment($this->_client); $service = new \Adyen\Service\Payment($this->_client);
......
...@@ -55,6 +55,7 @@ class TransactionPayment implements ClientInterface ...@@ -55,6 +55,7 @@ class TransactionPayment implements ClientInterface
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject) public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{ {
$request = $transferObject->getBody(); $request = $transferObject->getBody();
$headers = $transferObject->getHeaders();
// If the payments call is already done return the request // If the payments call is already done return the request
if (!empty($request['resultCode'])) { if (!empty($request['resultCode'])) {
...@@ -65,7 +66,12 @@ class TransactionPayment implements ClientInterface ...@@ -65,7 +66,12 @@ class TransactionPayment implements ClientInterface
$client = $this->adyenHelper->initializeAdyenClient(); $client = $this->adyenHelper->initializeAdyenClient();
$service = new \Adyen\Service\Checkout($client); $service = new \Adyen\Service\Checkout($client);
$requestOptions['idempotencyKey'] = $request['reference'];
$requestOptions = [];
if (!empty($headers['idempotencyKey'])) {
$requestOptions['idempotencyKey'] = $headers['idempotencyKey'];
}
try { try {
$response = $service->payments($request, $requestOptions); $response = $service->payments($request, $requestOptions);
......
...@@ -52,8 +52,14 @@ class TransferFactory implements TransferFactoryInterface ...@@ -52,8 +52,14 @@ class TransferFactory implements TransferFactoryInterface
*/ */
public function create(array $request) public function create(array $request)
{ {
return $this->transferBuilder if (!empty($request['headers'])) {
->setBody($request) $this->transferBuilder->setHeaders($request['headers']);
}
$transfer = $this->transferBuilder
->setBody($request['body'])
->build(); ->build();
return $transfer;
} }
} }
...@@ -61,6 +61,8 @@ class AddressDataBuilder implements BuilderInterface ...@@ -61,6 +61,8 @@ class AddressDataBuilder implements BuilderInterface
$billingAddress = $order->getBillingAddress(); $billingAddress = $order->getBillingAddress();
$shippingAddress = $order->getShippingAddress(); $shippingAddress = $order->getShippingAddress();
return $this->adyenRequestsHelper->buildAddressData([], $billingAddress, $shippingAddress); $request['body'] = $this->adyenRequestsHelper->buildAddressData([], $billingAddress, $shippingAddress);
return $request;
} }
} }
...@@ -55,12 +55,12 @@ class ApplePayAuthorizationDataBuilder implements BuilderInterface ...@@ -55,12 +55,12 @@ class ApplePayAuthorizationDataBuilder implements BuilderInterface
public function build(array $buildSubject) public function build(array $buildSubject)
{ {
$request = []; $requestBody = [];
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$token = $payment->getAdditionalInformation('token'); $token = $payment->getAdditionalInformation('token');
$request['paymentMethod']['type'] = 'applepay'; $requestBody['paymentMethod']['type'] = 'applepay';
// get payment data // get payment data
if ($token) { if ($token) {
...@@ -68,7 +68,7 @@ class ApplePayAuthorizationDataBuilder implements BuilderInterface ...@@ -68,7 +68,7 @@ class ApplePayAuthorizationDataBuilder implements BuilderInterface
$paymentData = $parsedToken->token->paymentData; $paymentData = $parsedToken->token->paymentData;
try { try {
$paymentData = base64_encode(json_encode($paymentData)); $paymentData = base64_encode(json_encode($paymentData));
$request['paymentMethod']['applepay.token'] = $paymentData; $requestBody['paymentMethod']['applepay.token'] = $paymentData;
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->_adyenLogger->addAdyenDebug("exception: " . $exception->getMessage()); $this->_adyenLogger->addAdyenDebug("exception: " . $exception->getMessage());
} }
...@@ -76,6 +76,8 @@ class ApplePayAuthorizationDataBuilder implements BuilderInterface ...@@ -76,6 +76,8 @@ class ApplePayAuthorizationDataBuilder implements BuilderInterface
$this->_adyenLogger->addAdyenDebug("PaymentToken is empty"); $this->_adyenLogger->addAdyenDebug("PaymentToken is empty");
} }
$request['body'] = $requestBody;
return $request; return $request;
} }
} }
...@@ -52,6 +52,7 @@ class BrowserInfoDataBuilder implements BuilderInterface ...@@ -52,6 +52,7 @@ class BrowserInfoDataBuilder implements BuilderInterface
*/ */
public function build(array $buildSubject) public function build(array $buildSubject)
{ {
return $this->adyenRequestsHelper->buildBrowserData(); $request['body'] = $this->adyenRequestsHelper->buildBrowserData();
return $request;
} }
} }
...@@ -60,9 +60,11 @@ class CancelDataBuilder implements BuilderInterface ...@@ -60,9 +60,11 @@ class CancelDataBuilder implements BuilderInterface
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$pspReference = $payment->getCcTransId(); $pspReference = $payment->getCcTransId();
return [ $request['body'] = [
"reference" => $order->getOrderIncrementId(), "reference" => $order->getOrderIncrementId(),
"originalReference" => $pspReference "originalReference" => $pspReference
]; ];
return $request;
} }
} }
...@@ -67,7 +67,7 @@ class CaptureDataBuilder implements BuilderInterface ...@@ -67,7 +67,7 @@ class CaptureDataBuilder implements BuilderInterface
$amount = $this->adyenHelper->formatAmount($amount, $currency); $amount = $this->adyenHelper->formatAmount($amount, $currency);
$modificationAmount = ['currency' => $currency, 'value' => $amount]; $modificationAmount = ['currency' => $currency, 'value' => $amount];
$request = [ $requestBody = [
"modificationAmount" => $modificationAmount, "modificationAmount" => $modificationAmount,
"reference" => $payment->getOrder()->getIncrementId(), "reference" => $payment->getOrder()->getIncrementId(),
"originalReference" => $pspReference "originalReference" => $pspReference
...@@ -79,9 +79,11 @@ class CaptureDataBuilder implements BuilderInterface ...@@ -79,9 +79,11 @@ class CaptureDataBuilder implements BuilderInterface
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) { if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) {
$openInvoiceFields = $this->getOpenInvoiceData($payment); $openInvoiceFields = $this->getOpenInvoiceData($payment);
$request["additionalData"] = $openInvoiceFields; $requestBody["additionalData"] = $openInvoiceFields;
} }
$request['body'] = $requestBody;
return $request; return $request;
} }
......
...@@ -42,7 +42,7 @@ class CcAuthorizationDataBuilder implements BuilderInterface ...@@ -42,7 +42,7 @@ class CcAuthorizationDataBuilder implements BuilderInterface
if ($response = $payment->getAdditionalInformation("paymentsResponse")) { if ($response = $payment->getAdditionalInformation("paymentsResponse")) {
// the payments response needs to be passed to the next process because after this point we don't have // the payments response needs to be passed to the next process because after this point we don't have
// access to the payment object therefore to the additionalInformation array // access to the payment object therefore to the additionalInformation array
$request = $response; $request['body'] = $response;
// Remove from additional data // Remove from additional data
$payment->unsAdditionalInformation("paymentsResponse"); $payment->unsAdditionalInformation("paymentsResponse");
} else { } else {
......
...@@ -61,24 +61,25 @@ class CcBackendAuthorizationDataBuilder implements BuilderInterface ...@@ -61,24 +61,25 @@ class CcBackendAuthorizationDataBuilder implements BuilderInterface
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */ /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$request = []; $order = $paymentDataObject->getOrder();
$storeId = $order->getStoreId();
$requestBody = [];
// If ccType is set use this. For bcmc you need bcmc otherwise it will fail // If ccType is set use this. For bcmc you need bcmc otherwise it will fail
$request['paymentMethod']['type'] = 'scheme'; $requestBody['paymentMethod']['type'] = 'scheme';
if ($cardNumber = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_CREDIT_CARD_NUMBER)) { if ($cardNumber = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_CREDIT_CARD_NUMBER)) {
$request['paymentMethod']['encryptedCardNumber'] = $cardNumber; $requestBody['paymentMethod']['encryptedCardNumber'] = $cardNumber;
} }
if ($expiryMonth = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_MONTH)) { if ($expiryMonth = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_MONTH)) {
$request['paymentMethod']['encryptedExpiryMonth'] = $expiryMonth; $requestBody['paymentMethod']['encryptedExpiryMonth'] = $expiryMonth;
} }
if ($expiryYear = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_YEAR)) { if ($expiryYear = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_EXPIRY_YEAR)) {
$request['paymentMethod']['encryptedExpiryYear'] = $expiryYear; $requestBody['paymentMethod']['encryptedExpiryYear'] = $expiryYear;
} }
if ($holderName = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::HOLDER_NAME)) { if ($holderName = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::HOLDER_NAME)) {
$request['paymentMethod']['holderName'] = $holderName; $requestBody['paymentMethod']['holderName'] = $holderName;
} }
if ($securityCode = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_SECURITY_CODE)) { if ($securityCode = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_SECURITY_CODE)) {
$request['paymentMethod']['encryptedSecurityCode'] = $securityCode; $requestBody['paymentMethod']['encryptedSecurityCode'] = $securityCode;
} }
// Remove from additional data // Remove from additional data
$payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_CREDIT_CARD_NUMBER); $payment->unsAdditionalInformation(AdyenCcDataAssignObserver::ENCRYPTED_CREDIT_CARD_NUMBER);
...@@ -89,23 +90,25 @@ class CcBackendAuthorizationDataBuilder implements BuilderInterface ...@@ -89,23 +90,25 @@ class CcBackendAuthorizationDataBuilder implements BuilderInterface
/** /**
* On Backend always use MOTO * On Backend always use MOTO
*/ */
$request['shopperInteraction'] = "Moto"; $requestBody['shopperInteraction'] = "Moto";
// if installments is set add it into the request // if installments is set add it into the request
if ($payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS) && if ($payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS) &&
$payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS) > 0 $payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS) > 0
) { ) {
$request['installments']['value'] = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS); $requestBody['installments']['value'] = $payment->getAdditionalInformation(AdyenCcDataAssignObserver::NUMBER_OF_INSTALLMENTS);
} }
// Flow for Billing agreements, for Vault check VaultDataBuilder // Flow for Billing agreements, for Vault check VaultDataBuilder
if (!$this->adyenHelper->isCreditCardVaultEnabled()) { if (!$this->adyenHelper->isCreditCardVaultEnabled()) {
if ($payment->getAdditionalInformation(AdyenCcDataAssignObserver::STORE_CC)) { if ($payment->getAdditionalInformation(AdyenCcDataAssignObserver::STORE_CC)) {
$request['enableRecurring'] = true; $requestBody['enableRecurring'] = true;
} else { } else {
$request['enableRecurring'] = false; $requestBody['enableRecurring'] = false;
} }
} }
$request['body'] = $requestBody;
return $request; return $request;
} }
} }
...@@ -69,31 +69,31 @@ class CheckoutDataBuilder implements BuilderInterface ...@@ -69,31 +69,31 @@ class CheckoutDataBuilder implements BuilderInterface
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$order = $payment->getOrder(); $order = $payment->getOrder();
$storeId = $order->getStoreId(); $storeId = $order->getStoreId();
$request = []; $requestBody = [];
// do not send email // do not send email
$order->setCanSendNewEmailFlag(false); $order->setCanSendNewEmailFlag(false);
$request['paymentMethod']['type'] = $payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE); $requestBody['paymentMethod']['type'] = $payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE);
// Additional data for payment methods with issuer list // Additional data for payment methods with issuer list
if ($payment->getAdditionalInformation(AdyenHppDataAssignObserver::ISSUER_ID)) { if ($payment->getAdditionalInformation(AdyenHppDataAssignObserver::ISSUER_ID)) {
$request['paymentMethod']['issuer'] = $payment->getAdditionalInformation(AdyenHppDataAssignObserver::ISSUER_ID); $requestBody['paymentMethod']['issuer'] = $payment->getAdditionalInformation(AdyenHppDataAssignObserver::ISSUER_ID);
} }
$request['returnUrl'] = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK) . 'adyen/process/result'; $requestBody['returnUrl'] = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK) . 'adyen/process/result';
// Additional data for ACH // Additional data for ACH
if ($payment->getAdditionalInformation("bankAccountNumber")) { if ($payment->getAdditionalInformation("bankAccountNumber")) {
$request['bankAccount']['bankAccountNumber'] = $payment->getAdditionalInformation("bankAccountNumber"); $requestBody['bankAccount']['bankAccountNumber'] = $payment->getAdditionalInformation("bankAccountNumber");
} }
if ($payment->getAdditionalInformation("bankLocationId")) { if ($payment->getAdditionalInformation("bankLocationId")) {
$request['bankAccount']['bankLocationId'] = $payment->getAdditionalInformation("bankLocationId"); $requestBody['bankAccount']['bankLocationId'] = $payment->getAdditionalInformation("bankLocationId");
} }
if ($payment->getAdditionalInformation("bankAccountOwnerName")) { if ($payment->getAdditionalInformation("bankAccountOwnerName")) {
$request['bankAccount']['ownerName'] = $payment->getAdditionalInformation("bankAccountOwnerName"); $requestBody['bankAccount']['ownerName'] = $payment->getAdditionalInformation("bankAccountOwnerName");
} }
// Additional data for open invoice payment // Additional data for open invoice payment
...@@ -101,31 +101,31 @@ class CheckoutDataBuilder implements BuilderInterface ...@@ -101,31 +101,31 @@ class CheckoutDataBuilder implements BuilderInterface
$order->setCustomerGender(\Adyen\Payment\Model\Gender::getMagentoGenderFromAdyenGender( $order->setCustomerGender(\Adyen\Payment\Model\Gender::getMagentoGenderFromAdyenGender(
$payment->getAdditionalInformation("gender")) $payment->getAdditionalInformation("gender"))
); );
$request['paymentMethod']['personalDetails']['gender'] = $payment->getAdditionalInformation("gender"); $requestBody['paymentMethod']['personalDetails']['gender'] = $payment->getAdditionalInformation("gender");
} }
if ($payment->getAdditionalInformation("dob")) { if ($payment->getAdditionalInformation("dob")) {
$order->setCustomerDob($payment->getAdditionalInformation("dob")); $order->setCustomerDob($payment->getAdditionalInformation("dob"));
$request['paymentMethod']['personalDetails']['dateOfBirth']= $this->adyenHelper->formatDate($payment->getAdditionalInformation("dob"), 'Y-m-d') ; $requestBody['paymentMethod']['personalDetails']['dateOfBirth']= $this->adyenHelper->formatDate($payment->getAdditionalInformation("dob"), 'Y-m-d') ;
} }
if ($payment->getAdditionalInformation("telephone")) { if ($payment->getAdditionalInformation("telephone")) {
$order->getBillingAddress()->setTelephone($payment->getAdditionalInformation("telephone")); $order->getBillingAddress()->setTelephone($payment->getAdditionalInformation("telephone"));
$request['paymentMethod']['personalDetails']['telephoneNumber']= $payment->getAdditionalInformation("telephone"); $requestBody['paymentMethod']['personalDetails']['telephoneNumber']= $payment->getAdditionalInformation("telephone");
} }
if ($payment->getAdditionalInformation("ssn")) { if ($payment->getAdditionalInformation("ssn")) {
$request['paymentMethod']['personalDetails']['socialSecurityNumber']= $payment->getAdditionalInformation("ssn"); $requestBody['paymentMethod']['personalDetails']['socialSecurityNumber']= $payment->getAdditionalInformation("ssn");
} }
// Additional data for sepa direct debit // Additional data for sepa direct debit
if ($payment->getAdditionalInformation("ownerName")) { if ($payment->getAdditionalInformation("ownerName")) {
$request['paymentMethod']['sepa.ownerName'] = $payment->getAdditionalInformation("ownerName"); $requestBody['paymentMethod']['sepa.ownerName'] = $payment->getAdditionalInformation("ownerName");
} }
if ($payment->getAdditionalInformation("ibanNumber")) { if ($payment->getAdditionalInformation("ibanNumber")) {
$request['paymentMethod']['sepa.ibanNumber'] = $payment->getAdditionalInformation("ibanNumber"); $requestBody['paymentMethod']['sepa.ibanNumber'] = $payment->getAdditionalInformation("ibanNumber");
} }
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod( if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod(
...@@ -137,27 +137,27 @@ class CheckoutDataBuilder implements BuilderInterface ...@@ -137,27 +137,27 @@ class CheckoutDataBuilder implements BuilderInterface
) )
) { ) {
$openInvoiceFields = $this->getOpenInvoiceData($order); $openInvoiceFields = $this->getOpenInvoiceData($order);
$request = array_merge($request, $openInvoiceFields); $requestBody = array_merge($requestBody, $openInvoiceFields);
} }
// Ratepay specific Fingerprint // Ratepay specific Fingerprint
if ($payment->getAdditionalInformation("df_value") && $this->adyenHelper->isPaymentMethodRatepayMethod( if ($payment->getAdditionalInformation("df_value") && $this->adyenHelper->isPaymentMethodRatepayMethod(
$payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE) $payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE)
)) { )) {
$request['deviceFingerprint'] = $payment->getAdditionalInformation("df_value"); $requestBody['deviceFingerprint'] = $payment->getAdditionalInformation("df_value");
} }
//Boleto data //Boleto data
if ($payment->getAdditionalInformation("social_security_number")) { if ($payment->getAdditionalInformation("social_security_number")) {
$request['socialSecurityNumber'] = $payment->getAdditionalInformation("social_security_number"); $requestBody['socialSecurityNumber'] = $payment->getAdditionalInformation("social_security_number");
} }
if ($payment->getAdditionalInformation("firstname")) { if ($payment->getAdditionalInformation("firstname")) {
$request['shopperName']['firstName'] = $payment->getAdditionalInformation("firstname"); $requestBody['shopperName']['firstName'] = $payment->getAdditionalInformation("firstname");
} }
if ($payment->getAdditionalInformation("lastName")) { if ($payment->getAdditionalInformation("lastName")) {
$request['shopperName']['lastName'] = $payment->getAdditionalInformation("lastName"); $requestBody['shopperName']['lastName'] = $payment->getAdditionalInformation("lastName");
} }
if ($payment->getMethod() == \Adyen\Payment\Model\Ui\AdyenBoletoConfigProvider::CODE) { if ($payment->getMethod() == \Adyen\Payment\Model\Ui\AdyenBoletoConfigProvider::CODE) {
...@@ -165,11 +165,11 @@ class CheckoutDataBuilder implements BuilderInterface ...@@ -165,11 +165,11 @@ class CheckoutDataBuilder implements BuilderInterface
$boletoTypes = explode(',', $boletoTypes); $boletoTypes = explode(',', $boletoTypes);
if (count($boletoTypes) == 1) { if (count($boletoTypes) == 1) {
$request['selectedBrand'] = $boletoTypes[0]; $requestBody['selectedBrand'] = $boletoTypes[0];
$request['paymentMethod']['type'] = $boletoTypes[0]; $requestBody['paymentMethod']['type'] = $boletoTypes[0];
} else { } else {
$request['selectedBrand'] = $payment->getAdditionalInformation("boleto_type"); $requestBody['selectedBrand'] = $payment->getAdditionalInformation("boleto_type");
$request['paymentMethod']['type'] = $payment->getAdditionalInformation("boleto_type"); $requestBody['paymentMethod']['type'] = $payment->getAdditionalInformation("boleto_type");
} }
$deliveryDays = (int)$this->adyenHelper->getAdyenBoletoConfigData("delivery_days", $storeId); $deliveryDays = (int)$this->adyenHelper->getAdyenBoletoConfigData("delivery_days", $storeId);
...@@ -186,10 +186,13 @@ class CheckoutDataBuilder implements BuilderInterface ...@@ -186,10 +186,13 @@ class CheckoutDataBuilder implements BuilderInterface
) )
); );
$request['deliveryDate'] = $deliveryDate; $requestBody['deliveryDate'] = $deliveryDate;
$order->setCanSendNewEmailFlag(true); $order->setCanSendNewEmailFlag(true);
} }
$request['body'] = $requestBody;
return $request; return $request;
} }
......
...@@ -62,6 +62,8 @@ class CustomerDataBuilder implements BuilderInterface ...@@ -62,6 +62,8 @@ class CustomerDataBuilder implements BuilderInterface
$billingAddress = $order->getBillingAddress(); $billingAddress = $order->getBillingAddress();
$storeId = $order->getStoreId(); $storeId = $order->getStoreId();
return $this->adyenRequestsHelper->buildCustomerData([], $customerId, $billingAddress, $storeId, $payment); $request['body'] = $this->adyenRequestsHelper->buildCustomerData([], $customerId, $billingAddress, $storeId, $payment);
return $request;
} }
} }
...@@ -60,6 +60,8 @@ class CustomerIpDataBuilder implements BuilderInterface ...@@ -60,6 +60,8 @@ class CustomerIpDataBuilder implements BuilderInterface
$shopperIp = $order-> getXForwardedFor(); $shopperIp = $order-> getXForwardedFor();
} }
return $this->adyenRequestsHelper->buildCustomerIpData([], $shopperIp); $request['body'] = $this->adyenRequestsHelper->buildCustomerIpData([], $shopperIp);
return $request;
} }
} }
...@@ -55,17 +55,17 @@ class GooglePayAuthorizationDataBuilder implements BuilderInterface ...@@ -55,17 +55,17 @@ class GooglePayAuthorizationDataBuilder implements BuilderInterface
public function build(array $buildSubject) public function build(array $buildSubject)
{ {
$request = []; $requestBody = [];
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$token = $payment->getAdditionalInformation('token'); $token = $payment->getAdditionalInformation('token');
$request['paymentMethod']['type'] = 'paywithgoogle'; $requestBody['paymentMethod']['type'] = 'paywithgoogle';
// get payment data // get payment data
if ($token) { if ($token) {
$parsedToken = json_decode($token); $parsedToken = json_decode($token);
try { try {
$request['paymentMethod']['paywithgoogle.token'] = $parsedToken; $requestBody['paymentMethod']['paywithgoogle.token'] = $parsedToken;
} catch (\Exception $exception) { } catch (\Exception $exception) {
$this->adyenLogger->addAdyenDebug("exception: " . $exception->getMessage()); $this->adyenLogger->addAdyenDebug("exception: " . $exception->getMessage());
} }
...@@ -73,6 +73,8 @@ class GooglePayAuthorizationDataBuilder implements BuilderInterface ...@@ -73,6 +73,8 @@ class GooglePayAuthorizationDataBuilder implements BuilderInterface
$this->adyenLogger->addAdyenDebug("PaymentToken is empty"); $this->adyenLogger->addAdyenDebug("PaymentToken is empty");
} }
$request['body'] = $requestBody;
return $request; return $request;
} }
} }
...@@ -56,6 +56,8 @@ class MerchantAccountDataBuilder implements BuilderInterface ...@@ -56,6 +56,8 @@ class MerchantAccountDataBuilder implements BuilderInterface
$storeId = $order->getStoreId(); $storeId = $order->getStoreId();
$method = $payment->getMethod(); $method = $payment->getMethod();
return $this->adyenRequestsHelper->buildMerchantAccountData([], $method, $storeId); $request['body'] = $this->adyenRequestsHelper->buildMerchantAccountData([], $method, $storeId);
return $request;
} }
} }
...@@ -60,7 +60,12 @@ class PaymentDataBuilder implements BuilderInterface ...@@ -60,7 +60,12 @@ class PaymentDataBuilder implements BuilderInterface
$currencyCode = $fullOrder->getOrderCurrencyCode(); $currencyCode = $fullOrder->getOrderCurrencyCode();
$amount = $fullOrder->getGrandTotal(); $amount = $fullOrder->getGrandTotal();
$reference = $order->getOrderIncrementId(); $reference = $order->getOrderIncrementId();
$paymentMethod = $payment->getMethod();
return $this->adyenRequestsHelper->buildPaymentData([], $amount, $currencyCode, $reference); $request['body'] = $this->adyenRequestsHelper->buildPaymentData([], $amount, $currencyCode, $reference, $paymentMethod);
$request['headers'] = $this->adyenRequestsHelper->addIdempotencyKey([], $paymentMethod, $reference);
return $request;
} }
} }
...@@ -38,11 +38,13 @@ class PosCloudBuilder implements BuilderInterface ...@@ -38,11 +38,13 @@ class PosCloudBuilder implements BuilderInterface
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
return [ $request['body'] = [
"response" => $payment->getAdditionalInformation("terminalResponse"), "response" => $payment->getAdditionalInformation("terminalResponse"),
"serviceID" => $payment->getAdditionalInformation("serviceID"), "serviceID" => $payment->getAdditionalInformation("serviceID"),
"initiateDate" => $payment->getAdditionalInformation("initiateDate"), "initiateDate" => $payment->getAdditionalInformation("initiateDate"),
"terminalID" => $payment->getAdditionalInformation("terminal_id") "terminalID" => $payment->getAdditionalInformation("terminal_id")
]; ];
return $request;
} }
} }
...@@ -65,6 +65,8 @@ class RecurringDataBuilder implements BuilderInterface ...@@ -65,6 +65,8 @@ class RecurringDataBuilder implements BuilderInterface
$storeId = $payment->getOrder()->getStoreId(); $storeId = $payment->getOrder()->getStoreId();
$areaCode = $this->appState->getAreaCode(); $areaCode = $this->appState->getAreaCode();
return $this->adyenRequestsHelper->buildRecurringData([], $areaCode, $storeId, $payment); $request['body'] = $this->adyenRequestsHelper->buildRecurringData([], $areaCode, $storeId, $payment);
return $request;
} }
} }
...@@ -33,17 +33,20 @@ class RecurringVaultDataBuilder implements BuilderInterface ...@@ -33,17 +33,20 @@ class RecurringVaultDataBuilder implements BuilderInterface
*/ */
public function build(array $buildSubject) public function build(array $buildSubject)
{ {
$result = []; $requestBody = [];
$recurring = ['contract' => \Adyen\Payment\Model\RecurringType::RECURRING]; $recurring = ['contract' => \Adyen\Payment\Model\RecurringType::RECURRING];
$result['recurring'] = $recurring; $requestBody['recurring'] = $recurring;
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */ /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$extensionAttributes = $payment->getExtensionAttributes(); $extensionAttributes = $payment->getExtensionAttributes();
$paymentToken = $extensionAttributes->getVaultPaymentToken(); $paymentToken = $extensionAttributes->getVaultPaymentToken();
$result['selectedRecurringDetailReference'] = $paymentToken->getGatewayToken(); $requestBody['selectedRecurringDetailReference'] = $paymentToken->getGatewayToken();
$result['shopperInteraction'] = 'ContAuth'; $requestBody['shopperInteraction'] = 'ContAuth';
return $result;
$request['body'] = $requestBody;
return $request;
} }
} }
...@@ -107,7 +107,7 @@ class RefundDataBuilder implements BuilderInterface ...@@ -107,7 +107,7 @@ class RefundDataBuilder implements BuilderInterface
} }
// loop over payment methods and refund them all // loop over payment methods and refund them all
$result = []; $requestBody = [];
foreach ($orderPaymentCollection as $splitPayment) { foreach ($orderPaymentCollection as $splitPayment) {
// could be that not all the split payments need a refund // could be that not all the split payments need a refund
if ($amount > 0) { if ($amount > 0) {
...@@ -140,7 +140,7 @@ class RefundDataBuilder implements BuilderInterface ...@@ -140,7 +140,7 @@ class RefundDataBuilder implements BuilderInterface
'value' => $this->adyenHelper->formatAmount($modificationAmount, $currency) 'value' => $this->adyenHelper->formatAmount($modificationAmount, $currency)
]; ];
$result[] = [ $requestBody[] = [
"modificationAmount" => $modificationAmountObject, "modificationAmount" => $modificationAmountObject,
"reference" => $payment->getOrder()->getIncrementId(), "reference" => $payment->getOrder()->getIncrementId(),
"originalReference" => $splitPayment->getPspreference(), "originalReference" => $splitPayment->getPspreference(),
...@@ -153,7 +153,7 @@ class RefundDataBuilder implements BuilderInterface ...@@ -153,7 +153,7 @@ class RefundDataBuilder implements BuilderInterface
$amount = $this->adyenHelper->formatAmount($amount, $currency); $amount = $this->adyenHelper->formatAmount($amount, $currency);
$modificationAmount = ['currency' => $currency, 'value' => $amount]; $modificationAmount = ['currency' => $currency, 'value' => $amount];
$result = [ $requestBody = [
[ [
"modificationAmount" => $modificationAmount, "modificationAmount" => $modificationAmount,
"reference" => $payment->getOrder()->getIncrementId(), "reference" => $payment->getOrder()->getIncrementId(),
...@@ -170,11 +170,13 @@ class RefundDataBuilder implements BuilderInterface ...@@ -170,11 +170,13 @@ class RefundDataBuilder implements BuilderInterface
$openInvoiceFields = $this->getOpenInvoiceData($payment); $openInvoiceFields = $this->getOpenInvoiceData($payment);
//There is only one payment, so we add the fields to the first(and only) result //There is only one payment, so we add the fields to the first(and only) result
$result[0]["additionalData"] = $openInvoiceFields; $requestBody[0]["additionalData"] = $openInvoiceFields;
} }
} }
return $result; $request['body'] = $requestBody;
return $request;
} }
/** /**
......
...@@ -54,6 +54,8 @@ class VaultDataBuilder implements BuilderInterface ...@@ -54,6 +54,8 @@ class VaultDataBuilder implements BuilderInterface
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$additionalInformation = $payment->getAdditionalInformation(); $additionalInformation = $payment->getAdditionalInformation();
return $this->adyenRequestsHelper->buildVaultData([], $additionalInformation); $request['body'] = $this->adyenRequestsHelper->buildVaultData([], $additionalInformation);
return $request;
} }
} }
...@@ -262,20 +262,20 @@ class Requests extends AbstractHelper ...@@ -262,20 +262,20 @@ class Requests extends AbstractHelper
} }
/** /**
* @param $request * @param array $request
* @param $amount * @param $amount
* @param $currencyCode * @param $currencyCode
* @param $reference * @param $reference
* @return mixed * @param $paymentMethod
* @return array
*/ */
public function buildPaymentData($request = [], $amount, $currencyCode, $reference) public function buildPaymentData($request = [], $amount, $currencyCode, $reference, $paymentMethod)
{ {
$request['amount'] = [ $request['amount'] = [
'currency' => $currencyCode, 'currency' => $currencyCode,
'value' => $this->adyenHelper->formatAmount($amount, $currencyCode) 'value' => $this->adyenHelper->formatAmount($amount, $currencyCode)
]; ];
$request["reference"] = $reference; $request["reference"] = $reference;
$request["fraudOffset"] = "0"; $request["fraudOffset"] = "0";
...@@ -482,4 +482,21 @@ class Requests extends AbstractHelper ...@@ -482,4 +482,21 @@ class Requests extends AbstractHelper
return $address; return $address;
} }
/**
* Only adds idempotency key if payment method is adyen_hpp for now
*
* @param array $request
* @param $paymentMethod
* @param $idempotencyKey
* @return array
*/
public function addIdempotencyKey($request = [], $paymentMethod, $idempotencyKey)
{
if (!empty($paymentMethod) && $paymentMethod == 'adyen_hpp') {
$request['idempotencyKey'] = $idempotencyKey;
}
return $request;
}
} }
...@@ -121,25 +121,25 @@ class AdyenPaymentProcess implements AdyenPaymentProcessInterface ...@@ -121,25 +121,25 @@ class AdyenPaymentProcess implements AdyenPaymentProcessInterface
$payment = $quote->getPayment(); $payment = $quote->getPayment();
// Init request array // Init request array
$request = []; $requestBody = [];
// Merchant account data builder // Merchant account data builder
$paymentMethod = $payment->getMethod(); $paymentMethod = $payment->getMethod();
$storeId = $quote->getStoreId(); $storeId = $quote->getStoreId();
$request = $this->adyenRequestHelper->buildMerchantAccountData($request, $paymentMethod, $storeId); $requestBody = $this->adyenRequestHelper->buildMerchantAccountData($requestBody, $paymentMethod, $storeId);
// Customer data builder // Customer data builder
$customerId = $quote->getCustomerId(); $customerId = $quote->getCustomerId();
$billingAddress = $quote->getBillingAddress(); $billingAddress = $quote->getBillingAddress();
$request = $this->adyenRequestHelper->buildCustomerData($request, $customerId, $billingAddress, $storeId, null, $payload); $requestBody = $this->adyenRequestHelper->buildCustomerData($requestBody, $customerId, $billingAddress, $storeId, null, $payload);
// Customer Ip data builder // Customer Ip data builder
$shopperIp = $quote->getXForwardedFor(); $shopperIp = $quote->getXForwardedFor();
$request = $this->adyenRequestHelper->buildCustomerIpData($request, $shopperIp); $requestBody = $this->adyenRequestHelper->buildCustomerIpData($requestBody, $shopperIp);
// AddressDataBuilder // AddressDataBuilder
$shippingAddress = $quote->getShippingAddress(); $shippingAddress = $quote->getShippingAddress();
$request = $this->adyenRequestHelper->buildAddressData($request, $billingAddress, $shippingAddress); $requestBody = $this->adyenRequestHelper->buildAddressData($requestBody, $billingAddress, $shippingAddress);
// PaymentDataBuilder // PaymentDataBuilder
$currencyCode = $quote->getQuoteCurrencyCode(); $currencyCode = $quote->getQuoteCurrencyCode();
...@@ -148,26 +148,32 @@ class AdyenPaymentProcess implements AdyenPaymentProcessInterface ...@@ -148,26 +148,32 @@ class AdyenPaymentProcess implements AdyenPaymentProcessInterface
// Setting the orderid to null, so that we generate a new one for each /payments call // Setting the orderid to null, so that we generate a new one for each /payments call
$quote->setReservedOrderId(null); $quote->setReservedOrderId(null);
$reference = $quote->reserveOrderId()->getReservedOrderId(); $reference = $quote->reserveOrderId()->getReservedOrderId();
$request = $this->adyenRequestHelper->buildPaymentData($request, $amount, $currencyCode, $reference); $requestBody = $this->adyenRequestHelper->buildPaymentData($requestBody, $amount, $currencyCode, $reference, $paymentMethod);
// Browser data builder // Browser data builder
$request = $this->adyenRequestHelper->buildBrowserData($request); $requestBody = $this->adyenRequestHelper->buildBrowserData($requestBody);
// 3DS2.0 data builder // 3DS2.0 data builder
$isThreeDS2Enabled = $this->adyenHelper->isCreditCardThreeDS2Enabled($storeId); $isThreeDS2Enabled = $this->adyenHelper->isCreditCardThreeDS2Enabled($storeId);
if ($isThreeDS2Enabled) { if ($isThreeDS2Enabled) {
$request = $this->adyenRequestHelper->buildThreeDS2Data($request, $payload, $quote->getStore()); $requestBody = $this->adyenRequestHelper->buildThreeDS2Data($requestBody, $payload, $quote->getStore());
} }
// RecurringDataBuilder // RecurringDataBuilder
$areaCode = $this->context->getAppState()->getAreaCode(); $areaCode = $this->context->getAppState()->getAreaCode();
$request = $this->adyenRequestHelper->buildRecurringData($request, $areaCode, $storeId, $payload); $requestBody = $this->adyenRequestHelper->buildRecurringData($requestBody, $areaCode, $storeId, $payload);
// CcAuthorizationDataBuilder // CcAuthorizationDataBuilder
$request = $this->adyenRequestHelper->buildCCData($request, $payload, $storeId, $areaCode); $requestBody = $this->adyenRequestHelper->buildCCData($requestBody, $payload, $storeId, $areaCode);
// Vault data builder // Vault data builder
$request = $this->adyenRequestHelper->buildVaultData($request, $payload); $requestBody = $this->adyenRequestHelper->buildVaultData($requestBody, $payload);
// Add idempotency key if applicable
$requestHeaders = $this->adyenRequestHelper->addIdempotencyKey([], $paymentMethod, $reference);
$request['body'] = $requestBody;
$request['headers'] = $requestHeaders;
// Create and send request // Create and send request
$transferObject = $this->transferFactory->create($request); $transferObject = $this->transferFactory->create($request);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment