-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
219 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Entity; | ||
|
||
use Sylius\Component\Core\Model\PaymentInterface; | ||
|
||
interface OrderLastNewPaymentAwareInterface | ||
{ | ||
public function getLastNewPayment(): ?PaymentInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CommerceWeavers\SyliusTpayPlugin\Entity; | ||
|
||
use Sylius\Component\Core\Model\PaymentInterface; | ||
|
||
trait OrderLastNewPaymentAwareTrait | ||
{ | ||
public function getLastNewPayment(): ?PaymentInterface | ||
{ | ||
return $this->getLastPayment('cart'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Entity; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Entity\OrderLastNewPaymentAwareInterface; | ||
use CommerceWeavers\SyliusTpayPlugin\Entity\OrderLastNewPaymentAwareTrait; | ||
use Doctrine\ORM\Mapping as ORM; | ||
use Sylius\Component\Core\Model\Order as BaseOrder; | ||
|
||
#[ORM\Entity] | ||
#[ORM\Table(name: 'sylius_order')] | ||
class Order extends BaseOrder implements OrderLastNewPaymentAwareInterface | ||
{ | ||
use OrderLastNewPaymentAwareTrait; | ||
} |
161 changes: 161 additions & 0 deletions
161
tests/Unit/Payum/Action/Api/CreateBlik0TransactionActionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\CommerceWeavers\SyliusTpayPlugin\Unit\Payum\Action\Api; | ||
|
||
use CommerceWeavers\SyliusTpayPlugin\Payum\Action\Api\CreateBlik0TransactionAction; | ||
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\CreateBlik0Transaction; | ||
use CommerceWeavers\SyliusTpayPlugin\Payum\Request\Api\CreateTransaction; | ||
use Payum\Core\Request\Sync; | ||
use Payum\Core\Security\GenericTokenFactoryInterface; | ||
use Payum\Core\Security\TokenInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
use Sylius\Component\Core\Model\AddressInterface; | ||
use Sylius\Component\Core\Model\CustomerInterface; | ||
use Sylius\Component\Core\Model\OrderInterface; | ||
use Sylius\Component\Core\Model\PaymentInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Tpay\OpenApi\Api\TpayApi; | ||
use Tpay\OpenApi\Api\Transactions\TransactionsApi; | ||
|
||
final class CreateBlik0TransactionActionTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
private CreateBlik0Transaction|ObjectProphecy $request; | ||
private PaymentInterface|ObjectProphecy $model; | ||
private TpayApi|ObjectProphecy $api; | ||
private RouterInterface|ObjectProphecy $router; | ||
private GenericTokenFactoryInterface|ObjectProphecy $tokenFactory; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->request = $this->prophesize(CreateTransaction::class); | ||
$this->model = $this->prophesize(PaymentInterface::class); | ||
$this->api = $this->prophesize(TpayApi::class); | ||
$this->router = $this->prophesize(RouterInterface::class); | ||
$this->tokenFactory = $this->prophesize(GenericTokenFactoryInterface::class); | ||
|
||
$this->request->getModel()->willReturn($this->model->reveal()); | ||
} | ||
|
||
public function test_it_supports_only_create_blik0_transaction_request(): void | ||
{ | ||
$action = $this->createTestSubject(); | ||
|
||
$this->assertFalse($action->supports(new Sync($this->model->reveal()))); | ||
$this->assertTrue($action->supports(new CreateBlik0Transaction($this->model->reveal()))); | ||
} | ||
|
||
public function test_it_supports_only_payment_interface_based_models(): void | ||
{ | ||
$action = $this->createTestSubject(); | ||
|
||
$this->assertFalse($action->supports(new CreateBlik0Transaction(new \stdClass()))); | ||
$this->assertTrue($action->supports(new CreateBlik0Transaction($this->model->reveal()))); | ||
} | ||
|
||
public function test_it_creates_blik0_transaction(): void | ||
{ | ||
$createTransactionToken = $this->prophesize(TokenInterface::class); | ||
$createTransactionToken->getGatewayName()->willReturn('tpay'); | ||
|
||
$this->request->getToken()->willReturn($createTransactionToken); | ||
|
||
$customer = $this->prophesize(CustomerInterface::class); | ||
$customer->getEmail()->willReturn('[email protected]'); | ||
|
||
$billingAddress = $this->prophesize(AddressInterface::class); | ||
$billingAddress->getFullName()->willReturn('Domino Jahas'); | ||
|
||
$order = $this->prophesize(OrderInterface::class); | ||
$order->getLocaleCode()->willReturn('en_US'); | ||
$order->getCustomer()->willReturn($customer); | ||
$order->getBillingAddress()->willReturn($billingAddress); | ||
$order->getNumber()->willReturn('00000001'); | ||
|
||
$this->model->getAmount()->willReturn(123); | ||
$this->model->getOrder()->willReturn($order); | ||
$blikCode = '777456'; | ||
$this->model->getDetails()->willReturn([ | ||
'blik' => $blikCode, | ||
]); | ||
$this->model->setDetails([ | ||
'tpay' => [ | ||
'transaction_id' => '123awsd', | ||
'transaction_payment_url' => 'https://tpay.pay', | ||
], | ||
])->shouldBeCalled(); | ||
|
||
$NOTIFY_URL = 'https://cw.org/notify'; | ||
$THANK_YOU_URL = 'https://cw.org/thank-you'; | ||
|
||
$this->tokenFactory->createToken( | ||
'tpay', | ||
$this->model, | ||
$NOTIFY_URL, | ||
)->willReturn($token = $this->prophesize(TokenInterface::class)); | ||
$token->getTargetUrl()->willReturn($NOTIFY_URL); | ||
|
||
$this->router | ||
->generate('sylius_shop_order_thank_you', ['_locale' => 'en_US', UrlGeneratorInterface::ABSOLUTE_URL]) | ||
->willReturn($THANK_YOU_URL) | ||
; | ||
|
||
$this->router | ||
->generate('commerce_weavers_tpay_payment_notification', ['_locale' => 'en_US'], UrlGeneratorInterface::ABSOLUTE_URL) | ||
->willReturn($NOTIFY_URL) | ||
; | ||
|
||
$transactionsApi = $this->prophesize(TransactionsApi::class); | ||
$transactionsApi->createTransaction([ | ||
'amount' => 12.3, | ||
'description' => 'zamówienie #00000001', | ||
'payer' => [ | ||
'email' => '[email protected]', | ||
'name' => 'Domino Jahas', | ||
], | ||
'pay' => [ | ||
'groupId' => 150, | ||
'blikPaymentData' => [ | ||
'blikToken' => $blikCode, | ||
], | ||
], | ||
'callbacks' => [ | ||
'payerUrls' => [ | ||
'success' => $THANK_YOU_URL, | ||
'error' => $THANK_YOU_URL, | ||
], | ||
'notification' => [ | ||
'url' => $NOTIFY_URL, | ||
], | ||
], | ||
])->shouldBeCalled()->willReturn([ | ||
'transactionId' => '123awsd', | ||
'transactionPaymentUrl' => 'https://tpay.pay', | ||
]); | ||
|
||
$this->api->transactions()->willReturn($transactionsApi); | ||
$this->createTestSubject()->execute($this->request->reveal()); | ||
} | ||
|
||
private function createTestSubject(): CreateBlik0TransactionAction | ||
{ | ||
$action = new CreateBlik0TransactionAction( | ||
$this->router->reveal(), | ||
'sylius_shop_order_thank_you', | ||
'sylius_shop_order_thank_you', | ||
'commerce_weavers_tpay_payment_notification', | ||
); | ||
|
||
$action->setApi($this->api->reveal()); | ||
$action->setGenericTokenFactory($this->tokenFactory->reveal()); | ||
|
||
return $action; | ||
} | ||
} | ||
|