14 class IpnTest extends \PHPUnit\Framework\TestCase
46 'canFetchPaymentReviewUpdate',
52 'getAdditionalInformation',
57 $this->_orderMock = $this->createPartialMock(\
Magento\Sales\Model\OrderFactory::class,
$methods);
58 $this->_orderMock->expects($this->any())->method(
'create')->will($this->returnSelf());
59 $this->_orderMock->expects($this->any())->method(
'loadByIncrementId')->will($this->returnSelf());
60 $this->_orderMock->expects($this->any())->method(
'getId')->will($this->returnSelf());
61 $this->_orderMock->expects($this->any())->method(
'getMethod')->will($this->returnSelf());
62 $this->_orderMock->expects($this->any())->method(
'getStoreId')->will($this->returnSelf());
63 $this->_orderMock->expects($this->any())->method(
'getEmailSent')->will($this->returnValue(
true));
65 $this->configFactory = $this->createPartialMock(\
Magento\Paypal\Model\ConfigFactory::class, [
'create']);
66 $configMock = $this->getMockBuilder(\
Magento\Paypal\Model\Config::class)
67 ->disableOriginalConstructor()
69 $this->configFactory->expects($this->any())->method(
'create')->willReturn($configMock);
70 $configMock->expects($this->any())->method(
'isMethodActive')->will($this->returnValue(
true));
71 $configMock->expects($this->any())->method(
'isMethodAvailable')->will($this->returnValue(
true));
72 $configMock->expects($this->any())->method(
'getValue')->will($this->returnValue(
null));
73 $configMock->expects($this->any())->method(
'getPayPalIpnUrl')
74 ->will($this->returnValue(
'https://ipnpb_paypal_url'));
76 $this->curlFactory = $this->createPartialMock(
77 \
Magento\Framework\HTTP\Adapter\CurlFactory::class,
78 [
'create',
'setConfig',
'write',
'read']
80 $this->curlFactory->expects($this->any())->method(
'create')->will($this->returnSelf());
81 $this->curlFactory->expects($this->any())->method(
'setConfig')->will($this->returnSelf());
82 $this->curlFactory->expects($this->any())->method(
'write')->will($this->returnSelf());
83 $this->curlFactory->expects($this->any())->method(
'read')->will($this->returnValue(
87 $this->_paypalInfo = $this->createPartialMock(
88 \
Magento\Paypal\Model\Info::class,
89 [
'importToPayment',
'getMethod',
'getAdditionalInformation']
91 $this->_paypalInfo->expects($this->any())->method(
'getMethod')->will($this->returnValue(
'some_method'));
92 $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
93 $this->_ipn = $objectHelper->getObject(
94 \
Magento\Paypal\Model\Ipn::class,
96 'configFactory' => $this->configFactory,
97 'curlFactory' => $this->curlFactory,
98 'orderFactory' => $this->_orderMock,
99 'paypalInfo' => $this->_paypalInfo,
100 'data' => [
'payment_status' =>
'Pending',
'pending_reason' =>
'authorization']
107 $this->_orderMock->expects($this->any())->method(
'canFetchPaymentReviewUpdate')->will(
108 $this->returnValue(
false)
111 'setPreparedMessage',
114 'setParentTransactionId',
115 'setIsTransactionClosed',
116 'registerAuthorizationNotification',
119 $payment->expects($this->any())->method(
'setPreparedMessage')->will($this->returnSelf());
120 $payment->expects($this->any())->method(
'setTransactionId')->will($this->returnSelf());
121 $payment->expects($this->any())->method(
'setParentTransactionId')->will($this->returnSelf());
122 $payment->expects($this->any())->method(
'setIsTransactionClosed')->will($this->returnSelf());
123 $this->_orderMock->expects($this->any())->method(
'getPayment')->will($this->returnValue(
$payment));
124 $this->_orderMock->expects($this->any())->method(
'getAdditionalInformation')->will($this->returnValue([]));
126 $this->_paypalInfo->expects($this->once())->method(
'importToPayment');
127 $this->_ipn->processIpnRequest();
132 $this->_orderMock->expects($this->any())->method(
'getPayment')->will($this->returnSelf());
133 $this->_orderMock->expects($this->any())->method(
'canFetchPaymentReviewUpdate')->will($this->returnValue(
true));
134 $this->_orderMock->expects($this->once())->method(
'update')->with(
true)->will($this->returnSelf());
135 $this->_ipn->processIpnRequest();
140 $paymentMock = $this->createPartialMock(
142 [
'getAdditionalInformation',
'__wakeup',
'registerCaptureNotification']
144 $paymentMock->expects($this->any())
145 ->method(
'getAdditionalInformation')
146 ->will($this->returnValue([]));
147 $paymentMock->expects($this->any())
148 ->method(
'registerCaptureNotification')
149 ->will($this->returnValue(
true));
150 $this->_orderMock->expects($this->any())->method(
'getPayment')->will($this->returnValue($paymentMock));
151 $this->_orderMock->expects($this->any())->method(
'canFetchPaymentReviewUpdate')->will($this->returnValue(
true));
152 $this->_orderMock->expects($this->once())->method(
'getState')->will(
155 $this->_paypalInfo->expects($this->once())
156 ->method(
'importToPayment')
159 'payment_status' =>
'pending',
160 'pending_reason' =>
'fraud',
161 'collected_fraud_filters' => [
'Maximum Transaction Amount'],
165 $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
166 $this->_ipn = $objectHelper->getObject(
167 \
Magento\Paypal\Model\Ipn::class,
169 'configFactory' => $this->configFactory,
170 'curlFactory' => $this->curlFactory,
171 'orderFactory' => $this->_orderMock,
172 'paypalInfo' => $this->_paypalInfo,
174 'payment_status' =>
'Pending',
175 'pending_reason' =>
'fraud',
176 'fraud_management_pending_filters_1' =>
'Maximum Transaction Amount',
180 $this->_ipn->processIpnRequest();
181 $this->assertEquals(
'IPN "Pending"', $paymentMock->getPreparedMessage());
184 public function testRegisterPaymentDenial()
187 $paymentMock = $this->getMockBuilder(\
Magento\Sales\Model\
Order\Payment::class)
189 'getAdditionalInformation',
191 'setNotificationResult',
192 'setIsTransactionClosed',
195 ->disableOriginalConstructor()
198 $paymentMock->expects($this->exactly(6))->method(
'getAdditionalInformation')->willReturn([]);
199 $paymentMock->expects($this->once())->method(
'setTransactionId')->willReturnSelf();
200 $paymentMock->expects($this->once())->method(
'setNotificationResult')->willReturnSelf();
201 $paymentMock->expects($this->once())->method(
'setIsTransactionClosed')->willReturnSelf();
202 $paymentMock->expects($this->once())->method(
'deny')->with(
false)->willReturnSelf();
204 $this->_orderMock->expects($this->exactly(4))->method(
'getPayment')->will($this->returnValue($paymentMock));
206 $this->_paypalInfo->expects($this->once())
207 ->method(
'importToPayment')
208 ->with([
'payment_status' =>
'denied'], $paymentMock);
210 $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
211 $this->_ipn = $objectHelper->getObject(
212 \
Magento\Paypal\Model\Ipn::class,
214 'configFactory' => $this->configFactory,
215 'curlFactory' => $this->curlFactory,
216 'orderFactory' => $this->_orderMock,
217 'paypalInfo' => $this->_paypalInfo,
219 'payment_status' =>
'Denied',
224 $this->_ipn->processIpnRequest();
testPaymentReviewRegisterPaymentFraud()
testPaymentReviewRegisterPaymentAuthorization()
const STATE_PENDING_PAYMENT
testLegacyRegisterPaymentAuthorization()