Skip to content

Commit

Permalink
Merge pull request #31 from logeecom/4.1
Browse files Browse the repository at this point in the history
Release version 4.1.10
  • Loading branch information
logeecom authored Mar 24, 2022
2 parents 064e63e + 9d463d3 commit 5eb0701
Show file tree
Hide file tree
Showing 46 changed files with 2,782 additions and 198 deletions.
235 changes: 222 additions & 13 deletions Entity/PaymentMethodSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,45 @@ class PaymentMethodSettings
* @ORM\Column(name="mollie_method_description", type="string", length=255, nullable=false)
*/
protected $mollieMethodDescription;
/**
* @var Collection|LocalizedFallbackValue[]
*
* @ORM\ManyToMany(
* targetEntity="Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue",
* cascade={"ALL"},
* orphanRemoval=true
* )
* @ORM\JoinTable(
* name="mollie_single_click_appr_text",
* joinColumns={
* @ORM\JoinColumn(name="payment_setting_id", referencedColumnName="id", onDelete="CASCADE")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="localized_value_id", referencedColumnName="id", onDelete="CASCADE", unique=true)
* }
* )
*/

protected $singleClickPaymentApprovalText;
/**
* @var Collection|LocalizedFallbackValue[]
*
* @ORM\ManyToMany(
* targetEntity="Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue",
* cascade={"ALL"},
* orphanRemoval=true
* )
* @ORM\JoinTable(
* name="mollie_single_click_desc",
* joinColumns={
* @ORM\JoinColumn(name="payment_setting_id", referencedColumnName="id", onDelete="CASCADE")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="localized_value_id", referencedColumnName="id", onDelete="CASCADE", unique=true)
* }
* )
*/
protected $singleClickPaymentDescription;
/**
* @var \Mollie\Bundle\PaymentBundle\IntegrationCore\BusinessLogic\PaymentMethod\Model\PaymentMethodConfig
*/
Expand Down Expand Up @@ -156,18 +194,35 @@ class PaymentMethodSettings
/**
* @var string
*/
private $method;
private $surchargeType;

/**
* @var string
*/
private $surchargeFixedAmount;

/**
* @var string
*/
private $surcharge;
private $surchargePercentage;

/**
* @var string
*/
private $surchargeLimit;
/**
* @var string
*/
private $method;
/**
* @var boolean
*/
private $mollieComponents;

/**
* @var boolean
*/
private $singleClickPayment;
/**
* @var string
*/
Expand Down Expand Up @@ -202,6 +257,8 @@ public function __construct()
$this->descriptions = new ArrayCollection();
$this->paymentDescriptions = new ArrayCollection();
$this->transactionDescriptions = new ArrayCollection();
$this->singleClickPaymentApprovalText = new ArrayCollection();
$this->singleClickPaymentDescription = new ArrayCollection();
}

/**
Expand Down Expand Up @@ -447,6 +504,70 @@ public function setEnabled($enabled)
$this->enabled = $enabled;
}

/**
* @return string
*/
public function getSurchargeType()
{
return $this->surchargeType;
}

/**
* @param string $surchargeType
*/
public function setSurchargeType($surchargeType)
{
$this->surchargeType = $surchargeType;
}

/**
* @return string
*/
public function getSurchargeFixedAmount()
{
return $this->surchargeFixedAmount;
}

/**
* @param string $surchargeFixedAmount
*/
public function setSurchargeFixedAmount($surchargeFixedAmount)
{
$this->surchargeFixedAmount = $surchargeFixedAmount;
}

/**
* @return string
*/
public function getSurchargePercentage()
{
return $this->surchargePercentage;
}

/**
* @param string $surchargePercentage
*/
public function setSurchargePercentage($surchargePercentage)
{
$this->surchargePercentage = $surchargePercentage;
}

/**
* @return string
*/
public function getSurchargeLimit()
{
return $this->surchargeLimit;
}

/**
* @param string $surchargeLimit
*/
public function setSurchargeLimit($surchargeLimit)
{
$this->surchargeLimit = $surchargeLimit;
}

/**
* @return string
*/
Expand Down Expand Up @@ -496,35 +617,123 @@ public function setOriginalImagePath($originalImagePath)
}

/**
* @return string
* @return mixed
*/
public function getSurcharge()
public function getMollieComponents()
{
return $this->surcharge;
return $this->mollieComponents;
}

/**
* @param string $surcharge
* @param bool $mollieComponents
*/
public function setSurcharge($surcharge)
public function setMollieComponents($mollieComponents)
{
$this->surcharge = $surcharge;
$this->mollieComponents = $mollieComponents;
}

/**
* @return mixed
*/
public function getMollieComponents()
public function getSingleClickPayment()
{
return $this->mollieComponents;
return $this->singleClickPayment;
}

/**
* @param bool $mollieComponents
* @param bool $singleClickPayment
*/
public function setMollieComponents($mollieComponents)
public function setSingleClickPayment($singleClickPayment)
{
$this->mollieComponents = $mollieComponents;
$this->singleClickPayment = $singleClickPayment;
}

/**
* @return Collection|LocalizedFallbackValue[]
*/
public function getSingleClickPaymentApprovalText()
{
return $this->singleClickPaymentApprovalText;
}

/**
* @param Collection|LocalizedFallbackValue[] $singleClickPaymentApprovalText
*/
public function setSingleClickPaymentApprovalText($singleClickPaymentApprovalText)
{
$this->singleClickPaymentApprovalText = $singleClickPaymentApprovalText;
}

/**
* @param LocalizedFallbackValue $singleClickPaymentApprovalText
*
* @return $this
*/
public function addSingleClickPaymentApprovalText(LocalizedFallbackValue $singleClickPaymentApprovalText)
{
if (!$this->singleClickPaymentApprovalText->contains($singleClickPaymentApprovalText)) {
$this->singleClickPaymentApprovalText->add($singleClickPaymentApprovalText);
}

return $this;
}

/**
* @param LocalizedFallbackValue $singleClickPaymentApprovalText
*
* @return $this
*/
public function removeSingleClickPaymentApprovalText(LocalizedFallbackValue $singleClickPaymentApprovalText)
{
if ($this->singleClickPaymentApprovalText->contains($singleClickPaymentApprovalText)) {
$this->singleClickPaymentApprovalText->removeElement($singleClickPaymentApprovalText);
}

return $this;
}

/**
* @return Collection|LocalizedFallbackValue[]
*/
public function getSingleClickPaymentDescription()
{
return $this->singleClickPaymentDescription;
}

/**
* @param Collection|LocalizedFallbackValue[] $singleClickPaymentDescription
*/
public function setSingleClickPaymentDescription($singleClickPaymentDescription)
{
$this->singleClickPaymentDescription = $singleClickPaymentDescription;
}

/**
* @param LocalizedFallbackValue $singleClickPaymentDescription
*
* @return $this
*/
public function addSingleClickPaymentDescription(LocalizedFallbackValue $singleClickPaymentDescription)
{
if (!$this->singleClickPaymentDescription->contains($singleClickPaymentDescription)) {
$this->singleClickPaymentDescription->add($singleClickPaymentDescription);
}

return $this;
}

/**
* @param LocalizedFallbackValue $singleClickPaymentDescription
*
* @return $this
*/
public function removeSingleClickPaymentDescription(LocalizedFallbackValue $singleClickPaymentDescription)
{
if ($this->singleClickPaymentDescription->contains($singleClickPaymentDescription)) {
$this->singleClickPaymentDescription->removeElement($singleClickPaymentDescription);
}

return $this;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion EventListener/ChannelSettingsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,13 @@ protected function updatePaymentMethodConfigurations(ChannelSettings $channelSet
);
}

$paymentMethodConfig->setSurcharge($paymentMethodSetting->getSurcharge());
$paymentMethodConfig->setSurchargeType($paymentMethodSetting->getSurchargeType());
$paymentMethodConfig->setSurchargeFixedAmount($paymentMethodSetting->getSurchargeFixedAmount());
$paymentMethodConfig->setSurchargePercentage($paymentMethodSetting->getSurchargePercentage());
$paymentMethodConfig->setSurchargeLimit($paymentMethodSetting->getSurchargeLimit());
$paymentMethodConfig->setApiMethod($paymentMethodSetting->getMethod());
$paymentMethodConfig->setUseMollieComponents($paymentMethodSetting->getMollieComponents());
$paymentMethodConfig->setUseSingleClickPayment($paymentMethodSetting->getSingleClickPayment());
$paymentMethodConfig->setIssuerListStyle($paymentMethodSetting->getIssuerListStyle());
$paymentMethodConfig->setDaysToOrderExpire($paymentMethodSetting->getOrderExpiryDays());
$paymentMethodConfig->setDaysToPaymentExpire($paymentMethodSetting->getPaymentExpiryDays());
Expand Down
41 changes: 39 additions & 2 deletions EventListener/CheckoutEntityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Mollie\Bundle\PaymentBundle\EventListener;

use Mollie\Bundle\PaymentBundle\Entity\MollieSurchargeAwareInterface;
use Mollie\Bundle\PaymentBundle\IntegrationCore\BusinessLogic\Surcharge\SurchargeService;
use Mollie\Bundle\PaymentBundle\IntegrationCore\Infrastructure\ServiceRegister;
use Mollie\Bundle\PaymentBundle\PaymentMethod\Config\Provider\MolliePaymentConfigProviderInterface;
use Oro\Bundle\CheckoutBundle\Entity\Checkout;

Expand Down Expand Up @@ -49,10 +51,45 @@ protected function setSurcharge(Checkout $checkout)
}

$paymentMethodConfig = $this->paymentConfigProvider->getPaymentConfig($checkout->getPaymentMethod());
if ($paymentMethodConfig && $paymentMethodConfig->getSurchargeAmount() > 0) {
$checkout->setMollieSurchargeAmount($paymentMethodConfig->getSurchargeAmount());

if ($paymentMethodConfig) {
$surcharge = $this->getSurchargeService()->calculateSurchargeAmount(
$paymentMethodConfig->getSurchargeType(),
$paymentMethodConfig->getSurchargeFixedAmount(),
$paymentMethodConfig->getSurchargePercentage(),
$paymentMethodConfig->getSurchargeLimit(),
$this->calculateSubtotal($checkout)
);

$checkout->setMollieSurchargeAmount($surcharge);
} else {
$checkout->setMollieSurchargeAmount(null);
}
}

/**
* @return SurchargeService
*/
protected function getSurchargeService()
{
/** @var SurchargeService $surchargeService */
$surchargeService = ServiceRegister::getService(SurchargeService::CLASS_NAME);

return $surchargeService;
}

/**
* @param Checkout $checkout
* @return float|int
*/
protected function calculateSubtotal(Checkout $checkout)
{
$subtotal = 0;
$checkoutSubtotals = $checkout->getSubtotals();
foreach ($checkoutSubtotals as $checkoutSubtotal) {
$subtotal += $checkoutSubtotal->getSubtotal()->getAmount();
}

return $subtotal;
}
}
18 changes: 17 additions & 1 deletion Form/EventListener/ChannelSettingsTypeSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,27 @@ protected function setPaymentMethodConfigurations(ChannelSettings $channelSettin
);
}

if (!empty($paymentMethodSetting->getSingleClickPaymentApprovalText()) && $paymentMethodSetting->getSingleClickPaymentApprovalText()->isEmpty()) {
$paymentMethodSetting->addSingleClickPaymentApprovalText(
(new LocalizedFallbackValue())->setString($this->translator->trans('mollie.payment.config.payment_methods.single_click_payment_approval_text.value'))
);
}

if (!empty($paymentMethodSetting->getSingleClickPaymentDescription()) && $paymentMethodSetting->getSingleClickPaymentDescription()->isEmpty()) {
$paymentMethodSetting->addSingleClickPaymentDescription(
(new LocalizedFallbackValue())->setString($this->translator->trans('mollie.payment.config.payment_methods.single_click_payment_description.value'))
);
}

$paymentMethodSetting->setPaymentMethodConfig($paymentMethodConfig);
$paymentMethodSetting->setEnabled($paymentMethodConfig->isEnabled());
$paymentMethodSetting->setSurcharge($paymentMethodConfig->getSurcharge());
$paymentMethodSetting->setSurchargeType($paymentMethodConfig->getSurchargeType());
$paymentMethodSetting->setSurchargeFixedAmount($paymentMethodConfig->getSurchargeFixedAmount());
$paymentMethodSetting->setSurchargePercentage($paymentMethodConfig->getSurchargePercentage());
$paymentMethodSetting->setSurchargeLimit($paymentMethodConfig->getSurchargeLimit());
$paymentMethodSetting->setMethod($paymentMethodConfig->getApiMethod());
$paymentMethodSetting->setMollieComponents($paymentMethodConfig->useMollieComponents());
$paymentMethodSetting->setSingleClickPayment($paymentMethodConfig->useSingleClickPayment());
$paymentMethodSetting->setIssuerListStyle($paymentMethodConfig->getIssuerListStyle());
$paymentMethodSetting->setVoucherCategory($paymentMethodConfig->getVoucherCategory());
$paymentMethodSetting->setProductAttribute($paymentMethodConfig->getProductAttribute());
Expand Down
Loading

0 comments on commit 5eb0701

Please sign in to comment.