Skip to content

Commit

Permalink
Interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt75 committed Jan 16, 2024
1 parent 9f49a67 commit 39b7ea4
Show file tree
Hide file tree
Showing 8 changed files with 421 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Cart/CartInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PrestashopCheckout\Cart;

use PrestaShop\Module\PrestashopCheckout\DTO\Orders\PurchaseUnitRequest;

interface CartInterface
{
/**
* @return int
*/
public function getId();

/**
* @return string
*/
public function getCurrencyCode();

public function getCustomer();

public function getBillingAddress();

/**
* @return PurchaseUnitRequest[]
*/
public function getPurchaseUnits();

Check failure on line 44 in src/Cart/CartInterface.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Return typehint of method PrestaShop\Module\PrestashopCheckout\Cart\CartInterface::getPurchaseUnits() has invalid type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PurchaseUnitRequest.

Check failure on line 44 in src/Cart/CartInterface.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Return typehint of method PrestaShop\Module\PrestashopCheckout\Cart\CartInterface::getPurchaseUnits() has invalid type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PurchaseUnitRequest.
}
36 changes: 36 additions & 0 deletions src/Cart/CartRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PrestashopCheckout\Cart;

use PrestaShop\Module\PrestashopCheckout\Cart\Exception\CartNotFoundException;
use PrestaShop\Module\PrestashopCheckout\Cart\ValueObject\CartId;

interface CartRepositoryInterface
{
/**
* @param CartId $cartId
*
* @return CartInterface
*
* @throws CartNotFoundException
*/
public function getCartById(CartId $cartId);
}
85 changes: 85 additions & 0 deletions src/DTO/Orders/CreatePayPalOrderRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PrestashopCheckout\DTO\Orders;

class CreatePayPalOrderRequest
{
/**
* @var string
*/
private $intent;
/**
* @var PurchaseUnitRequest[]
*/
private $purchase_units;

Check failure on line 32 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Property PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::$purchase_units has unknown class PrestaShop\Module\PrestashopCheckout\DTO\Orders\PurchaseUnitRequest as its type.

Check failure on line 32 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Property PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::$purchase_units has unknown class PrestaShop\Module\PrestashopCheckout\DTO\Orders\PurchaseUnitRequest as its type.
/**
* @var PaymentSourceRequest
*/
private $payment_source;

Check failure on line 36 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Property PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::$payment_source has unknown class PrestaShop\Module\PrestashopCheckout\DTO\Orders\PaymentSourceRequest as its type.

Check failure on line 36 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Property PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::$payment_source has unknown class PrestaShop\Module\PrestashopCheckout\DTO\Orders\PaymentSourceRequest as its type.

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

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

/**
* @return PurchaseUnitRequest[]
*/
public function getPurchaseUnits()

Check failure on line 57 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Return typehint of method PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::getPurchaseUnits() has invalid type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PurchaseUnitRequest.

Check failure on line 57 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Return typehint of method PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::getPurchaseUnits() has invalid type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PurchaseUnitRequest.
{
return $this->purchase_units;
}

/**
* @param PurchaseUnitRequest[] $purchase_units
*/
public function setPurchaseUnits(array $purchase_units)

Check failure on line 65 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Parameter $purchase_units of method PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::setPurchaseUnits() has invalid typehint type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PurchaseUnitRequest.

Check failure on line 65 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Parameter $purchase_units of method PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::setPurchaseUnits() has invalid typehint type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PurchaseUnitRequest.
{
$this->purchase_units = $purchase_units;
}

/**
* @return PaymentSourceRequest
*/
public function getPaymentSource()

Check failure on line 73 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Return typehint of method PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::getPaymentSource() has invalid type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PaymentSourceRequest.

Check failure on line 73 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Return typehint of method PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::getPaymentSource() has invalid type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PaymentSourceRequest.
{
return $this->payment_source;
}

/**
* @param PaymentSourceRequest $payment_source
*/
public function setPaymentSource(PaymentSourceRequest $payment_source)

Check failure on line 81 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Parameter $payment_source of method PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::setPaymentSource() has invalid typehint type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PaymentSourceRequest.

Check failure on line 81 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Parameter $payment_source of method PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::setPaymentSource() has invalid typehint type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PaymentSourceRequest.

Check failure on line 81 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Parameter $payment_source of method PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::setPaymentSource() has invalid typehint type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PaymentSourceRequest.

Check failure on line 81 in src/DTO/Orders/CreatePayPalOrderRequest.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Parameter $payment_source of method PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest::setPaymentSource() has invalid typehint type PrestaShop\Module\PrestashopCheckout\DTO\Orders\PaymentSourceRequest.
{
$this->payment_source = $payment_source;
}
}
34 changes: 34 additions & 0 deletions src/DTO/Orders/CreatePayPalOrderResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PrestashopCheckout\DTO\Orders;

class CreatePayPalOrderResponse
{
public function getId()
{
return '';
}

public function toArray()
{
return [];
}
}
62 changes: 62 additions & 0 deletions src/PayPal/Order/Command/CreatePayPalOrderCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

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

use PrestaShop\Module\PrestashopCheckout\Cart\ValueObject\CartId;

class CreatePayPalOrderCommand
{
/**
* @var CartId
*/
private $cartId;

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

/**
* @param CartId $cartId
* @param string $fundingSource
*/
public function __construct(CartId $cartId, $fundingSource)
{
$this->cartId = $cartId;
$this->fundingSource = $fundingSource;
}

/**
* @return CartId
*/
public function getCartId()
{
return $this->cartId;
}

/**
* @return string
*/
public function getFundingSource()
{
return $this->fundingSource;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

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

use PrestaShop\Module\PrestashopCheckout\Cart\CartRepositoryInterface;
use PrestaShop\Module\PrestashopCheckout\Cart\Exception\CartNotFoundException;
use PrestaShop\Module\PrestashopCheckout\Event\EventDispatcherInterface;
use PrestaShop\Module\PrestashopCheckout\PayPal\Order\Command\CreatePayPalOrderCommand;
use PrestaShop\Module\PrestashopCheckout\PayPal\Order\CreatePayPalOrderPayloadBuilderInterface;
use PrestaShop\Module\PrestashopCheckout\PayPal\Order\Event\PayPalOrderCreatedEvent;
use PrestaShop\Module\PrestashopCheckout\PayPal\Order\Exception\PayPalOrderException;
use PrestaShop\Module\PrestashopCheckout\PayPal\Order\PayPalOrderHttpClientInterface;

class CreatePayPalOrderCommandHandler
{
/**
* @var CartRepositoryInterface
*/
private $cartRepository;

/**
* @var CreatePayPalOrderPayloadBuilderInterface
*/
private $createPayPalOrderPayloadBuilder;

/**
* @var PayPalOrderHttpClientInterface
*/
private $orderHttpClient;

/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;

/**
* @param CartRepositoryInterface $cartRepository
* @param CreatePayPalOrderPayloadBuilderInterface $createPayPalOrderPayloadBuilder
* @param PayPalOrderHttpClientInterface $orderHttpClient
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(
CartRepositoryInterface $cartRepository,
CreatePayPalOrderPayloadBuilderInterface $createPayPalOrderPayloadBuilder,
PayPalOrderHttpClientInterface $orderHttpClient,
EventDispatcherInterface $eventDispatcher
) {
$this->cartRepository = $cartRepository;
$this->createPayPalOrderPayloadBuilder = $createPayPalOrderPayloadBuilder;
$this->orderHttpClient = $orderHttpClient;
$this->eventDispatcher = $eventDispatcher;
}

/**
* @param CreatePayPalOrderCommand $command
*
* @return void
*
* @throws PayPalOrderException
* @throws CartNotFoundException
*/
public function handle(CreatePayPalOrderCommand $command)
{
$cart = $this->cartRepository->getCartById($command->getCartId());
$payload = $this->createPayPalOrderPayloadBuilder->build($cart, $command->getFundingSource());
$order = $this->orderHttpClient->createOrder($payload);
$this->eventDispatcher->dispatch(new PayPalOrderCreatedEvent($order->getId(), $order->toArray()));
}
}
35 changes: 35 additions & 0 deletions src/PayPal/Order/CreatePayPalOrderPayloadBuilderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PrestashopCheckout\PayPal\Order;

use PrestaShop\Module\PrestashopCheckout\Cart\CartInterface;
use PrestaShop\Module\PrestashopCheckout\DTO\Orders\CreatePayPalOrderRequest;

interface CreatePayPalOrderPayloadBuilderInterface
{
/**
* @param CartInterface $cart
* @param string $fundingSource
*
* @return CreatePayPalOrderRequest
*/
public function build(CartInterface $cart, $fundingSource);
}
Loading

0 comments on commit 39b7ea4

Please sign in to comment.