From f0051c405ac2b5b9b8382bef0851935575a06f07 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Mon, 15 Jul 2024 16:40:53 +0300 Subject: [PATCH] Added merchantInfo to transactionInfo payload --- .../GooglePayTransactionInfoBuilder.php | 7 +- .../DTO/GooglePayTransactionInfo.php | 24 ++++ src/PayPal/GooglePay/DTO/MerchantInfo.php | 111 ++++++++++++++++++ 3 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 src/PayPal/GooglePay/DTO/MerchantInfo.php diff --git a/src/PayPal/GooglePay/Builder/GooglePayTransactionInfoBuilder.php b/src/PayPal/GooglePay/Builder/GooglePayTransactionInfoBuilder.php index 59ba84871..8eecc6665 100644 --- a/src/PayPal/GooglePay/Builder/GooglePayTransactionInfoBuilder.php +++ b/src/PayPal/GooglePay/Builder/GooglePayTransactionInfoBuilder.php @@ -23,6 +23,7 @@ use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException; use PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\DTO\GooglePayDisplayItem; use PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\DTO\GooglePayTransactionInfo; +use PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\DTO\MerchantInfo; use PrestaShop\Module\PrestashopCheckout\Translations\Translations; class GooglePayTransactionInfoBuilder @@ -98,10 +99,14 @@ public function buildFromPayPalPayload($payload) $displayItems = array_merge($productItems, $displayItems); + $merchantInfo = new MerchantInfo(); + $merchantInfo->setMerchantName($payload['application_context']['brand_name']); + $transactionInfo->setCurrencyCode($payload['amount']['currency_code']) ->setTotalPrice($payload['amount']['value']) ->setTotalPriceLabel($this->translations['total']) - ->setDisplayItems($displayItems); + ->setDisplayItems($displayItems) + ->setMerchantInfo($merchantInfo); return $transactionInfo; } diff --git a/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php b/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php index 7869df2ca..364c64c1d 100644 --- a/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php +++ b/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php @@ -59,6 +59,10 @@ class GooglePayTransactionInfo * @var 'DEFAULT'|'COMPLETE_IMMEDIATE_PURCHASE' */ private $checkoutOption = self::CHECKOUT_OPTION_DEFAULT; + /** + * @var MerchantInfo + */ + private $merchantInfo; /** * @return string @@ -220,6 +224,25 @@ public function setCheckoutOption($checkoutOption) return $this; } + /** + * @param MerchantInfo $merchantInfo + * + * @return GooglePayTransactionInfo + */ + public function setMerchantInfo($merchantInfo) + { + $this->merchantInfo = $merchantInfo; + return $this; + } + + /** + * @return MerchantInfo + */ + public function getMerchantInfo() + { + return $this->merchantInfo; + } + public function toArray() { return array_filter([ @@ -233,6 +256,7 @@ public function toArray() 'displayItems' => array_map(function (GooglePayDisplayItem $item) { return $item->toArray(); }, $this->displayItems), + 'merchantInfo' => $this->merchantInfo->toArray() ]); } } diff --git a/src/PayPal/GooglePay/DTO/MerchantInfo.php b/src/PayPal/GooglePay/DTO/MerchantInfo.php new file mode 100644 index 000000000..739b1a322 --- /dev/null +++ b/src/PayPal/GooglePay/DTO/MerchantInfo.php @@ -0,0 +1,111 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +namespace PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\DTO; + +class MerchantInfo +{ + /** + * @var string + */ + private $merchantName; + + /** + * @var string + */ + private $merchantId; + + /** + * @var string + */ + private $merchantOrigin; + + /** + * @return string + */ + public function getMerchantName() + { + return $this->merchantName; + } + + /** + * @param string $merchantName + * + * @return MerchantInfo + */ + public function setMerchantName($merchantName) + { + $this->merchantName = $merchantName; + + return $this; + } + + /** + * @return string + */ + public function getMerchantId() + { + return $this->merchantId; + } + + /** + * @param string $merchantId + * + * @return MerchantInfo + */ + public function setMerchantId($merchantId) + { + $this->merchantId = $merchantId; + + return $this; + } + + /** + * @return string + */ + public function getMerchantOrigin() + { + return $this->merchantOrigin; + } + + /** + * @param string $merchantOrigin + * + * @return MerchantInfo + */ + public function setMerchantOrigin($merchantOrigin) + { + $this->merchantOrigin = $merchantOrigin; + + return $this; + } + + /** + * @return array + */ + public function toArray() + { + return array_filter([ + 'merchantName' => $this->merchantName, + 'merchantId' => $this->merchantId, + 'merchantOrigin' => $this->merchantOrigin, + ]); + } +}