diff --git a/mangopay/resources.py b/mangopay/resources.py index 5630ac2..2362d6d 100644 --- a/mangopay/resources.py +++ b/mangopay/resources.py @@ -427,6 +427,9 @@ class CardValidation(BaseModel): default=None) result_code = CharField(api_name='ResultCode') result_message = CharField(api_name='ResultMessage') + preferred_card_network = CharField(api_name='PreferredCardNetwork') + authorization_date = DateTimeField(api_name='AuthorizationDate') + card_info = CardInfoField(api_name='CardInfo') def validate(self, card_id, **kwargs): insert = InsertQuery(self, **kwargs) @@ -435,11 +438,19 @@ def validate(self, card_id, **kwargs): insert.identifier = 'CARD_VALIDATE' return insert.execute() + def get_card_validation(self, card_id, *args, **kwargs): + kwargs['card_id'] = card_id + kwargs['id'] = self.id + select = SelectQuery(CardValidation, *args, **kwargs) + select.identifier = 'GET_CARD_VALIDATION' + return select.all(*args, **kwargs) + class Meta: verbose_name = 'card_validation' verbose_name_plural = 'card_validations' url = { - 'CARD_VALIDATE': '/cards/%(id)s/validation' + 'CARD_VALIDATE': '/cards/%(id)s/validation', + 'GET_CARD_VALIDATION': '/cards/%(card_id)s/validation/%(id)s' } diff --git a/tests/test_cards.py b/tests/test_cards.py index b58c42d..39b3708 100644 --- a/tests/test_cards.py +++ b/tests/test_cards.py @@ -312,3 +312,43 @@ def test_cardValidation(self): self.assertIsNotNone(validation_response) self.assertIsNotNone(validation_response['id']) + + def test_getCardValidation(self): + user = BaseTestLive.get_john() + + card_registration = CardRegistration() + card_registration.user = user + card_registration.currency = 'EUR' + + saved_registration = card_registration.save() + data = { + 'cardNumber': '4970107111111119', + 'cardCvx': '123', + 'cardExpirationDate': '1224', + 'accessKeyRef': card_registration.access_key, + 'data': card_registration.preregistration_data + } + headers = { + 'content-type': 'application/x-www-form-urlencoded' + } + registration_data_response = requests.post(card_registration.card_registration_url, data=data, headers=headers) + saved_registration['registration_data'] = registration_data_response.text + updated_registration = CardRegistration(**saved_registration).save() + card_id = updated_registration['card_id'] + + card_validation = CardValidation() + card_validation.author = user + card_validation.tag = "test" + card_validation.secure_mode_return_url = "http://www.example.com/" + card_validation.ip_address = "2001:0620:0000:0000:0211:24FF:FE80:C12C" + card_validation.browser_info = BaseTest.get_browser_info() + + validation_response = card_validation.validate(card_id) + + get_card_validation = CardValidation() + get_card_validation.id = validation_response['id'] + get_card_validation_response = get_card_validation.get_card_validation(card_id) + + self.assertIsNotNone(get_card_validation_response.data[0]) + self.assertIsNotNone(get_card_validation_response.data[0].id) + self.assertEqual(get_card_validation_response.data[0].id, validation_response['id'])