Skip to content

Commit

Permalink
Updated PayPal order getters and removed PsCheckoutCart creation
Browse files Browse the repository at this point in the history
  • Loading branch information
L3RAZ committed Mar 5, 2024
1 parent bdf2af9 commit 8d2adc2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/Entity/PayPalOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function setEnvironment($environment)
/**
* @return bool
*/
public function getIsCardFields()
public function isCardFields()
{
return $this->isCardFields;
}
Expand All @@ -235,7 +235,7 @@ public function setIsCardFields($isCardFields)
/**
* @return bool
*/
public function getIsExpressCheckout()
public function isExpressCheckout()
{
return $this->isExpressCheckout;
}
Expand Down
10 changes: 5 additions & 5 deletions src/PayPal/Order/Event/PayPalOrderCreatedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class PayPalOrderCreatedEvent extends PayPalOrderEvent
/**
* @var bool
*/
private $isHostedFields;
private $isCardFields;
/**
* @var bool
*/
private $isExpressCheckout;

public function __construct($orderPayPalId, $orderPayPal, $cartId, $isHostedFields, $isExpressCheckout)
public function __construct($orderPayPalId, $orderPayPal, $cartId, $isCardFields, $isExpressCheckout)
{
parent::__construct($orderPayPalId, $orderPayPal);
$this->cartId = $cartId;
$this->isHostedFields = $isHostedFields;
$this->isCardFields = $isCardFields;
$this->isExpressCheckout = $isExpressCheckout;
}

Expand All @@ -51,9 +51,9 @@ public function getCartId()
/**
* @return bool
*/
public function isHostedFields()
public function isCardFields()
{
return $this->isHostedFields;
return $this->isCardFields;
}

/**
Expand Down
31 changes: 9 additions & 22 deletions src/PayPal/Order/EventSubscriber/PayPalOrderEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

namespace PrestaShop\Module\PrestashopCheckout\PayPal\Order\EventSubscriber;

use DateTime;
use Exception;
use PrestaShop\Module\PrestashopCheckout\Checkout\CheckoutChecker;
use PrestaShop\Module\PrestashopCheckout\CommandBus\CommandBusInterface;
Expand All @@ -45,7 +44,7 @@
use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration;
use PrestaShop\Module\PrestashopCheckout\Repository\PayPalOrderRepository;
use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository;
use PsCheckoutCart;
use PrestaShop\PrestaShop\Core\Foundation\Database\EntityNotFoundException;
use Psr\SimpleCache\CacheInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand Down Expand Up @@ -138,11 +137,10 @@ public static function getSubscribedEvents()

public function saveCreatedPayPalOrder(PayPalOrderCreatedEvent $event)
{
$psCheckoutCart = $this->psCheckoutCartRepository->findOneByCartId($event->getCartId());

if ($psCheckoutCart && $psCheckoutCart->getPaypalOrderId()) {
$psCheckoutCart->paypal_status = PayPalOrderStatus::CANCELED;
$this->psCheckoutCartRepository->save($psCheckoutCart);
try { // NOT SURE WHAT SHOULD HAPPEN IF ORDER WITH THAT ID ALREADY EXISTS
$payPalOrder = $this->payPalOrderRepository->getPayPalOrderById($event->getOrderPayPalId()->getValue());
$this->payPalOrderRepository->deletePayPalOrder($payPalOrder->getId());
} catch (EntityNotFoundException $e) {
}

$order = $event->getOrderPayPal();
Expand All @@ -153,24 +151,13 @@ public function saveCreatedPayPalOrder(PayPalOrderCreatedEvent $event)
$order['intent'],
array_keys($order['payment_source'])[0],
$order['status'],
json_encode($order['payment_source'])
json_encode($order['payment_source']),
$this->payPalConfiguration->getPaymentMode(),
$event->isCardFields(),
$event->isExpressCheckout()
);

$this->payPalOrderRepository->createPayPalOrder($payPalOrder);

$psCheckoutCart = new PsCheckoutCart();
$psCheckoutCart->id_cart = $event->getCartId();
$psCheckoutCart->paypal_funding = $order['payment_source'];
$psCheckoutCart->paypal_order = $order['id'];
$psCheckoutCart->paypal_status = $order['status'];
$psCheckoutCart->paypal_intent = $order['intent'];
$psCheckoutCart->paypal_token = $order['client_token'];
$psCheckoutCart->paypal_token_expire = (new DateTime())->modify('+3550 seconds')->format('Y-m-d H:i:s');
$psCheckoutCart->environment = $this->payPalConfiguration->getPaymentMode();
$psCheckoutCart->isExpressCheckout = $event->isExpressCheckout();
$psCheckoutCart->isHostedFields = $event->isHostedFields();

$this->psCheckoutCartRepository->save($psCheckoutCart);
}

public function saveApprovedPayPalOrder(PayPalOrderApprovedEvent $event)
Expand Down
8 changes: 4 additions & 4 deletions src/Repository/PayPalOrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function createPayPalOrder(PayPalOrder $payPalOrder)
'status' => pSQL($payPalOrder->getStatus()),
'payment_source' => pSQL($payPalOrder->getPaymentSource()),
'environment' => pSQL($payPalOrder->getEnvironment()),
'is_card_fields' => $payPalOrder->getIsCardFields(),
'is_express_checkout' => $payPalOrder->getIsExpressCheckout(),
'is_card_fields' => $payPalOrder->isCardFields(),
'is_express_checkout' => $payPalOrder->isExpressCheckout(),
]
);
}
Expand Down Expand Up @@ -127,8 +127,8 @@ public function updatePayPalOrder(PayPalOrder $payPalOrder)
'funding_source' => pSQL($payPalOrder->getFundingSource()),
'status' => pSQL($payPalOrder->getStatus()),
'payment_source' => pSQL($payPalOrder->getPaymentSource()),
'is_card_fields' => $payPalOrder->getIsCardFields(),
'is_express_checkout' => $payPalOrder->getIsExpressCheckout(),
'is_card_fields' => $payPalOrder->isCardFields(),
'is_express_checkout' => $payPalOrder->isExpressCheckout(),
],
'`id` = ' . pSQL($payPalOrder->getId())
);
Expand Down

0 comments on commit 8d2adc2

Please sign in to comment.