Skip to content

Commit

Permalink
Added merchantInfo to transactionInfo payload
Browse files Browse the repository at this point in the history
  • Loading branch information
L3RAZ committed Jul 15, 2024
1 parent f1d7cee commit f0051c4
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class GooglePayTransactionInfo
* @var 'DEFAULT'|'COMPLETE_IMMEDIATE_PURCHASE'
*/
private $checkoutOption = self::CHECKOUT_OPTION_DEFAULT;
/**
* @var MerchantInfo
*/
private $merchantInfo;

/**
* @return string
Expand Down Expand Up @@ -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([
Expand All @@ -233,6 +256,7 @@ public function toArray()
'displayItems' => array_map(function (GooglePayDisplayItem $item) {
return $item->toArray();
}, $this->displayItems),
'merchantInfo' => $this->merchantInfo->toArray()
]);
}
}
111 changes: 111 additions & 0 deletions src/PayPal/GooglePay/DTO/MerchantInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @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,
]);
}
}

0 comments on commit f0051c4

Please sign in to comment.