6 declare(strict_types=1);
21 use PHPUnit\Framework\TestCase;
41 private $paymentInstance;
61 private $transactionRepository;
71 $this->nvp = $this->createPartialMock(
73 [
'getData',
'setProcessableErrors',
'callDoAuthorization']
75 $this->nvp->method(
'getData')->willReturn([]);
76 $this->nvp->method(
'setProcessableErrors')->willReturnSelf();
78 $this->pro = $this->createPartialMock(
80 [
'setMethod',
'getApi',
'importPaymentInfo']
82 $this->pro->method(
'getApi')->willReturn($this->nvp);
84 $this->transaction = $this->getMockForAbstractClass(TransactionInterface::class);
85 $this->transactionRepository = $this->createPartialMock(
86 TransactionRepository::class,
87 [
'getByTransactionType']
89 $this->transactionRepository->method(
'getByTransactionType')->willReturn($this->transaction);
94 'data' => [$this->pro],
95 'transactionRepository' => $this->transactionRepository,
99 $this->paymentInstance = $this->getMockForAbstractClass(MethodInterface::class);
100 $this->payment = $this->createPartialMock(
103 'getAmountAuthorized',
109 'addTransactionCommentsToOrder',
110 'setAmountAuthorized',
113 $this->payment->method(
'getMethodInstance')
114 ->willReturn($this->paymentInstance);
116 $this->payment->method(
'addTransaction')
117 ->willReturn($this->transaction);
127 $this->order = $this->createPartialMock(
129 [
'getId',
'getPayment',
'getTotalDue',
'getBaseTotalDue']
131 $this->order->method(
'getPayment')
132 ->willReturn($this->payment);
133 $this->order->method(
'getId')
139 $this->order->method(
'getTotalDue')
140 ->willReturn($totalDue);
141 $this->order->method(
'getBaseTotalDue')
142 ->willReturn($baseTotalDue);
144 $this->payment->method(
'getMethod')
145 ->willReturn(
'paypal_express');
146 $this->payment->method(
'getId')
148 $this->payment->method(
'getOrder')
149 ->willReturn($this->order);
150 $this->payment->method(
'getAmountAuthorized')
153 $this->paymentInstance->method(
'getConfigPaymentAction')
154 ->willReturn(
'order');
156 $this->nvp->expects(static::once())
157 ->method(
'callDoAuthorization')
160 $this->payment->expects(static::once())
161 ->method(
'addTransaction')
163 ->willReturn($this->transaction);
165 $this->payment->method(
'addTransactionCommentsToOrder')
166 ->with($this->transaction);
168 $this->payment->method(
'setAmountAuthorized')
171 $this->express->authorizeOrder($this->order);
187 float $authorizedAmount,
190 $this->payment->method(
'getMethod')
193 $this->paymentInstance->method(
'getConfigPaymentAction')
194 ->willReturn($action);
196 $this->payment->method(
'getAmountAuthorized')
197 ->willReturn($authorizedAmount);
199 static::assertEquals($isAuthAllowed, $this->express->isOrderAuthorizationAllowed($this->payment));
210 [
'paypal_express',
'sale', 10,
false],
211 [
'paypal_express',
'order', 50,
false],
212 [
'paypal_express',
'capture', 0,
false],
213 [
'paypal_express',
'order', 0,
true],
214 [
'braintree',
'authorize', 10,
false],
215 [
'braintree',
'authorize', 0,
false],
testIsOrderAuthorizationAllowed(string $method, string $action, float $authorizedAmount, bool $isAuthAllowed)