-
Notifications
You must be signed in to change notification settings - Fork 3
/
AuthorizeActionTest.php
106 lines (86 loc) · 3.64 KB
/
AuthorizeActionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
declare(strict_types=1);
namespace Setono\Payum\QuickPay\Tests\Action;
use Exception;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Model\Token;
use Payum\Core\Reply\HttpRedirect;
use Payum\Core\Request\Authorize;
use Payum\Core\Request\Convert;
use Payum\Core\Security\GenericTokenFactoryAwareInterface;
use Payum\Core\Security\GenericTokenFactoryInterface;
use ReflectionClass;
use ReflectionException;
use Setono\Payum\QuickPay\Action\AuthorizeAction;
use Setono\Payum\QuickPay\Action\ConvertPaymentAction;
use Setono\Payum\QuickPay\Model\QuickPayPaymentOperation;
class AuthorizeActionTest extends ActionTestAbstract
{
protected $requestClass = Authorize::class;
protected $actionClass = AuthorizeAction::class;
/**
* @test
*
* @throws ReflectionException
*/
public function shouldImplementGenericTokenFactoryAwareInterface(): void
{
$rc = new ReflectionClass($this->actionClass);
self::assertTrue($rc->implementsInterface(GenericTokenFactoryAwareInterface::class));
}
/**
* @test
*
* @throws Exception
*/
public function shouldRedirectToPaymentLink(): void
{
$payment = $this->createPayment();
$token = new Token();
$token->setTargetUrl('theCallbackUrl');
$token->setAfterUrl('theContinueUrl');
$token->setGatewayName('quickpay');
$convert = new Convert($payment, 'array', $token);
$convertPaymentAction = new ConvertPaymentAction();
$convertPaymentAction->setGateway($this->gateway);
$convertPaymentAction->setApi($this->api);
$convertPaymentAction->execute($convert);
$payment->setDetails($convert->getResult());
$details = ArrayObject::ensureArrayObject($payment->getDetails());
$token->setDetails($details);
/** @var Authorize $authorize */
$authorize = new $this->requestClass($token);
$authorize->setModel($details);
$tokenFactory = $this->createMock(GenericTokenFactoryInterface::class);
$tokenFactory
->expects($this->once())
->method('createNotifyToken')
->with('quickpay', $this->identicalTo($details))
->willReturn($token)
;
/** @var AuthorizeAction $action */
$action = new $this->actionClass();
$action->setGateway($this->gateway);
$action->setApi($this->api);
$action->setGenericTokenFactory($tokenFactory);
try {
$action->execute($authorize);
} catch (HttpRedirect $redirect) {
self::assertStringStartsWith('https://payment.quickpay.net/payments/', $redirect->getUrl());
}
// Authorize payment with test card
$details['card'] = $this->getTestCard()->toArray();
$details['acquirer'] = 'clearhaus';
$quickpayPayment = $this->api->authorizePayment($details['quickpayPayment'], $details);
// Validate that we received the payment from the operation
self::assertEquals($details['quickpayPayment']->getId(), $quickpayPayment->getId());
// Reload payment to get the status of the authorize operation
sleep(1);
$quickpayPayment = $this->api->getPayment(new ArrayObject(['quickpayPaymentId' => $quickpayPayment->getId()]));
// Validate authorize operation
$latestOperation = $quickpayPayment->getLatestOperation();
self::assertEquals(QuickPayPaymentOperation::TYPE_AUTHORIZE, $latestOperation->getType());
self::assertEquals(QuickPayPaymentOperation::STATUS_CODE_APPROVED, $latestOperation->getStatusCode());
self::assertEquals($details['amount'], $latestOperation->getAmount());
}
}