Skip to content

Commit

Permalink
Verify IPN with order from shop
Browse files Browse the repository at this point in the history
CS-5639
  • Loading branch information
MarijaIv committed Jul 5, 2024
1 parent c2e1ba6 commit 5ce6d48
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/BusinessLogic/Webhook/Handler/WebhookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use SeQura\Core\BusinessLogic\Domain\Webhook\Models\Webhook;
use SeQura\Core\BusinessLogic\SeQuraAPI\Order\OrderProxy;
use SeQura\Core\BusinessLogic\Domain\Order\ProxyContracts\OrderProxyInterface;
use SeQura\Core\BusinessLogic\Webhook\Services\ShopOrderService;
use SeQura\Core\BusinessLogic\Webhook\Tasks\OrderUpdateTask;
use SeQura\Core\Infrastructure\Http\Exceptions\HttpRequestException;
use SeQura\Core\Infrastructure\ORM\Exceptions\QueryFilterInvalidParamException;
Expand Down Expand Up @@ -70,19 +71,19 @@ protected function acknowledgeOrder(string $orderReference, string $state): void
* @var OrderProxy $orderProxy
*/
$orderProxy = ServiceRegister::getService(OrderProxyInterface::class);
$order = $this->getSeQuraOrderByOrderReference($orderReference);
$shopOrder = $this->getCreateOrderRequest($orderReference);

$request = new CreateOrderRequest(
OrderRequestStatusMapping::mapOrderRequestStatus($state),
$order->getMerchant(),
$order->getUnshippedCart(),
$order->getDeliveryMethod(),
$order->getCustomer(),
$order->getPlatform(),
$order->getDeliveryAddress(),
$order->getInvoiceAddress(),
$order->getGui(),
$order->getMerchantReference()
$shopOrder->getMerchant(),
$shopOrder->getCart(),
$shopOrder->getDeliveryMethod(),
$shopOrder->getCustomer(),
$shopOrder->getPlatform(),
$shopOrder->getDeliveryAddress(),
$shopOrder->getInvoiceAddress(),
$shopOrder->getGui(),
$shopOrder->getMerchantReference()
);

$orderProxy->acknowledgeOrder($orderReference, $request);
Expand Down Expand Up @@ -112,4 +113,19 @@ protected function getSeQuraOrderByOrderReference(string $orderRef): ?SeQuraOrde

return $order;
}

/**
* Retrieves create order request.
*
* @param string $orderReference
*
* @return CreateOrderRequest
*/
protected function getCreateOrderRequest(string $orderReference): CreateOrderRequest
{
/** @var ShopOrderService $service */
$service = ServiceRegister::getService(ShopOrderService::class);

return $service->getCreateOrderRequest($orderReference);
}
}
10 changes: 10 additions & 0 deletions src/BusinessLogic/Webhook/Services/ShopOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SeQura\Core\BusinessLogic\Webhook\Services;

use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\CreateOrderRequest;
use SeQura\Core\BusinessLogic\Domain\Webhook\Models\Webhook;

/**
Expand Down Expand Up @@ -49,4 +50,13 @@ public function getStatisticsOrderIds(int $page, int $limit = 5000): array;
* @return string
*/
public function getOrderUrl(string $merchantReference): string;

/**
* Retrieves create order request from shop.
*
* @param string $orderReference
*
* @return CreateOrderRequest
*/
public function getCreateOrderRequest(string $orderReference): CreateOrderRequest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@

namespace SeQura\Core\Tests\BusinessLogic\WebhookAPI\MockComponents;

use SeQura\Core\BusinessLogic\Domain\Order\Builders\CreateOrderRequestBuilder;
use SeQura\Core\BusinessLogic\Domain\Order\Exceptions\InvalidCartItemsException;
use SeQura\Core\BusinessLogic\Domain\Order\Exceptions\InvalidGuiLayoutValueException;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Address;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Cart;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\CreateOrderRequest;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Customer;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\DeliveryMethod;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Gui;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item\ProductItem;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Merchant;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\MerchantReference;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Platform;
use SeQura\Core\BusinessLogic\Domain\Webhook\Models\Webhook;
use SeQura\Core\BusinessLogic\Webhook\Services\ShopOrderService;
use SeQura\Core\Infrastructure\Http\Exceptions\HttpRequestException;
use SeQura\Core\Tests\Infrastructure\Common\TestServiceRegister;

class MockShopErrorOrderService implements ShopOrderService
{
Expand Down Expand Up @@ -47,4 +61,53 @@ public function getOrderUrl(string $merchantReference): string
{
return '';
}

/**
* @throws InvalidCartItemsException
* @throws InvalidGuiLayoutValueException
*/
public function getCreateOrderRequest(string $orderReference): CreateOrderRequest
{
$merchant = new Merchant('testMerchantId');
$merchantReference = new MerchantReference('test123');
$cart = new Cart('testCurrency', false, [
new ProductItem('testItemReference','testName', 5,2, 10, false)
], $orderReference);

$deliveryMethod = new DeliveryMethod('testDeliveryMethodName');
$deliveryAddress = new Address(
'testDeliveryAddressCompany',
'testDeliveryAddressLine1',
'testDeliveryAddressLine2',
'testDeliveryAddressPostalCode',
'testDeliveryAddressCity',
'ES'
);

$invoiceAddress = new Address(
'testInvoiceAddressCompany',
'testInvoiceAddressLine1',
'testInvoiceAddressLine2',
'testInvoiceAddressPostalCode',
'testInvoiceAddressCity',
'ES'
);

$customer = new Customer('[email protected]','testCode','testIpNum','testAgent');
$platform = new Platform('testName','testVersion','testUName','testDbName','testDbVersion');
$gui = new Gui(Gui::ALLOWED_VALUES['desktop']);

return new CreateOrderRequest(
'testState',
$merchant,
$cart,
$deliveryMethod,
$customer,
$platform,
$deliveryAddress,
$invoiceAddress,
$gui,
$merchantReference
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@

namespace SeQura\Core\Tests\BusinessLogic\WebhookAPI\MockComponents;

use SeQura\Core\BusinessLogic\Domain\Order\Builders\CreateOrderRequestBuilder;
use SeQura\Core\BusinessLogic\Domain\Order\Exceptions\InvalidCartItemsException;
use SeQura\Core\BusinessLogic\Domain\Order\Exceptions\InvalidGuiLayoutValueException;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Address;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Cart;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\CreateOrderRequest;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Customer;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\DeliveryMethod;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Gui;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Item\ProductItem;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Merchant;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\MerchantReference;
use SeQura\Core\BusinessLogic\Domain\Order\Models\OrderRequest\Platform;
use SeQura\Core\BusinessLogic\Domain\Webhook\Models\Webhook;
use SeQura\Core\BusinessLogic\Webhook\Services\ShopOrderService;
use SeQura\Core\Tests\Infrastructure\Common\TestServiceRegister;

/**
* Class MockShopOrderService
Expand Down Expand Up @@ -49,4 +63,53 @@ public function getOrderUrl(string $merchantReference): string
{
return 'https.test.url/' . $merchantReference;
}

/**
* @throws InvalidCartItemsException
* @throws InvalidGuiLayoutValueException
*/
public function getCreateOrderRequest(string $orderReference): CreateOrderRequest
{
$merchant = new Merchant('testMerchantId');
$merchantReference = new MerchantReference('test123');
$cart = new Cart('testCurrency', false, [
new ProductItem('testItemReference','testName', 5,2, 10, false)
], $orderReference);

$deliveryMethod = new DeliveryMethod('testDeliveryMethodName');
$deliveryAddress = new Address(
'testDeliveryAddressCompany',
'testDeliveryAddressLine1',
'testDeliveryAddressLine2',
'testDeliveryAddressPostalCode',
'testDeliveryAddressCity',
'ES'
);

$invoiceAddress = new Address(
'testInvoiceAddressCompany',
'testInvoiceAddressLine1',
'testInvoiceAddressLine2',
'testInvoiceAddressPostalCode',
'testInvoiceAddressCity',
'ES'
);

$customer = new Customer('[email protected]','testCode','testIpNum','testAgent');
$platform = new Platform('testName','testVersion','testUName','testDbName','testDbVersion');
$gui = new Gui(Gui::ALLOWED_VALUES['desktop']);

return new CreateOrderRequest(
'testState',
$merchant,
$cart,
$deliveryMethod,
$customer,
$platform,
$deliveryAddress,
$invoiceAddress,
$gui,
$merchantReference
);
}
}

0 comments on commit 5ce6d48

Please sign in to comment.