Ejemplo 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': {}
         })
Ejemplo n.º 2
0
Archivo: models.py Proyecto: 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()
Ejemplo n.º 3
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': {}
            })
Ejemplo n.º 4
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': {}
            })