From c6fd8100d81f1c9c0cfc9614271c7f8932504d88 Mon Sep 17 00:00:00 2001 From: Arkadiusz Pabisz Date: Wed, 19 Jul 2023 14:34:39 +0200 Subject: [PATCH] unset notification container for previous API version --- .../Request/Initialize/InitializeRequest.php | 22 +++++++++++-------- .../InitializeRequestObjectCreator.php | 4 +++- src/Service/SaferPayInitialize.php | 1 + 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/DTO/Request/Initialize/InitializeRequest.php b/src/DTO/Request/Initialize/InitializeRequest.php index 20aa71dd..82e90e07 100755 --- a/src/DTO/Request/Initialize/InitializeRequest.php +++ b/src/DTO/Request/Initialize/InitializeRequest.php @@ -68,12 +68,12 @@ class InitializeRequest private $returnUrl; /** - * @var array + * @var SaferPayNotification|null */ private $notification; /** - * @var array + * @var DeliveryAddressForm */ private $deliveryAddressForm; @@ -124,7 +124,7 @@ public function __construct( Payment $payment, Payer $payer, ReturnUrl $returnUrl, - SaferPayNotification $notification, + $notification, DeliveryAddressForm $deliveryAddressForm, $configSet, $cssUrl, @@ -214,17 +214,21 @@ public function getAsArray() 'ReturnUrl' => [ 'Url' => $this->returnUrl->getReturnUrl(), ], - 'Notification' => [ - 'PayerEmail' => $this->notification->getPayerEmail(), - 'MerchantEmails' => [$this->notification->getMerchantEmail()], - 'SuccessNotifyUrl' => $this->notification->getNotifyUrl(), - 'FailNotifyUrl' => $this->notification->getNotifyUrl(), - ], 'DeliveryAddressForm' => [ 'AddressSource' => $this->deliveryAddressForm->getAddressSource(), 'MandatoryFields' => $this->deliveryAddressForm->getMandatoryFields(), ], ]; + + if ($this->notification !== null) { + $return['Notification'] = [ + 'PayerEmail' => $this->notification->getPayerEmail(), + 'MerchantEmails' => [$this->notification->getMerchantEmail()], + 'SuccessNotifyUrl' => $this->notification->getNotifyUrl(), + 'FailNotifyUrl' => $this->notification->getNotifyUrl(), + ]; + } + if ($this->configSet) { $return['ConfigSet'] = $this->configSet; } diff --git a/src/Service/Request/InitializeRequestObjectCreator.php b/src/Service/Request/InitializeRequestObjectCreator.php index d7bf6fae..77452fe9 100755 --- a/src/Service/Request/InitializeRequestObjectCreator.php +++ b/src/Service/Request/InitializeRequestObjectCreator.php @@ -27,6 +27,7 @@ use Configuration; use Customer; use Invertus\SaferPay\Config\SaferPayConfig; +use Invertus\SaferPay\DTO\Request\RequestHeader; use Invertus\SaferPay\DTO\Request\Initialize\InitializeRequest; use Invertus\SaferPay\DTO\Request\Payer; @@ -51,6 +52,7 @@ public function create( $deliveryAddressId, $invoiceAddressId, $customerId, + $isBusinessLicence, $alias = null, $fieldToken = null ) { @@ -63,7 +65,7 @@ public function create( $payment = $this->requestObjectCreator->createPayment($cart, $totalPrice); $payer = new Payer(); $returnUrl = $this->requestObjectCreator->createReturnUrl($returnUrl); - $notification = $this->requestObjectCreator->createNotification($customerEmail, $notifyUrl); + $notification = ($isBusinessLicence && version_compare(Configuration::get(RequestHeader::SPEC_VERSION), '1.35', '<')) ? null : $this->requestObjectCreator->createNotification($customerEmail, $notifyUrl); $deliveryAddressForm = $this->requestObjectCreator->createDeliveryAddressForm(); $configSet = Configuration::get(SaferPayConfig::CONFIGURATION_NAME); $cssUrl = Configuration::get(SaferPayConfig::CSS_FILE); diff --git a/src/Service/SaferPayInitialize.php b/src/Service/SaferPayInitialize.php index b28ee497..184ad034 100755 --- a/src/Service/SaferPayInitialize.php +++ b/src/Service/SaferPayInitialize.php @@ -114,6 +114,7 @@ public function initialize( $this->context->cart->id_address_delivery, $this->context->cart->id_address_invoice, $this->context->cart->id_customer, + $isBusinessLicence, $alias, $fieldToken );