Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt75 committed Jan 24, 2025
1 parent 4c60aca commit d4dc959
Show file tree
Hide file tree
Showing 5 changed files with 2,342 additions and 21 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@
"webmozart/assert": "^1.0"
},
"require-dev": {
"guzzlehttp/guzzle": "~5.0",
"monolog/monolog": "1.25.3",
"phpunit/phpunit": "~5.7",
"prestashop/php-dev-tools": "~3.0",
"psr/simple-cache": "^1.0",
"symfony/cache": "^3.4",
"symfony/config": "^3.4",
"symfony/dependency-injection": "^3.4",
"symfony/finder": "^3.4",
"symfony/options-resolver": "^3.4",
"guzzlehttp/guzzle": "~5.0",
"monolog/monolog": "1.25.3"
"symfony/options-resolver": "^3.4"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/command-handlers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ services:
- '@PrestaShop\Module\PrestashopCheckout\Context\PrestaShopContext'
- '@PrestaShop\Module\PrestashopCheckout\Repository\PayPalCustomerRepository'
- '@PrestaShop\Module\PrestashopCheckout\Repository\PayPalOrderRepository'
- '@PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration'

PrestaShop\Module\PrestashopCheckout\Checkout\CommandHandler\SaveCheckoutCommandHandler:
class: 'PrestaShop\Module\PrestashopCheckout\Checkout\CommandHandler\SaveCheckoutCommandHandler'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

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

use Configuration;
use PrestaShop\Module\PrestashopCheckout\Context\PrestaShopContext;
use PrestaShop\Module\PrestashopCheckout\Customer\ValueObject\CustomerId;
use PrestaShop\Module\PrestashopCheckout\Event\EventDispatcherInterface;
Expand All @@ -37,6 +36,7 @@
use PrestaShop\Module\PrestashopCheckout\PayPal\Payment\Capture\Event\PayPalCapturePendingEvent;
use PrestaShop\Module\PrestashopCheckout\PayPal\Payment\Capture\PayPalCaptureStatus;
use PrestaShop\Module\PrestashopCheckout\PayPal\PaymentToken\Event\PaymentTokenCreatedEvent;
use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration;
use PrestaShop\Module\PrestashopCheckout\PayPalProcessorResponse;
use PrestaShop\Module\PrestashopCheckout\Repository\PayPalCustomerRepository;
use PrestaShop\Module\PrestashopCheckout\Repository\PayPalOrderRepository;
Expand Down Expand Up @@ -70,38 +70,32 @@ class CapturePayPalOrderCommandHandler
* @var PayPalOrderRepository
*/
private $payPalOrderRepository;
/**
* @var PayPalConfiguration
*/
private $payPalConfiguration;

public function __construct(
MaaslandHttpClient $maaslandHttpClient,
EventDispatcherInterface $eventDispatcher,
CacheInterface $orderPayPalCache,
PrestaShopContext $prestaShopContext,
PayPalCustomerRepository $payPalCustomerRepository,
PayPalOrderRepository $payPalOrderRepository
PayPalOrderRepository $payPalOrderRepository,
PayPalConfiguration $payPalConfiguration
) {
$this->maaslandHttpClient = $maaslandHttpClient;
$this->eventDispatcher = $eventDispatcher;
$this->orderPayPalCache = $orderPayPalCache;
$this->prestaShopContext = $prestaShopContext;
$this->payPalCustomerRepository = $payPalCustomerRepository;
$this->payPalOrderRepository = $payPalOrderRepository;
$this->payPalConfiguration = $payPalConfiguration;
}

public function handle(CapturePayPalOrderCommand $capturePayPalOrderCommand)
{
$merchantId = Configuration::get('PS_CHECKOUT_PAYPAL_ID_MERCHANT', null, null, $this->prestaShopContext->getShopId());

$payload = [
'mode' => $capturePayPalOrderCommand->getFundingSource(),
'orderId' => $capturePayPalOrderCommand->getOrderId()->getValue(),
'payee' => ['merchant_id' => $merchantId],
];

$order = $this->payPalOrderRepository->getPayPalOrderById($capturePayPalOrderCommand->getOrderId());

if ($order->checkCustomerIntent(PayPalOrder::CUSTOMER_INTENT_USES_VAULTING)) {
$payload['vault'] = true;
}
$payload = $this->createCapturePayload($capturePayPalOrderCommand);

$response = $this->maaslandHttpClient->captureOrder($payload);

Expand Down Expand Up @@ -136,7 +130,7 @@ public function handle(CapturePayPalOrderCommand $capturePayPalOrderCommand)

$this->eventDispatcher->dispatch(new PaymentTokenCreatedEvent(
$resource,
$merchantId
$this->payPalConfiguration->getMerchantId()
));
}
}
Expand Down Expand Up @@ -175,4 +169,26 @@ public function handle(CapturePayPalOrderCommand $capturePayPalOrderCommand)
throw new PsCheckoutException('PayPal declined the capture', PsCheckoutException::PAYPAL_PAYMENT_CAPTURE_DECLINED);
}
}

/**
* @param CapturePayPalOrderCommand $capturePayPalOrderCommand
*
* @return array
*/
private function createCapturePayload(CapturePayPalOrderCommand $capturePayPalOrderCommand)
{
$payload = [
'mode' => $capturePayPalOrderCommand->getFundingSource(),
'orderId' => $capturePayPalOrderCommand->getOrderId()->getValue(),
'payee' => ['merchant_id' => $this->payPalConfiguration->getMerchantId()],
];

$order = $this->payPalOrderRepository->getPayPalOrderById($capturePayPalOrderCommand->getOrderId());

if ($order->checkCustomerIntent(PayPalOrder::CUSTOMER_INTENT_USES_VAULTING)) {
$payload['vault'] = true;
}

return $payload;
}
}
Loading

0 comments on commit d4dc959

Please sign in to comment.