1 | <?php |
||||||
2 | |||||||
3 | namespace ByTIC\Payments\Mobilpay\Tests; |
||||||
4 | |||||||
5 | use ByTIC\Common\Tests\Fixtures\Unit\Payments\PaymentMethod; |
||||||
6 | use ByTIC\Omnipay\Mobilpay\Message\CompletePurchaseResponse; |
||||||
7 | use ByTIC\Omnipay\Mobilpay\Message\PurchaseRequest; |
||||||
8 | use ByTIC\Omnipay\Mobilpay\Message\PurchaseResponse; |
||||||
9 | use ByTIC\Omnipay\Mobilpay\Message\ServerCompletePurchaseResponse; |
||||||
10 | use ByTIC\Omnipay\Mobilpay\Models\Request\Card; |
||||||
11 | use ByTIC\Payments\Mobilpay\Gateway; |
||||||
12 | use ByTIC\Payments\Mobilpay\Message\Soap\Payment\DoPayTRequest; |
||||||
13 | use ByTIC\Payments\Mobilpay\Tests\Fixtures\MobilpayData; |
||||||
14 | use Http\Discovery\Psr17FactoryDiscovery; |
||||||
15 | |||||||
16 | /** |
||||||
17 | * Class GatewayTest |
||||||
18 | * @package ByTIC\Payments\Mobilpay\Tests |
||||||
19 | */ |
||||||
20 | class GatewayTest extends \ByTIC\Payments\Tests\Gateways\GatewayTest |
||||||
21 | { |
||||||
22 | /** |
||||||
23 | * @var Gateway |
||||||
24 | */ |
||||||
25 | protected $gateway; |
||||||
26 | |||||||
27 | public function testPurchaseResponse() |
||||||
28 | { |
||||||
29 | $this->purchase->id = rand(111111111, 999999999); |
||||||
30 | |||||||
31 | /** @var PurchaseRequest $request */ |
||||||
32 | $request = $this->gateway->purchaseFromModel($this->purchase); |
||||||
33 | self::assertSame(false, $request->getTestMode()); |
||||||
34 | |||||||
35 | /** @var PurchaseResponse $response */ |
||||||
36 | $response = $request->send(); |
||||||
37 | self::assertInstanceOf(PurchaseResponse::class, $response); |
||||||
38 | |||||||
39 | $data = $response->getRedirectData(); |
||||||
40 | self::assertCount(2, $data); |
||||||
41 | self::assertSame('https://secure.mobilpay.ro', $response->getRedirectUrl()); |
||||||
42 | |||||||
43 | $gatewayResponse = $this->client->request( |
||||||
44 | 'POST', |
||||||
45 | $response->getRedirectUrl(), |
||||||
46 | ['Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'], |
||||||
47 | Psr17FactoryDiscovery::findStreamFactory()->createStream(http_build_query($data, '', '&')) |
||||||
48 | ); |
||||||
49 | |||||||
50 | self::assertSame(200, $gatewayResponse->getStatusCode()); |
||||||
51 | |||||||
52 | //Validate first Response |
||||||
53 | $body = $gatewayResponse->getBody()->__toString(); |
||||||
54 | self::assertRegExp('/ID Tranzactie/', $body); |
||||||
55 | self::assertRegExp('/Descriere plata/', $body); |
||||||
56 | self::assertRegExp('/Site comerciant/', $body); |
||||||
57 | } |
||||||
58 | |||||||
59 | public function testPurchaseResponseSandbox() |
||||||
60 | { |
||||||
61 | // Debug::debug($this->gateway->getParameters()); |
||||||
62 | $this->gateway->setTestMode(true); |
||||||
63 | /** @var PurchaseRequest $request */ |
||||||
64 | $request = $this->gateway->purchaseFromModel($this->purchase); |
||||||
65 | self::assertSame(true, $request->getTestMode()); |
||||||
66 | |||||||
67 | $response = $request->send(); |
||||||
68 | self::assertInstanceOf(PurchaseResponse::class, $response); |
||||||
69 | |||||||
70 | $data = $response->getRedirectData(); |
||||||
71 | |||||||
72 | self::assertCount(2, $data); |
||||||
73 | self::assertSame('http://sandboxsecure.mobilpay.ro', $response->getRedirectUrl()); |
||||||
74 | |||||||
75 | $gatewayResponse = $this->client->request( |
||||||
76 | 'POST', |
||||||
77 | $response->getRedirectUrl(), |
||||||
78 | ['Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'], |
||||||
79 | Psr17FactoryDiscovery::findStreamFactory()->createStream(http_build_query($data, '', '&')) |
||||||
80 | ); |
||||||
81 | self::assertSame(200, $gatewayResponse->getStatusCode()); |
||||||
82 | |||||||
83 | //Validate first Response |
||||||
84 | $body = $gatewayResponse->getBody()->__toString(); |
||||||
85 | self::assertRegExp('/ID Tranzactie/', $body); |
||||||
86 | self::assertRegExp('/Descriere plata/', $body); |
||||||
87 | self::assertRegExp('/Site comerciant/', $body); |
||||||
88 | } |
||||||
89 | |||||||
90 | public function test_purchaseWithToken() |
||||||
91 | { |
||||||
92 | $request = $this->gateway->purchaseWithToken([]); |
||||||
93 | self::assertInstanceOf(DoPayTRequest::class, $request); |
||||||
94 | |||||||
95 | } |
||||||
96 | |||||||
97 | public function testCompletePurchaseResponse() |
||||||
98 | { |
||||||
99 | $httpRequest = MobilpayData::getCompletePurchaseRequest(); |
||||||
100 | |||||||
101 | /** @var CompletePurchaseResponse $response */ |
||||||
102 | $response = $this->gatewayManager->detectItemFromHttpRequest( |
||||||
103 | $this->purchaseManager, |
||||||
104 | 'completePurchase', |
||||||
105 | $httpRequest |
||||||
106 | ); |
||||||
107 | |||||||
108 | self::assertInstanceOf(CompletePurchaseResponse::class, $response); |
||||||
109 | |||||||
110 | $model = $response->getModel(); |
||||||
0 ignored issues
–
show
|
|||||||
111 | self::assertSame($response->isSuccessful(), $model->status == 'active'); |
||||||
112 | self::assertEquals($httpRequest->query->get('id'), $model->id); |
||||||
113 | } |
||||||
114 | |||||||
115 | public function test_ServerCompletePurchaseConfirmedResponse() |
||||||
116 | { |
||||||
117 | $httpRequest = MobilpayData::getServerCompletePurchaseRequest(); |
||||||
118 | $response = $this->createServerCompletePurchaseResponse($httpRequest); |
||||||
119 | |||||||
120 | self::assertTrue($response->isSuccessful()); |
||||||
121 | |||||||
122 | $content = $response->getContent(); |
||||||
123 | $validContent = '<?xml version="1.0" encoding="utf-8"?>' . "\n"; |
||||||
124 | $validContent .= '<crc>1e59360874ae14eb39c7a038b205bf0d</crc>'; |
||||||
125 | self::assertSame($validContent, $content); |
||||||
126 | } |
||||||
127 | |||||||
128 | /** |
||||||
129 | * @param $request |
||||||
130 | * @return ServerCompletePurchaseResponse |
||||||
131 | */ |
||||||
132 | protected function createServerCompletePurchaseResponse($request) |
||||||
133 | { |
||||||
134 | /** @var ServerCompletePurchaseResponse $response */ |
||||||
135 | $response = $this->gatewayManager->detectItemFromHttpRequest( |
||||||
136 | $this->purchaseManager, |
||||||
137 | 'serverCompletePurchase', |
||||||
138 | $request |
||||||
139 | ); |
||||||
140 | |||||||
141 | self::assertInstanceOf(ServerCompletePurchaseResponse::class, $response); |
||||||
142 | self::assertInstanceOf(Card::class, $response->getMobilpayRequest()); |
||||||
143 | |||||||
144 | return $response; |
||||||
145 | } |
||||||
146 | |||||||
147 | public function test_ServerCompletePurchaseInsufficientFondsResponse() |
||||||
148 | { |
||||||
149 | $httpRequest = MobilpayData::getServerCompletePurchaseRequestInsufficientFonds(); |
||||||
150 | $response = $this->createServerCompletePurchaseResponse($httpRequest); |
||||||
151 | |||||||
152 | self::assertSame('20', $response->getCode()); |
||||||
153 | self::assertFalse($response->isSuccessful()); |
||||||
154 | self::assertFalse($response->isPending()); |
||||||
155 | self::assertFalse($response->isCancelled()); |
||||||
156 | self::assertSame('error', $response->getModelResponseStatus()); |
||||||
0 ignored issues
–
show
The method
getModelResponseStatus() does not exist on ByTIC\Omnipay\Mobilpay\M...ompletePurchaseResponse . Are you sure you never get this type here, but always one of the subclasses?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
157 | self::assertSame('Fonduri insuficiente.', $response->getMessage()); |
||||||
158 | |||||||
159 | $content = $response->getContent(); |
||||||
160 | $validContent = '<?xml version="1.0" encoding="utf-8"?>' . "\n"; |
||||||
161 | $validContent .= '<crc error_type="20" error_code="20">Fonduri insuficiente.</crc>'; |
||||||
162 | self::assertSame($validContent, $content); |
||||||
163 | } |
||||||
164 | |||||||
165 | public function testServerCompletePurchaseGenericError35Response() |
||||||
166 | { |
||||||
167 | $httpRequest = MobilpayData::getServerCompletePurchaseRequestGenericError35(); |
||||||
168 | $response = $this->createServerCompletePurchaseResponse($httpRequest); |
||||||
169 | |||||||
170 | self::assertSame('35', $response->getCode()); |
||||||
171 | self::assertFalse($response->isSuccessful()); |
||||||
172 | self::assertFalse($response->isPending()); |
||||||
173 | self::assertFalse($response->isCancelled()); |
||||||
174 | self::assertSame('error', $response->getModelResponseStatus()); |
||||||
175 | self::assertSame(' ', $response->getMessage()); |
||||||
176 | |||||||
177 | $content = $response->getContent(); |
||||||
178 | $validContent = '<?xml version="1.0" encoding="utf-8"?>' . "\n"; |
||||||
179 | $validContent .= '<crc error_type="35" error_code="35"> </crc>'; |
||||||
180 | self::assertSame($validContent, $content); |
||||||
181 | } |
||||||
182 | |||||||
183 | public function testServerCompletePurchaseDeclined3DSecureResponse() |
||||||
184 | { |
||||||
185 | $httpRequest = MobilpayData::getServerCompletePurchaseRequestDeclined3DSecure(); |
||||||
186 | $response = $this->createServerCompletePurchaseResponse($httpRequest); |
||||||
187 | |||||||
188 | self::assertSame('39', $response->getCode()); |
||||||
189 | self::assertFalse($response->isSuccessful()); |
||||||
190 | self::assertFalse($response->isPending()); |
||||||
191 | self::assertFalse($response->isCancelled()); |
||||||
192 | self::assertSame('error', $response->getModelResponseStatus()); |
||||||
193 | self::assertSame('gwDeclined3DSecure', $response->getMessage()); |
||||||
194 | |||||||
195 | $content = $response->getContent(); |
||||||
196 | $validContent = '<?xml version="1.0" encoding="utf-8"?>' . "\n"; |
||||||
197 | $validContent .= '<crc error_type="39" error_code="39">gwDeclined3DSecure</crc>'; |
||||||
198 | self::assertSame($validContent, $content); |
||||||
199 | } |
||||||
200 | |||||||
201 | protected function setUp(): void |
||||||
202 | { |
||||||
203 | parent::setUp(); |
||||||
204 | |||||||
205 | /** @var PaymentMethod $paymentMethod */ |
||||||
206 | $paymentMethod = $this->purchase->getPaymentMethod(); |
||||||
0 ignored issues
–
show
Are you sure the assignment to
$paymentMethod is correct as $this->purchase->getPaymentMethod() targeting ByTIC\Payments\Tests\Fix...ord::getPaymentMethod() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||||
207 | $paymentMethod->options = trim(MobilpayData::getMethodOptions()); |
||||||
208 | |||||||
209 | $this->purchase->created = date('Y-m-d H:i:s'); |
||||||
210 | |||||||
211 | MobilpayData::buildCertificates(); |
||||||
212 | $this->gateway = $paymentMethod->getType()->getGateway(); |
||||||
0 ignored issues
–
show
The method
getGateway() does not exist on ByTIC\Payments\Models\Methods\Types\AbstractType . It seems like you code against a sub-type of ByTIC\Payments\Models\Methods\Types\AbstractType such as ByTIC\Payments\Models\Methods\Types\CreditCards .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
213 | $this->gateway->setPaymentMethod($paymentMethod); |
||||||
0 ignored issues
–
show
The method
setPaymentMethod() does not exist on Omnipay\Common\GatewayInterface . It seems like you code against a sub-type of Omnipay\Common\GatewayInterface such as ByTIC\Common\Payments\Ga...AbstractGateway\Gateway or ByTIC\Payments\Gateways\Providers\Twispay\Gateway or ByTIC\Payments\Gateways\Providers\Payu\Gateway or ByTIC\Payments\Mobilpay\Gateway or ByTIC\Payments\Gateways\Providers\Romcard\Gateway or ByTIC\Payments\Gateways\...iders\Euplatesc\Gateway or ByTIC\Payments\Gateways\...ers\PlatiOnline\Gateway or ByTIC\Payments\Gateways\Providers\Paylike\Gateway .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
214 | } |
||||||
215 | |||||||
216 | /** |
||||||
217 | * @param $purchase |
||||||
218 | * @return \Mockery\Mock |
||||||
219 | */ |
||||||
220 | protected function generatePurchaseManagerMock($purchase) |
||||||
221 | { |
||||||
222 | $manager = parent::generatePurchaseManagerMock($purchase); |
||||||
223 | |||||||
224 | $purchase->id = 39188; |
||||||
225 | $manager->shouldReceive('findOne')->withAnyArgs()->andReturn($purchase); |
||||||
226 | |||||||
227 | return $manager; |
||||||
228 | } |
||||||
229 | } |
||||||
230 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.