Exemplo n.º 1
0
 def post(self, request, format=None):
     try:
         card_detail = UserCardDetails.objects.get(user=request.user, currency__code=request.data['currency'],\
                                                                                             is_completed = False)
         card_registration = CardRegistration.get(
             card_detail.mangopay_card_registration_id)
         card_registration.registration_data = request.data[
             'registration_data']
         card_registration.save()
         card_detail.is_completed = True
         card_detail.save()
         logger.info("Card successfully registered for {} currency by {} user.".format(request.data['currency'],\
                                                                                             request.user.phone_no))
         return Response({
             'success': True,
             'message': 'card registration successful.',
             'data': {}
         })
     except Exception as e:
         logger.error(
             "{}, error occured while card registration.".format(e))
         return Response({
             'success': False,
             'message': 'Error occured while card registration.',
             'data': {}
         })
Exemplo n.º 2
0
def create_card(mangopay_user_id):
    cr = CardRegistration()
    cr.UserId = mangopay_user_id
    cr.Currency = 'EUR'
    cr.CardType = 'CB_VISA_MASTERCARD'
    cr.save()
    data = dict(
        accessKeyRef=cr.AccessKey,
        cardNumber='3569990000000132',
        cardExpirationDate='1234',
        cardCvx='123',
        data=cr.PreregistrationData,
    )
    cr.RegistrationData = requests.post(cr.CardRegistrationURL, data).text
    cr.save()
    return cr
Exemplo n.º 3
0
 def create(self):
     # Currently only registers CB_VISA_MC....
     registration = CardRegistration(UserId=self.mid,
                                     Currency=self.currency,
                                     CardType=self.card_type)
     print(registration)
     registration.save()
     # Create the card that will hold all the data once registration is done
     card = MangoCard(mid=self.mid, is_valid=True)
     card.save()
     # Now the preregistration data should be in the 'registration' variable. Passing this back to the view.
     preregdata = {
         'accessKey': registration['AccessKey'],
         'preregistrationdata': registration['preregistrationData'],
         'cardRegistrationURL': registration['cardRegistrationURL']
     }
     return preregdata
Exemplo n.º 4
0
Arquivo: models.py Projeto: ojr9/g39
 def create(self, user):
     saver = Saver.objects.get(user=user)
     registration = CardRegistration(UserId=saver.mid, Currency=self.currency)
     registration.save()
     print(registration.Id)
     self.crid = registration.Id
     # Create the card that will hold all the data once registration is done
     if not self.card:
         card = MangoCard(saver=saver, currency=self.currency, is_valid=True, card_type=self.card_type)
         card.save()
         self.card = card
         if not self.card:
             return HttpResponse('card in thingy not beign saved')
     # Now the preregistration data should be in the 'registration' variable. Passing this back to the view.
     preregdata = {'AccessKey': registration.AccessKey, 'PreregistrationData': registration.PreregistrationData,
                   'CardRegistrationURL': registration.CardRegistrationURL, 'CardRegId': self.crid}
     return preregdata
Exemplo n.º 5
0
    def post(self, request, format=None):
        try:
            try:
                card_detail = UserCardDetails.objects.get(
                    user=request.user, currency__code=request.data['currency'])
                if card_detail.is_completed:
                    return Response({
                        'success': False,
                        'message':
                        'Card already registrated for given currency.',
                        'data': {}
                    })
                else:
                    card_registration = CardRegistration.get(
                        card_detail.mangopay_card_registration_id)

            except UserCardDetails.DoesNotExist:
                mangopay_user = NaturalUser.get(request.user.mangopay_user_id)
                currency = Currency.objects.get(code=request.data['currency'])
                card_registration = CardRegistration(user=mangopay_user,
                                                     currency=currency.code)
                card_registration.save()
                UserCardDetails.objects.create(user=request.user, currency=currency, \
                                                 mangopay_card_registration_id=card_registration.id)
            logger.info("Card successfully pre-registered for {} currency by {} user.".format(request.data['currency'],\
                                                                                                request.user.phone_no))
            return Response({
                'success': True,
                'message': 'Pre card registration successful.',
                'data': {
                    "AccessKey": card_registration.AccessKey,
                    "PreregistrationData":
                    card_registration.PreregistrationData,
                    "CardRegistrationURL":
                    card_registration.CardRegistrationURL
                }
            })
        except Exception as e:
            logger.exception(
                "{}, error occured while pre card registration.".format(e))
            return Response({
                'success': False,
                'message': 'Error occured while pre card registration.',
                'data': {}
            })
Exemplo n.º 6
0
def create_card(mangopay_user_id):
    cr = CardRegistration()
    cr.UserId = mangopay_user_id
    cr.Currency = 'EUR'
    cr.CardType = 'CB_VISA_MASTERCARD'
    cr.save()
    data = dict(
        accessKeyRef=cr.AccessKey,
        cardNumber='3569990000000132',
        cardExpirationDate='1234',
        cardCvx='123',
        data=cr.PreregistrationData,
    )
    cr.RegistrationData = requests.post(cr.CardRegistrationURL, data).text
    cr.save()
    return cr
Exemplo n.º 7
0
Arquivo: models.py Projeto: ojr9/g39
 def _update(self, data):
     reg = CardRegistration.get(self.crid)
     reg.update(data)
     reg.save()
     crd = MangoCard.objects.get(self.card)
     crd.cid = reg.Id
     crd.expiration_date = reg.ExpirationDate
     crd.alias = reg.Alias
     crd.creation_date = reg.CreationDate
     crd.fingerprint = reg.Fingerprint
     crd.save()
Exemplo n.º 8
0
 def Get(self, card_registration_id):
         card_registration = CardRegistration(card_registration_id)
         card_registration.RegistrationData = "data=RegistrationData"
         card_registration.PreregistrationData = "PreregistrationData"
         card_registration.AccessKey = "AccessKey"
         card_registration.CardRegistrationURL = "CardRegistrationURL"
         return card_registration
Exemplo n.º 9
0
    def post(self, request, format=None):
        try:
            try:
                currency = Currency.objects.get(code=request.data['currency'])
                card_detail = UserCardDetails.objects.get(user=request.user,
                                                          currency=currency,
                                                          is_completed=True)
            except UserCardDetails.DoesNotExist:
                return Response({
                    'success': True,
                    'message':
                    'Please complete card registration first for selected currency.',
                    'data': {}
                })
            card_registration = CardRegistration.get(
                card_detail.mangopay_card_registration_id)
            user_wallet = UserWallet.objects.get(user=request.user,
                                                 currency=currency,
                                                 status='A')
            wallet = Wallet.get(user_wallet.mangopay_wallet_id)
            mangopay_user = NaturalUser.get(request.user.mangopay_user_id)
            direct_payin = DirectPayIn(
                author=mangopay_user,
                debited_funds=Money(amount=request.data['amount'],
                                    currency=currency.code),
                fees=Money(amount=currency.fee, currency=currency.code),
                credited_wallet_id=wallet.get_pk(),
                card_id=card_registration.CardId,
                secure_mode="DEFAULT",
                secure_mode_return_url="/")  #take url from client

            direct_payin.save()
            logger.info("{} {} credited by {} user.".format(
                request.data['amount'], currency.code, request.user.phone_no))
            return Response({
                'success': True,
                'message': 'Money successfully credited.',
                'data': {
                    'transaction_id': direct_payin.get_pk()
                }
            })
        except Exception as e:
            logger.error(
                "{}, error occured while adding money by card.".format(e))
            return Response({
                'success': False,
                'message': 'Error occured while adding money by card.',
                'data': {}
            })
Exemplo n.º 10
0
 def get_card_registration(self, currency='EUR'):
     user = self.mangopay_user.get_user()
     return CardRegistration(id=self.mangopay_id,
                             user=user,
                             currency=currency)
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
0
    w.Owners = [mangopay_user_id]
    w.Description = 'test wallet'
    w.Currency = 'EUR'
    w.save()
    return w


with use_cassette('MangopayHarness'):
    cls = MangopayHarness

    cls.david_id = make_mangopay_account('David')
    cls.david_wallet_id = make_wallet(cls.david_id).Id

    cls.janet_id = make_mangopay_account('Janet')
    cls.janet_wallet_id = make_wallet(cls.janet_id).Id
    cr = CardRegistration()
    cr.UserId = cls.janet_id
    cr.Currency = 'EUR'
    cr.CardType = 'CB_VISA_MASTERCARD'
    cr.save()
    data = dict(
        accessKeyRef=cr.AccessKey,
        cardNumber='3569990000000132',
        cardExpirationDate='1234',
        cardCvx='123',
        data=cr.PreregistrationData,
    )
    cr.RegistrationData = requests.post(cr.CardRegistrationURL, data).text
    cr.save()
    cls.card_id = cr.CardId
    del cr, data