Пример #1
0
 def invalidate(self, obj=None):
     if self.network.startswith('stripe-'):
         if self.address.startswith('pm_'):
             stripe.PaymentMethod.detach(self.address)
         else:
             try:
                 source = stripe.Source.retrieve(self.address).detach()
             except stripe.error.InvalidRequestError as e:
                 if "does not appear to be currently attached" in str(e):
                     pass
                 else:
                     raise
             else:
                 assert source.status == 'consumed'
                 self.update_status(source.status)
                 return
     elif self.network == 'mango-cc':
         card = obj or Card.get(self.address)
         if card.Active:
             card.Active = False
             card.save()
             assert card.Active is False, card.Active
     if self.mandate:
         mandate = Mandate.get(self.mandate)
         if mandate.Status in ('SUBMITTED', 'ACTIVE'):
             mandate.cancel()
     self.update_status('canceled')
Пример #2
0
 def invalidate(self, obj=None):
     if self.network == 'mango-cc':
         card = obj or Card.get(self.address)
         if card.Active:
             card.Active = False
             card.save()
             assert card.Active is False, card.Active
     self.update_error('invalidated')
 def invalidate(self, obj=None):
     if self.network == 'mango-cc':
         card = obj or Card.get(self.address)
         if card.Active:
             card.Active = False
             card.save()
             assert card.Active is False, card.Active
     if self.mandate:
         mandate = Mandate.get(self.mandate)
         if mandate.Status in ('SUBMITTED', 'ACTIVE'):
             mandate.cancel()
     self.update_error('invalidated')
Пример #4
0
 def invalidate(self, obj=None):
     if self.network == 'mango-cc':
         card = obj or Card.get(self.address)
         if card.Active:
             card.Active = False
             card.save()
             assert card.Active is False, card.Active
     if self.mandate:
         mandate = Mandate.get(self.mandate)
         if mandate.Status in ('SUBMITTED', 'ACTIVE'):
             mandate.cancel()
     self.update_error('invalidated')
Пример #5
0
Файл: models.py Проект: ojr9/g39
 def update_from_api(self):
     # Am I getting here the first cid? then no if
     if self.cid:
         card = Card.get(self.cid)
         self.expiration_date = card.ExpirationDate
         self.alias = card.Alias
         self.provider = card.CardProvider
         self.currency = card.Currency
         if card.Active == '':
             self.is_active = True
         if card.Validity == 'VALID':
             self.is_valid = True
         self.creation_date = card.CreationDate
         self.fingerprint = card.fingerprint
         self.card_type = card.CardType
         self.save()
Пример #6
0
 def update(self):
     # Am I getting here the first cid? then no if
     if self.cid:
         card = Card.get(self.cid)
         self.expiration_date = card['ExpirationDate']
         self.alias = card['Alias']
         self.provider = card['CardProvider']
         self.currency = card['Currency']
         if card['Active'] == '':
             self.is_active = True
         if card['Validity'] == 'VALID':
             self.is_valid = True
         self.creation_date = card['CreationDate']
         self.fingerprint = card['fingerprint']
         self.card_type = card['CardType']
         self.save()
Пример #7
0
 def invalidate(self, obj=None):
     if self.network.startswith('stripe-'):
         source = stripe.Source.retrieve(self.address).detach()
         assert source.status == 'consumed'
         self.update_status(source.status)
         return
     if self.network == 'mango-cc':
         card = obj or Card.get(self.address)
         if card.Active:
             card.Active = False
             card.save()
             assert card.Active is False, card.Active
     if self.mandate:
         mandate = Mandate.get(self.mandate)
         if mandate.Status in ('SUBMITTED', 'ACTIVE'):
             mandate.cancel()
     self.update_status('canceled')
Пример #8
0
 def invalidate(self, obj=None):
     if self.network.startswith('stripe-'):
         if self.address.startswith('pm_'):
             stripe.PaymentMethod.detach(self.address)
         else:
             source = stripe.Source.retrieve(self.address).detach()
             assert source.status == 'consumed'
             self.update_status(source.status)
             return
     elif self.network == 'mango-cc':
         card = obj or Card.get(self.address)
         if card.Active:
             card.Active = False
             card.save()
             assert card.Active is False, card.Active
     if self.mandate:
         mandate = Mandate.get(self.mandate)
         if mandate.Status in ('SUBMITTED', 'ACTIVE'):
             mandate.cancel()
     self.update_status('canceled')
Пример #9
0
    def test_desactive_card(self):
        self.mock_natural_user()
        self.mock_card()
        self.mock_tokenization_request()
        self.register_mock({
            'method':
            responses.GET,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/users/1169419/cards',
            'body': [{
                "ExpirationDate": "1214",
                "Alias": "497010XXXXXX4406",
                "CardType": "CB",
                "Country": "",
                "Product": "",
                "BankCode": "",
                "Active": True,
                "Currency": "XXX",
                "Validity": "VALID",
                "UserId": "1167495",
                "Id": "1167507",
                "Tag": None,
                "CreationDate": 1382608428
            }],
            'status':
            200
        })
        self.register_mock({
            'method':
            responses.PUT,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/cards/1167507',
            'body': {
                "ExpirationDate": "1214",
                "Alias": "497010XXXXXX4406",
                "CardType": "CB",
                "Country": "",
                "Product": "",
                "BankCode": "",
                "Active": False,
                "Currency": "XXX",
                "Validity": "VALID",
                "UserId": "1167495",
                "Id": "1167507",
                "Tag": None,
                "CreationDate": 1382608428
            },
            'status':
            200
        })

        # Create a CardRegistration object
        card_params = {"user": self.natural_user, "currency": 'EUR'}
        card_registration = CardRegistration(**card_params)
        card_registration.save()

        # Send card details to the Tokenization server
        response = requests.post(
            card_registration.card_registration_url,
            urlrequest.urlencode({
                'cardNumber': '4970100000000154',
                'cardCvx': '123',
                'cardExpirationDate': '0120',
                'accessKeyRef': card_registration.access_key,
                'data': card_registration.preregistration_data
            }))

        # Edit the CardRegistration with received RegistrationData
        previous_pk = card_registration.get_pk()

        card_registration.registration_data = response.text
        card_registration.save()

        card = Card.get(card_registration.card_id)

        card.active = False
        card.save()

        self.assertIs(card.active, False)
Пример #10
0
    def test_cards_registration(self):
        """
        Card registration process:
        - Create a CardRegistration object
        - Receive a CardRegistration object
        - Send card details to the Tokenization server
        - Receive RegistrationData
        - Edit the CardRegistration with received RegistrationData
        """

        self.mock_natural_user()
        self.mock_card()
        self.mock_tokenization_request()
        self.register_mock({
            'method':
            responses.GET,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/users/1169419/cards',
            'body': [{
                "ExpirationDate": "1214",
                "Alias": "497010XXXXXX4406",
                "CardType": "CB",
                "Country": "",
                "Product": "",
                "BankCode": "",
                "Active": True,
                "Currency": "XXX",
                "Validity": "VALID",
                "UserId": "1167495",
                "Id": "1167507",
                "Tag": None,
                "CreationDate": 1382608428
            }],
            'status':
            200
        })

        # Create a CardRegistration object
        card_params = {"user": self.natural_user, "currency": 'EUR'}
        card_registration = CardRegistration(**card_params)
        card_registration.save()

        for key, value in card_params.items():
            self.assertEqual(getattr(card_registration, key), value)

        self.assertIsNotNone(card_registration.get_pk())

        # Send card details to the Tokenization server
        response = requests.post(
            card_registration.card_registration_url,
            urlrequest.urlencode({
                'cardNumber': '4970100000000154',
                'cardCvx': '123',
                'cardExpirationDate': '0120',
                'accessKeyRef': card_registration.access_key,
                'data': card_registration.preregistration_data
            }))

        # Edit the CardRegistration with received RegistrationData
        previous_pk = card_registration.get_pk()

        card_registration.registration_data = response.text
        card_registration.save()

        self.assertEqual(previous_pk, card_registration.get_pk())
        self.assertIsNotNone(card_registration.registration_data)
        self.assertEqual(card_registration.registration_data, response.text)
        self.assertEqual(card_registration.status, 'VALIDATED')
        self.assertEqual(card_registration.result_message, 'Success')
        self.assertEqual(card_registration.result_code, '000000')
        self.assertIsNotNone(
            card_registration.card_id)  # We now have a card id!

        # Fetch the new card thanks to card_id
        self.assertIsNotNone(card_registration.card_id)

        card = Card.get(card_registration.card_id)
        self.assertIsNotNone(card.get_pk())
        self.assertEqual(card.get_pk(), card_registration.card_id)

        # Retrieve user's cards
        self.assertEqual(len(self.natural_user.cards.all()), 1)
        self.assertEqual(self.natural_user.cards.all()[0], card)
        self.assertEqual(self.natural_user.cards.get(card.id), card)
Пример #11
0
    def test_cards_for_fingerprint(self):
        self.mock_natural_user()
        self.mock_card()
        self.mock_tokenization_request()
        self.register_mock([{
            'method':
            responses.GET,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/users/1169419/cards',
            'body': [{
                "ExpirationDate": "1214",
                "Alias": "497010XXXXXX4406",
                "CardType": "CB",
                "Country": "",
                "Product": "",
                "BankCode": "",
                "Active": True,
                "Currency": "XXX",
                "Validity": "VALID",
                "UserId": "1167495",
                "Id": "1167507",
                "Tag": None,
                "CreationDate": 1382608428
            }],
            'status':
            200
        }, {
            'method':
            responses.GET,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/cards/fingerprints/c188a617d3ed42169a7d91f7485c65f3',
            'body': [{
                "ExpirationDate": "1214",
                "Alias": "497010XXXXXX4406",
                "CardType": "CB",
                "Country": "",
                "Product": "",
                "BankCode": "",
                "Active": True,
                "Currency": "XXX",
                "Validity": "VALID",
                "UserId": "1167495",
                "Id": "1167507",
                "Tag": None,
                "CreationDate": 1382608428,
                "Fingerprint": "c188a617d3ed42169a7d91f7485c65f3"
            }],
            'status':
            200
        }])

        card_params = {"user": self.natural_user, "currency": 'EUR'}
        card_registration = CardRegistration(**card_params)
        card_registration.save()

        for key, value in card_params.items():
            self.assertEqual(getattr(card_registration, key), value)

        self.assertIsNotNone(card_registration.get_pk())

        response = requests.post(
            card_registration.card_registration_url,
            urlrequest.urlencode({
                'cardNumber': '4970100000000154',
                'cardCvx': '123',
                'cardExpirationDate': '0120',
                'accessKeyRef': card_registration.access_key,
                'data': card_registration.preregistration_data
            }))

        card_registration.registration_data = response.text
        card_registration.save()

        card = Card.get(card_registration.card_id)
        cards = Card.get_by_fingerprint(card.fingerprint)

        self.assertTrue(len(cards) > 0)

        for c in cards:
            self.assertEqual(c.fingerprint, card.fingerprint)
Пример #12
0
    def test_desactive_card(self):
        self.mock_natural_user()
        self.mock_card()
        self.mock_tokenization_request()
        self.register_mock({
            'method': responses.GET,
            'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/cards',
            'body': [
                {
                    "ExpirationDate": "1214",
                    "Alias": "497010XXXXXX4406",
                    "CardType": "CB",
                    "Country": "",
                    "Product": "",
                    "BankCode": "",
                    "Active": True,
                    "Currency": "XXX",
                    "Validity": "VALID",
                    "UserId": "1167495",
                    "Id": "1167507",
                    "Tag": None,
                    "CreationDate": 1382608428
                }
            ],
            'status': 200
        })
        self.register_mock({
            'method': responses.PUT,
            'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/cards/1167507',
            'body': {
                "ExpirationDate": "1214",
                "Alias": "497010XXXXXX4406",
                "CardType": "CB",
                "Country": "",
                "Product": "",
                "BankCode": "",
                "Active": False,
                "Currency": "XXX",
                "Validity": "VALID",
                "UserId": "1167495",
                "Id": "1167507",
                "Tag": None,
                "CreationDate": 1382608428
            },
            'status': 200
        })

        # Create a CardRegistration object
        card_params = {
            "user": self.natural_user,
            "currency": 'EUR'
        }
        card_registration = CardRegistration(**card_params)
        card_registration.save()

        # Send card details to the Tokenization server
        response = requests.post(card_registration.card_registration_url, urlrequest.urlencode({
            'cardNumber': '4970100000000154',
            'cardCvx': '123',
            'cardExpirationDate': '0120',
            'accessKeyRef': card_registration.access_key,
            'data': card_registration.preregistration_data
        }))

        # Edit the CardRegistration with received RegistrationData
        previous_pk = card_registration.get_pk()

        card_registration.registration_data = response.text
        card_registration.save()

        card = Card.get(card_registration.card_id)

        card.active = False
        card.save()

        self.assertIs(card.active, False)
Пример #13
0
    def test_cards_registration(self):
        """
        Card registration process:
        - Create a CardRegistration object
        - Receive a CardRegistration object
        - Send card details to the Tokenization server
        - Receive RegistrationData
        - Edit the CardRegistration with received RegistrationData
        """

        self.mock_natural_user()
        self.mock_card()
        self.mock_tokenization_request()
        self.register_mock({
            'method': responses.GET,
            'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/cards',
            'body': [
                {
                    "ExpirationDate": "1214",
                    "Alias": "497010XXXXXX4406",
                    "CardType": "CB",
                    "Country": "",
                    "Product": "",
                    "BankCode": "",
                    "Active": True,
                    "Currency": "XXX",
                    "Validity": "VALID",
                    "UserId": "1167495",
                    "Id": "1167507",
                    "Tag": None,
                    "CreationDate": 1382608428
                }
            ],
            'status': 200
        })

        # Create a CardRegistration object
        card_params = {
            "user": self.natural_user,
            "currency": 'EUR'
        }
        card_registration = CardRegistration(**card_params)
        card_registration.save()

        for key, value in card_params.items():
            self.assertEqual(getattr(card_registration, key), value)

        self.assertIsNotNone(card_registration.get_pk())

        # Send card details to the Tokenization server
        response = requests.post(card_registration.card_registration_url, urlrequest.urlencode({
            'cardNumber': '4970100000000154',
            'cardCvx': '123',
            'cardExpirationDate': '0120',
            'accessKeyRef': card_registration.access_key,
            'data': card_registration.preregistration_data
        }))

        # Edit the CardRegistration with received RegistrationData
        previous_pk = card_registration.get_pk()

        card_registration.registration_data = response.text
        card_registration.save()

        self.assertEqual(previous_pk, card_registration.get_pk())
        self.assertIsNotNone(card_registration.registration_data)
        self.assertEqual(card_registration.registration_data, response.text)
        self.assertEqual(card_registration.status, 'VALIDATED')
        self.assertEqual(card_registration.result_message, 'Success')
        self.assertEqual(card_registration.result_code, '000000')
        self.assertIsNotNone(card_registration.card_id)  # We now have a card id!

        # Fetch the new card thanks to card_id
        self.assertIsNotNone(card_registration.card_id)

        card = Card.get(card_registration.card_id)
        self.assertIsNotNone(card.get_pk())
        self.assertEqual(card.get_pk(), card_registration.card_id)

        # Retrieve user's cards
        self.assertEqual(len(self.natural_user.cards.all()), 1)
        self.assertEqual(self.natural_user.cards.all()[0], card)
        self.assertEqual(self.natural_user.cards.get(card.id), card)
Пример #14
0
    def test_cards_for_fingerprint(self):
        self.mock_natural_user()
        self.mock_card()
        self.mock_tokenization_request()
        self.register_mock([{
            'method': responses.GET,
            'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/cards',
            'body': [
                {
                    "ExpirationDate": "1214",
                    "Alias": "497010XXXXXX4406",
                    "CardType": "CB",
                    "Country": "",
                    "Product": "",
                    "BankCode": "",
                    "Active": True,
                    "Currency": "XXX",
                    "Validity": "VALID",
                    "UserId": "1167495",
                    "Id": "1167507",
                    "Tag": None,
                    "CreationDate": 1382608428
                }
            ],
            'status': 200
        }, {
            'method': responses.GET,
            'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/cards/fingerprints/c188a617d3ed42169a7d91f7485c65f3',
            'body': [
                {
                    "ExpirationDate": "1214",
                    "Alias": "497010XXXXXX4406",
                    "CardType": "CB",
                    "Country": "",
                    "Product": "",
                    "BankCode": "",
                    "Active": True,
                    "Currency": "XXX",
                    "Validity": "VALID",
                    "UserId": "1167495",
                    "Id": "1167507",
                    "Tag": None,
                    "CreationDate": 1382608428,
                    "Fingerprint": "c188a617d3ed42169a7d91f7485c65f3"
                }
            ],
            'status': 200
        }])

        card_params = {
            "user": self.natural_user,
            "currency": 'EUR'
        }
        card_registration = CardRegistration(**card_params)
        card_registration.save()

        for key, value in card_params.items():
            self.assertEqual(getattr(card_registration, key), value)

        self.assertIsNotNone(card_registration.get_pk())

        response = requests.post(card_registration.card_registration_url, urlrequest.urlencode({
            'cardNumber': '4970100000000154',
            'cardCvx': '123',
            'cardExpirationDate': '0120',
            'accessKeyRef': card_registration.access_key,
            'data': card_registration.preregistration_data
        }))

        card_registration.registration_data = response.text
        card_registration.save()

        card = Card.get(card_registration.card_id)
        cards = Card.get_by_fingerprint(card.fingerprint)

        self.assertTrue(len(cards) > 0)

        for c in cards:
            self.assertEqual(c.fingerprint, card.fingerprint)