custom/plugins/SwagPayPal/src/Webhook/Handler/CaptureCompleted.php line 51

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3. * (c) shopware AG <info@shopware.com>
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. */
  7. namespace Swag\PayPal\Webhook\Handler;
  8. use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStateHandler;
  9. use Shopware\Core\Framework\Context;
  10. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  11. use Swag\PayPal\RestApi\PayPalApiStruct;
  12. use Swag\PayPal\RestApi\V2\Api\Order\PurchaseUnit\Payments\Capture;
  13. use Swag\PayPal\RestApi\V2\Api\Webhook as WebhookV2;
  14. use Swag\PayPal\Util\PaymentStatusUtilV2;
  15. use Swag\PayPal\Webhook\Exception\WebhookException;
  16. use Swag\PayPal\Webhook\WebhookEventTypes;
  17. class CaptureCompleted extends AbstractWebhookHandler
  18. {
  19. private PaymentStatusUtilV2 $paymentStatusUtil;
  20. /**
  21. * @internal
  22. */
  23. public function __construct(
  24. EntityRepository $orderTransactionRepository,
  25. OrderTransactionStateHandler $orderTransactionStateHandler,
  26. PaymentStatusUtilV2 $paymentStatusUtil
  27. ) {
  28. parent::__construct($orderTransactionRepository, $orderTransactionStateHandler);
  29. $this->paymentStatusUtil = $paymentStatusUtil;
  30. }
  31. public function getEventType(): string
  32. {
  33. return WebhookEventTypes::PAYMENT_CAPTURE_COMPLETED;
  34. }
  35. /**
  36. * @param WebhookV2 $webhook
  37. */
  38. public function invoke(PayPalApiStruct $webhook, Context $context): void
  39. {
  40. /** @var Capture|null $capture */
  41. $capture = $webhook->getResource();
  42. if ($capture === null) {
  43. throw new WebhookException($this->getEventType(), 'Given webhook does not have needed resource data');
  44. }
  45. $orderTransaction = $this->getOrderTransactionV2($capture, $context);
  46. $this->paymentStatusUtil->applyCaptureState($orderTransaction->getId(), $capture, $context);
  47. }
  48. }