Skip to content

Commit

Permalink
Added get card validation endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Silviana Ghita committed Jan 25, 2024
1 parent d51c6b6 commit ceaf328
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mangopay/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'
}


Expand Down
40 changes: 40 additions & 0 deletions tests/test_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

0 comments on commit ceaf328

Please sign in to comment.