|
5 | 5 |
|
6 | 6 | class TestPayments(unittest.TestCase): |
7 | 7 |
|
| 8 | + adyen = Adyen.Adyen() |
| 9 | + |
| 10 | + client = adyen.client |
| 11 | + test = BaseTest(adyen) |
| 12 | + client.username = "YourWSUser" |
| 13 | + client.password = "YourWSPassword" |
| 14 | + client.platform = "test" |
| 15 | + client.app_name = "appname" |
| 16 | + client.xapikey = "" |
| 17 | + |
8 | 18 | def test_authorise_success_mocked(self): |
9 | 19 | request = {} |
10 | 20 | request['merchantAccount'] = "YourMerchantAccount" |
@@ -189,40 +199,222 @@ def test_error_401_mocked(self): |
189 | 199 | self.adyen.payment.authorise, request) |
190 | 200 |
|
191 | 201 |
|
192 | | -class BasicAuth(TestPayments): |
| 202 | +class TestPaymentsWithXapiKey(unittest.TestCase): |
| 203 | + |
193 | 204 | adyen = Adyen.Adyen() |
194 | 205 |
|
195 | 206 | client = adyen.client |
196 | 207 | test = BaseTest(adyen) |
197 | | - client.username = "YourWSUser" |
198 | | - client.password = "YourWSPassword" |
199 | 208 | client.platform = "test" |
200 | 209 | client.app_name = "appname" |
| 210 | + client.username = "YourWSUser" |
| 211 | + client.password = "YourWSPassword" |
| 212 | + client.xapikey = "" |
201 | 213 |
|
| 214 | + def test_authorise_success_mocked(self): |
| 215 | + request = {} |
| 216 | + request['merchantAccount'] = "YourMerchantAccount" |
| 217 | + request['amount'] = {"value": "100000", "currency": "EUR"} |
| 218 | + request['reference'] = "123456" |
| 219 | + request['card'] = { |
| 220 | + "number": "5136333333333335", |
| 221 | + "expiryMonth": "08", |
| 222 | + "expiryYear": "2018", |
| 223 | + "cvc": "737", |
| 224 | + "holderName": "John Doe" |
| 225 | + } |
| 226 | + self.adyen.client = self.test.create_client_from_file(200, request, |
| 227 | + 'test/mocks/' |
| 228 | + 'authorise' |
| 229 | + '-success' |
| 230 | + '.json') |
| 231 | + result = self.adyen.payment.authorise(request) |
| 232 | + self.assertEqual("Authorised", result.message['resultCode']) |
| 233 | + self.assertEqual("8/2018", |
| 234 | + result.message['additionalData']['expiryDate']) |
| 235 | + self.assertEqual("411111", |
| 236 | + result.message['additionalData']['cardBin']) |
| 237 | + self.assertEqual("1111", |
| 238 | + result.message['additionalData']['cardSummary']) |
| 239 | + self.assertEqual("Holder", |
| 240 | + result.message['additionalData']['cardHolderName']) |
| 241 | + self.assertEqual("true", |
| 242 | + result.message['additionalData']['threeDOffered']) |
| 243 | + self.assertEqual("false", |
| 244 | + result.message['additionalData'] |
| 245 | + ['threeDAuthenticated']) |
| 246 | + self.assertEqual("69746", result.message['authCode']) |
| 247 | + self.assertEqual(11, len(result.message['fraudResult']['results'])) |
| 248 | + fraud_checks = result.message['fraudResult']['results'] |
| 249 | + fraud_check_result = fraud_checks[0]['FraudCheckResult'] |
| 250 | + self.assertEqual("CardChunkUsage", fraud_check_result['name']) |
| 251 | + self.assertEqual(8, fraud_check_result['accountScore']) |
| 252 | + self.assertEqual(2, fraud_check_result['checkId']) |
202 | 253 |
|
203 | | -class XApiKey(TestPayments): |
204 | | - adyen = Adyen.Adyen() |
| 254 | + def test_authorise_error010_mocked(self): |
| 255 | + request = {} |
| 256 | + request['merchantAccount'] = "testaccount" |
| 257 | + request['amount'] = {"value": "100000", "currency": "EUR"} |
| 258 | + request['reference'] = "123456" |
| 259 | + request['card'] = { |
| 260 | + "number": "5136333333333335", |
| 261 | + "expiryMonth": "08", |
| 262 | + "expiryYear": "2018", |
| 263 | + "cvc": "737", |
| 264 | + "holderName": "John Doe" |
| 265 | + } |
| 266 | + self.adyen.client = self.test.create_client_from_file(403, request, |
| 267 | + 'test/mocks/' |
| 268 | + 'authorise-error' |
| 269 | + '-010' |
| 270 | + '.json') |
| 271 | + self.assertRaises(Adyen.AdyenAPIInvalidPermission, |
| 272 | + self.adyen.payment.authorise, request) |
205 | 273 |
|
206 | | - client = adyen.client |
207 | | - test = BaseTest(adyen) |
208 | | - client.platform = "test" |
209 | | - client.app_name = "appname" |
210 | | - client.xapikey = "YourWSXApiKey" |
| 274 | + def test_authorise_error_cvc_declined_mocked(self): |
| 275 | + request = {} |
| 276 | + request['amount'] = {"value": "100000", "currency": "EUR"} |
| 277 | + request['reference'] = "123456" |
| 278 | + request['card'] = { |
| 279 | + "number": "5136333333333335", |
| 280 | + "expiryMonth": "08", |
| 281 | + "expiryYear": "2018", |
| 282 | + "cvc": "787", |
| 283 | + "holderName": "John Doe" |
| 284 | + } |
| 285 | + self.adyen.client = self.test.create_client_from_file(200, request, |
| 286 | + 'test/mocks/' |
| 287 | + 'authorise' |
| 288 | + '-error-' |
| 289 | + 'cvc-declined' |
| 290 | + '.json') |
| 291 | + result = self.adyen.payment.authorise(request) |
| 292 | + self.assertEqual("Refused", result.message['resultCode']) |
| 293 | + |
| 294 | + def test_authorise_success_3d_mocked(self): |
| 295 | + request = {} |
| 296 | + request['merchantAccount'] = "YourMerchantAccount" |
| 297 | + request['amount'] = {"value": "100000", "currency": "EUR"} |
| 298 | + request['reference'] = "123456" |
| 299 | + request['card'] = { |
| 300 | + "number": "5136333333333335", |
| 301 | + "expiryMonth": "08", |
| 302 | + "expiryYear": "2018", |
| 303 | + "cvc": "787", |
| 304 | + "holderName": "John Doe" |
| 305 | + } |
| 306 | + request['browserInfo'] = { |
| 307 | + "userAgent": "YourUserAgent", |
| 308 | + "acceptHeader": "YourAcceptHeader" |
| 309 | + } |
| 310 | + self.adyen.client = self.test.create_client_from_file(200, request, |
| 311 | + 'test/mocks/' |
| 312 | + 'authorise' |
| 313 | + '-success' |
| 314 | + '-3d.json') |
| 315 | + result = self.adyen.payment.authorise(request) |
| 316 | + self.assertEqual("RedirectShopper", result.message['resultCode']) |
| 317 | + self.assertIsNotNone(result.message['md']) |
| 318 | + self.assertIsNotNone(result.message['issuerUrl']) |
| 319 | + self.assertIsNotNone(result.message['paRequest']) |
| 320 | + |
| 321 | + def test_authorise_3d_success_mocked(self): |
| 322 | + request = {} |
| 323 | + request['merchantAccount'] = "YourMerchantAccount" |
| 324 | + request['md'] = "testMD" |
| 325 | + request['paResponse'] = "paresponsetest" |
| 326 | + request['browserInfo'] = { |
| 327 | + "userAgent": "YourUserAgent", |
| 328 | + "acceptHeader": "YourAcceptHeader" |
| 329 | + } |
| 330 | + self.adyen.client = self.test.create_client_from_file(200, request, |
| 331 | + 'test/mocks/' |
| 332 | + 'authorise3d-' |
| 333 | + 'success.json') |
| 334 | + result = self.adyen.payment.authorise3d(request) |
| 335 | + self.assertEqual("Authorised", result.message['resultCode']) |
| 336 | + self.assertIsNotNone(result.message['pspReference']) |
211 | 337 |
|
| 338 | + def test_authorise_cse_success_mocked(self): |
| 339 | + request = {} |
| 340 | + request['amount'] = {"value": "1234", "currency": "EUR"} |
| 341 | + request['merchantAccount'] = "YourMerchantAccount" |
| 342 | + request['reference'] = "YourReference" |
| 343 | + request['additionalData'] = { |
| 344 | + "card.encrypted.json": "YourCSEToken" |
| 345 | + } |
| 346 | + self.adyen.client = self.test.create_client_from_file(200, request, |
| 347 | + 'test/mocks/' |
| 348 | + 'authorise' |
| 349 | + '-success' |
| 350 | + '-cse.json') |
| 351 | + result = self.adyen.payment.authorise(request) |
| 352 | + self.assertEqual("Authorised", result.message['resultCode']) |
| 353 | + |
| 354 | + def test_authorise_cse_error_expired_mocked(self): |
| 355 | + request = {} |
| 356 | + request['amount'] = {"value": "1234", "currency": "EUR"} |
| 357 | + request['merchantAccount'] = "YourMerchantAccount" |
| 358 | + request['reference'] = "YourReference" |
| 359 | + request['additionalData'] = { |
| 360 | + "card.encrypted.json": "YourCSEToken" |
| 361 | + } |
| 362 | + |
| 363 | + self.adyen.client = self.test.create_client_from_file(200, request, |
| 364 | + 'test/mocks/' |
| 365 | + 'authorise' |
| 366 | + '-error-' |
| 367 | + 'expired.json') |
| 368 | + result = self.adyen.payment.authorise(request) |
| 369 | + self.assertEqual("Refused", result.message['resultCode']) |
| 370 | + self.assertEqual("DECLINED Expiry Incorrect", |
| 371 | + result.message['additionalData']['refusalReasonRaw']) |
| 372 | + |
| 373 | + def test_error_401_mocked(self): |
| 374 | + request = {} |
| 375 | + request['merchantAccount'] = "YourMerchantAccount" |
| 376 | + request['amount'] = {"value": "100000", "currency": "EUR"} |
| 377 | + request['reference'] = "123456" |
| 378 | + request['card'] = { |
| 379 | + "number": "5136333333333335", |
| 380 | + "expiryMonth": "08", |
| 381 | + "expiryYear": "2018", |
| 382 | + "cvc": "787", |
| 383 | + "holderName": "John Doe" |
| 384 | + } |
| 385 | + self.adyen.client = self.test.create_client_from_file(401, request, |
| 386 | + 'test/mocks/' |
| 387 | + 'authorise' |
| 388 | + '-error-' |
| 389 | + '010.json') |
| 390 | + self.assertRaisesRegexp(Adyen.AdyenAPIAuthenticationError, |
| 391 | + "Unable to authenticate with Adyen's Servers." |
| 392 | + " Please verify the credentials set with the" |
| 393 | + " Adyen base class. Please reach out to your" |
| 394 | + " Adyen Admin if the problem persists", |
| 395 | + self.adyen.payment.authorise, request) |
212 | 396 |
|
213 | | -def test_with(auth): |
214 | | - auth.client.http_force = "requests" |
215 | | - suite = unittest.TestLoader().loadTestsFromTestCase(auth) |
216 | | - unittest.TextTestRunner(verbosity=2).run(suite) |
217 | | - auth.client.http_force = "pycurl" |
218 | | - auth.client.http_init = False |
219 | | - suite = unittest.TestLoader().loadTestsFromTestCase(auth) |
220 | | - unittest.TextTestRunner(verbosity=2).run(suite) |
221 | | - auth.client.http_force = "other" |
222 | | - auth.client.http_init = False |
223 | | - suite = unittest.TestLoader().loadTestsFromTestCase(auth) |
224 | | - unittest.TextTestRunner(verbosity=2).run(suite) |
225 | 397 |
|
| 398 | +TestPayments.client.http_force = "requests" |
| 399 | +suite = unittest.TestLoader().loadTestsFromTestCase(TestPayments) |
| 400 | +unittest.TextTestRunner(verbosity=2).run(suite) |
| 401 | +TestPayments.client.http_force = "pycurl" |
| 402 | +TestPayments.client.http_init = False |
| 403 | +suite = unittest.TestLoader().loadTestsFromTestCase(TestPayments) |
| 404 | +unittest.TextTestRunner(verbosity=2).run(suite) |
| 405 | +TestPayments.client.http_force = "other" |
| 406 | +TestPayments.client.http_init = False |
| 407 | +suite = unittest.TestLoader().loadTestsFromTestCase(TestPayments) |
| 408 | +unittest.TextTestRunner(verbosity=2).run(suite) |
226 | 409 |
|
227 | | -test_with(BasicAuth) |
228 | | -test_with(XApiKey) |
| 410 | +TestPaymentsWithXapiKey.client.http_force = "requests" |
| 411 | +suite = unittest.TestLoader().loadTestsFromTestCase(TestPaymentsWithXapiKey) |
| 412 | +unittest.TextTestRunner(verbosity=2).run(suite) |
| 413 | +TestPaymentsWithXapiKey.client.http_force = "pycurl" |
| 414 | +TestPaymentsWithXapiKey.client.http_init = False |
| 415 | +suite = unittest.TestLoader().loadTestsFromTestCase(TestPaymentsWithXapiKey) |
| 416 | +unittest.TextTestRunner(verbosity=2).run(suite) |
| 417 | +TestPaymentsWithXapiKey.client.http_force = "other" |
| 418 | +TestPaymentsWithXapiKey.client.http_init = False |
| 419 | +suite = unittest.TestLoader().loadTestsFromTestCase(TestPaymentsWithXapiKey) |
| 420 | +unittest.TextTestRunner(verbosity=2).run(suite) |
0 commit comments