-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
- Loading branch information
There are no files selected for viewing
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 GitHub Actions / PHPStan (8.0.0)
Check failure on line 44 in src/Cart/CartInterface.php GitHub Actions / PHPStan (latest)
|
||
} |
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); | ||
} |
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 GitHub Actions / PHPStan (8.0.0)
Check failure on line 32 in src/DTO/Orders/CreatePayPalOrderRequest.php GitHub Actions / PHPStan (latest)
|
||
/** | ||
* @var PaymentSourceRequest | ||
*/ | ||
private $payment_source; | ||
Check failure on line 36 in src/DTO/Orders/CreatePayPalOrderRequest.php GitHub Actions / PHPStan (8.0.0)
Check failure on line 36 in src/DTO/Orders/CreatePayPalOrderRequest.php GitHub Actions / PHPStan (latest)
|
||
|
||
/** | ||
* @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 GitHub Actions / PHPStan (8.0.0)
Check failure on line 57 in src/DTO/Orders/CreatePayPalOrderRequest.php GitHub Actions / PHPStan (latest)
|
||
{ | ||
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 GitHub Actions / PHPStan (8.0.0)
Check failure on line 65 in src/DTO/Orders/CreatePayPalOrderRequest.php GitHub Actions / PHPStan (latest)
|
||
{ | ||
$this->purchase_units = $purchase_units; | ||
} | ||
|
||
/** | ||
* @return PaymentSourceRequest | ||
*/ | ||
public function getPaymentSource() | ||
Check failure on line 73 in src/DTO/Orders/CreatePayPalOrderRequest.php GitHub Actions / PHPStan (8.0.0)
Check failure on line 73 in src/DTO/Orders/CreatePayPalOrderRequest.php GitHub Actions / PHPStan (latest)
|
||
{ | ||
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 GitHub Actions / PHPStan (8.0.0)
Check failure on line 81 in src/DTO/Orders/CreatePayPalOrderRequest.php GitHub Actions / PHPStan (8.0.0)
Check failure on line 81 in src/DTO/Orders/CreatePayPalOrderRequest.php GitHub Actions / PHPStan (latest)
Check failure on line 81 in src/DTO/Orders/CreatePayPalOrderRequest.php GitHub Actions / PHPStan (latest)
|
||
{ | ||
$this->payment_source = $payment_source; | ||
} | ||
} |
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 []; | ||
} | ||
} |
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())); | ||
} | ||
} |
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); | ||
} |