|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* another great project. |
|
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace spec\BitBag\SyliusQuadPayPlugin\Resolver; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusQuadPayPlugin\Client\QuadPayApiClientInterface; |
|
16
|
|
|
use BitBag\SyliusQuadPayPlugin\QuadPayGatewayFactory; |
|
17
|
|
|
use BitBag\SyliusQuadPayPlugin\Resolver\PaymentStateResolver; |
|
18
|
|
|
use BitBag\SyliusQuadPayPlugin\Resolver\PaymentStateResolverInterface; |
|
19
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
20
|
|
|
use Payum\Core\Model\GatewayConfigInterface; |
|
21
|
|
|
use PhpSpec\ObjectBehavior; |
|
22
|
|
|
use SM\Factory\FactoryInterface; |
|
23
|
|
|
use SM\StateMachine\StateMachineInterface; |
|
24
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
|
25
|
|
|
use Sylius\Component\Core\Model\PaymentMethodInterface; |
|
26
|
|
|
use Sylius\Component\Payment\PaymentTransitions; |
|
27
|
|
|
|
|
28
|
|
|
final class PaymentStateResolverSpec extends ObjectBehavior |
|
29
|
|
|
{ |
|
30
|
|
|
function let( |
|
|
|
|
|
|
31
|
|
|
FactoryInterface $stateMachineFactory, |
|
32
|
|
|
QuadPayApiClientInterface $quadPayApiClient, |
|
33
|
|
|
EntityManagerInterface $paymentEntityManager |
|
34
|
|
|
): void { |
|
35
|
|
|
$this->beConstructedWith($stateMachineFactory, $quadPayApiClient, $paymentEntityManager); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_is_initializable(): void |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
$this->shouldHaveType(PaymentStateResolver::class); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
function it_implements_payment_state_resolver_interface(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->shouldHaveType(PaymentStateResolverInterface::class); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
function it_resolves( |
|
49
|
|
|
PaymentInterface $payment, |
|
50
|
|
|
PaymentMethodInterface $paymentMethod, |
|
51
|
|
|
GatewayConfigInterface $gatewayConfig, |
|
52
|
|
|
QuadPayApiClientInterface $quadPayApiClient, |
|
53
|
|
|
FactoryInterface $stateMachineFactory, |
|
54
|
|
|
StateMachineInterface $stateMachine |
|
55
|
|
|
): void { |
|
56
|
|
|
$gatewayConfig->getFactoryName()->willReturn(QuadPayGatewayFactory::FACTORY_NAME); |
|
|
|
|
|
|
57
|
|
|
$gatewayConfig->getConfig()->willReturn([ |
|
58
|
|
|
'clientId' => 'test', |
|
59
|
|
|
'clientSecret' => 'test', |
|
60
|
|
|
'apiEndpoint' => 'https://api-ci.quadpay.com/', |
|
61
|
|
|
'authTokenEndpoint' => 'https://api-ci.quadpay.com/', |
|
62
|
|
|
'apiAudience' => 'https://api-ci.quadpay.com/', |
|
63
|
|
|
]); |
|
64
|
|
|
$paymentMethod->getGatewayConfig()->willReturn($gatewayConfig); |
|
|
|
|
|
|
65
|
|
|
$payment->getMethod()->willReturn($paymentMethod); |
|
|
|
|
|
|
66
|
|
|
$payment->getAmount()->willReturn(222222); |
|
67
|
|
|
$payment->getDetails()->willReturn([ |
|
68
|
|
|
'orderToken' => 'test', |
|
69
|
|
|
]); |
|
70
|
|
|
$quadPayApiClient->setConfig( |
|
71
|
|
|
'test', |
|
72
|
|
|
'test', |
|
73
|
|
|
'https://api-ci.quadpay.com/', |
|
74
|
|
|
'https://api-ci.quadpay.com/', |
|
75
|
|
|
'https://api-ci.quadpay.com/' |
|
76
|
|
|
); |
|
77
|
|
|
$quadPayApiClient->getOrderByToken('test')->willReturn(['orderStatus' => QuadPayApiClientInterface::STATUS_APPROVED]); |
|
78
|
|
|
$stateMachineFactory->get($payment, PaymentTransitions::GRAPH)->willReturn($stateMachine); |
|
|
|
|
|
|
79
|
|
|
$stateMachine->can(PaymentTransitions::TRANSITION_COMPLETE)->willReturn(true); |
|
80
|
|
|
|
|
81
|
|
|
$payment->setDetails(['orderToken' => 'test', 'orderStatus' => 'approved'])->shouldBeCalled(); |
|
|
|
|
|
|
82
|
|
|
$stateMachine->apply(PaymentTransitions::TRANSITION_COMPLETE)->shouldBeCalled(); |
|
83
|
|
|
|
|
84
|
|
|
$this->resolve($payment); |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.