Skip to content

Commit

Permalink
Merge pull request #347 from Mangopay/feature/get-card-validation
Browse files Browse the repository at this point in the history
feature/Added get card validation endpoint
  • Loading branch information
iulian03 authored Feb 12, 2024
2 parents d51c6b6 + 32ece35 commit 983ebc5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 13 deletions.
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
1 change: 1 addition & 0 deletions tests/test_bankaccounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ def test_deactivateBankAccount(self):
def test_BankAccount_getTransactions(self):
account = BaseTestLive.get_johns_account()

time.sleep(2)
transactions_page = account.get_transactions()

self.assertIsNotNone(transactions_page.data)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def card(self):
self.mock_tokenization_request()

response = requests.post(card_registration.card_registration_url, data={
'cardNumber': '4970100000000154',
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '0124',
'accessKeyRef': card_registration.access_key,
Expand All @@ -148,7 +148,7 @@ def natural_user_card(self):
self.mock_tokenization_request()

response = requests.post(card_registration.card_registration_url, data={
'cardNumber': '4970101122334422',
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '0124',
'accessKeyRef': card_registration.access_key,
Expand All @@ -174,7 +174,7 @@ def legal_user_card(self):
self.mock_tokenization_request()

response = requests.post(card_registration.card_registration_url, data={
'cardNumber': '4970101122334406',
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '0124',
'accessKeyRef': card_registration.access_key,
Expand Down Expand Up @@ -539,7 +539,7 @@ def get_johns_card(recreate=False):
params = {
"data_XXX": card_registration.preregistration_data,
"accessKeyRef": card_registration.access_key,
"cardNumber": '4970101122334422',
"cardNumber": '4970107111111119',
"cardExpirationDate": '1224',
"cardCvx": '123'
}
Expand All @@ -563,7 +563,7 @@ def get_johns_card_3dsecure(recreate=False):
params = {
"data_XXX": card_registration.preregistration_data,
"accessKeyRef": card_registration.access_key,
"cardNumber": '4970105191923460',
"cardNumber": '4970107111111119',
"cardExpirationDate": '1224',
"cardCvx": '123'
}
Expand Down Expand Up @@ -609,7 +609,7 @@ def create_new_card_registration_for_deposit():
params = {
"data_XXX": card_registration.preregistration_data,
"accessKeyRef": card_registration.access_key,
"cardNumber": '4970105181818183',
"cardNumber": '4970107111111119',
"cardExpirationDate": '1224',
"cardCvx": '123'
}
Expand Down
49 changes: 46 additions & 3 deletions tests/test_cards.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import time

from tests import settings

try:
Expand Down Expand Up @@ -67,7 +69,7 @@ def test_cards_registration(self):

# Send card details to the Tokenization server
response = requests.post(card_registration.card_registration_url, urlrequest.urlencode({
'cardNumber': '4970100000000154',
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '0128',
'accessKeyRef': card_registration.access_key,
Expand Down Expand Up @@ -163,7 +165,7 @@ def test_cards_for_fingerprint(self):
self.assertIsNotNone(card_registration.get_pk())

response = requests.post(card_registration.card_registration_url, urlrequest.urlencode({
'cardNumber': '4970100000000154',
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '0128',
'accessKeyRef': card_registration.access_key,
Expand Down Expand Up @@ -239,7 +241,7 @@ def test_desactive_card(self):

# Send card details to the Tokenization server
response = requests.post(card_registration.card_registration_url, urlrequest.urlencode({
'cardNumber': '4970100000000154',
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '0128',
'accessKeyRef': card_registration.access_key,
Expand Down Expand Up @@ -273,6 +275,7 @@ def test_getCardPreAuthorizations(self):
def test_getCardTransactions(self):
card = BaseTestLive.get_johns_card()

time.sleep(2)
transactions_page = card.get_transactions()

self.assertIsNotNone(transactions_page.data)
Expand Down Expand Up @@ -312,3 +315,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'])
7 changes: 4 additions & 3 deletions tests/test_preauthorizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def test_PreAuthorizations_CreateWithAvs(self):

saved_registration = card_registration.save()
data = {
'cardNumber': '4970105191923460',
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '1224',
'accessKeyRef': card_registration.access_key,
Expand Down Expand Up @@ -729,7 +729,7 @@ def test_PreAuthorizations_CreateDirect(self):

saved_registration = card_registration.save()
data = {
'cardNumber': '4970105191923460',
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '1224',
'accessKeyRef': card_registration.access_key,
Expand Down Expand Up @@ -782,6 +782,7 @@ def test_PreAuthorizations_CreateDirect(self):
payin.culture = 'fr'
BaseTestLive._johns_payin = PreAuthorizedPayIn(**payin.save())

time.sleep(2)
transactions = pre_authorization.get_transactions()

self.assertIsNotNone(saved_pre_authorization)
Expand All @@ -799,7 +800,7 @@ def test_PreAuthorizations_CheckCardInfo(self):

saved_registration = card_registration.save()
data = {
'cardNumber': '4970105191923460',
'cardNumber': '4970107111111119',
'cardCvx': '123',
'cardExpirationDate': '1224',
'accessKeyRef': card_registration.access_key,
Expand Down

0 comments on commit 983ebc5

Please sign in to comment.