예제 #1
0
파일: user.py 프로젝트: zzsnicole/Bankey
    def create(self, validated_data):
        address_data = validated_data.pop('address')
        user = User.objects.create(**validated_data)
        country = Country.objects.get(code=address_data['country'])
        user.address = Address.objects.create(country=country)
        user.set_password(validated_data['password'])
        user.save()
        Token.objects.create(user=user)
        # first_name, last_name = validated_data['name'].split(' ')
        birth_date = int(
            time.mktime(
                time.strptime(str(validated_data['birth_date']), '%Y-%m-%d')))
        mangopay_user = NaturalUser(first_name=validated_data['name'],
                                    last_name=validated_data['surname'],
                                    birthday=birth_date,
                                    nationality=country.code,
                                    country_of_residence=country.code,
                                    person_type='NATURAL',
                                    email=validated_data['email'])
        mangopay_user.save()
        user.mangopay_user_id = mangopay_user.id
        user.save()
        wallet = Wallet(owners=[mangopay_user],
                        description='Wallet for USD',
                        currency='USD')

        wallet.save()
        currency = Currency.objects.get(code='USD')
        UserWallet.objects.create(user=user,
                                  currency=currency,
                                  mangopay_wallet_id=wallet.id)
        return user
예제 #2
0
파일: models.py 프로젝트: ojr9/confessapp
 def create(self):
     wallet_call = Wallet(Owners=[self.mid],
                          Description=f'Wallet for {self.mid}',
                          currency=self.currency)
     wallet_call.save()
     self.wid = int(wallet_call.get_pk())
     self.save()
예제 #3
0
    def post(self, request, format=None):
        try:
            currency = Currency.objects.get(code=request.data['currency'])
            receiver_user = User.objects.get(phone_no=request.data['mobile_number'])
            sender_wallet_obj = UserWallet.objects.get(user=request.user, currency=currency, status='A')
            sender_wallet = Wallet.get(sender_wallet_obj.mangopay_wallet_id)
            receiver_wallet_obj = UserWallet.objects.get(user=receiver_user, currency=currency, status='A')
            receiver_wallet = Wallet.get(receiver_wallet_obj.mangopay_wallet_id)
            author_user = NaturalUser.get(request.user.mangopay_user_id)
            transfer = Transfer(author=author_user, #sender
                                debited_funds=Money(amount=request.data['amount'], currency=currency.code),
                                fees=Money(amount=currency.fee, currency=currency.code),
                                debited_wallet=sender_wallet,
                                credited_wallet=receiver_wallet)

            transfer.save()
            logger.info("Money transfered successfully from {} user to {} user."\
                        .format(request.user.phone_no, receiver_user.phone_no))
            return Response({
                'success': True,
                'message': 'Money transfered successfully.',
                'data':{
                    'transaction_id':transfer.get_pk()
                }
            })
        except Exception as e:
            logger.exception("{}, error occured while transfering money.".format(e))
            return Response({
                'success': False,
                'message': 'Error occured while transfering money.',
                'data':{}
            })
예제 #4
0
파일: models.py 프로젝트: ojr9/g39
 def create(self):
     # get the mid here? rather here, but eaiser in view
     saver = Saver.objects.get(user=self.cuenta.user)
     wallet_call = Wallet(Owners=[saver.mid], Description=self.cuenta.description, currency=self.cuenta.currency)
     wallet_call.save()
     self.cuenta.wid = wallet_call.Id # make sure an int is returned here.
     print(self.cuenta.wid)
     print(wallet_call.Id)
     self.save()
예제 #5
0
 def post(self, request, format=None):
     try:
         currency = Currency.objects.get(code=request.data['currency'])
         user_wallet = UserWallet.objects.get(user=request.user,
                                              currency=currency,
                                              status='A')
         wallet = Wallet.get(user_wallet.mangopay_wallet_id)
         logger.info(
             "Successfully returned balance of {} user for {} currency.".
             format(request.user.phone_no, currency.code))
         return Response({
             'success': True,
             'message': 'Successfully returned balance.',
             'data': {
                 "balance": str(wallet.balance.amount)
             }
         })
     except Exception as e:
         logger.error(
             "{}, error occured while returning balance.".format(e))
         return Response({
             'success': False,
             'message': 'Error occured while returning balance.',
             'data': {}
         })
예제 #6
0
def make_wallet(mangopay_user_id):
    w = Wallet()
    w.Owners = [mangopay_user_id]
    w.Description = 'test wallet'
    w.Currency = 'EUR'
    w.save()
    return w
예제 #7
0
 def post(self, request, format=None):
     try:
         cash_request = CashRequest.objects.get(user_confirmation_code=request.data['confirmation_code'])
         teller = Teller.objects.get(user=request.user)
         if cash_request.teller == teller:
             teller_wallet_obj = UserWallet.objects.get(user=request.user, currency=cash_request.currency, status='A')
             teller_wallet = Wallet.get(teller_wallet_obj.mangopay_wallet_id)
             user_wallet_obj = UserWallet.objects.get(user=cash_request.user, currency=cash_request.currency, status='A')
             user_wallet = Wallet.get(user_wallet_obj.mangopay_wallet_id)
             if cash_request.request_type == 'A':
                 transaction_amount = cash_request.amount - teller.fee
                 author_user = NaturalUser.get(request.user.mangopay_user_id)
                 transfer = Transfer(author=author_user, #sender
                                     debited_funds=Money(amount=transaction_amount, currency=cash_request.currency.code),
                                     fees=Money(amount=cash_request.currency.fee, currency=cash_request.currency.code),
                                     debited_wallet=teller_wallet,
                                     credited_wallet=user_wallet)
             else:
                 transaction_amount = cash_request.amount + teller.fee + cash_request.currency.fee
                 author_user = NaturalUser.get(cash_request.user.mangopay_user_id)
                 transfer = Transfer(author=author_user, #sender
                                     debited_funds=Money(amount=transaction_amount, currency=cash_request.currency.code),
                                     fees=Money(amount=cash_request.currency.fee, currency=cash_request.currency.code),
                                     debited_wallet=user_wallet,
                                     credited_wallet=teller_wallet)
             transfer.save()
         cash_request.transaction_reference_number = transfer.get_pk()
         cash_request.save()
         logger.info("Cash_transaction completed successfully  between {} user and {} teller for {} cashrequest."\
                     .format(request.user.phone_no, teller.user.phone_no, cash_request.id))
         return Response({
             'success': True,
             'message': 'Cash transaction successfully completed.',
             'data':{
                 'transaction_id':transfer.get_pk()
             }
         })
     except Exception as e:
         logger.exception("{}, error occured while cash transaction.".format(e))
         return Response({
             'success': False,
             'message': 'Error occured while cash transaction.',
             'data':{}
         })
예제 #8
0
def check_wallet_balance(w, state={}):
    remote_wallet = Wallet.get(w.remote_id)
    remote_balance = remote_wallet.balance / 100
    try:
        assert remote_balance == w.balance, (
            "balances don't match for user #%s (liberapay id %s), wallet #%s contains %s, we expected %s" %
            (w.remote_owner_id, w.owner, w.remote_id, remote_balance, w.balance)
        )
    except AssertionError as e:
        from liberapay.website import website
        website.tell_sentry(e, state, allow_reraise=False)
예제 #9
0
def check_wallet_balance(w, state={}):
    remote_wallet = Wallet.get(w.remote_id)
    remote_balance = remote_wallet.balance / 100
    try:
        assert remote_balance == w.balance, (
            "balances don't match for user #%s (liberapay id %s), wallet #%s contains %s, we expected %s" %
            (w.remote_owner_id, w.owner, w.remote_id, remote_balance, w.balance)
        )
    except AssertionError as e:
        from liberapay.website import website
        website.tell_sentry(e, state, allow_reraise=False)
예제 #10
0
def make_wallet(mangopay_user_id):
    w = Wallet()
    w.Owners = [mangopay_user_id]
    w.Description = 'test wallet'
    w.Currency = 'EUR'
    w.save()
    return w
예제 #11
0
def create_wallet(db, participant, currency):
    w = Wallet()
    w.Owners = [participant.mangopay_user_id]
    w.Description = str(participant.id)
    w.Currency = currency
    w.save()
    return db.one("""
        INSERT INTO wallets
                    (remote_id, balance, owner, remote_owner_id)
             VALUES (%s, %s, %s, %s)
          RETURNING *
    """, (w.Id, w.Balance, participant.id, participant.mangopay_user_id))
예제 #12
0
def create_wallet(db, participant):
    w = Wallet()
    w.Owners = [participant.mangopay_user_id]
    w.Description = str(participant.id)
    w.Currency = 'EUR'
    w.save()
    db.run("""
        UPDATE participants
           SET mangopay_wallet_id = %s
         WHERE id = %s
    """, (w.Id, participant.id))
    participant.set_attributes(mangopay_wallet_id=w.Id)
    return w.Id
예제 #13
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': {}
            })
예제 #14
0
 def post(self, request, format=None):
     try:
         try:
             currency = Currency.objects.get(code=request.data['currency'])
             UserWallet.objects.get(user=request.user,
                                    currency=currency,
                                    status='A')
             return Response({
                 'success': False,
                 'message': 'Wallet Exist.',
                 'data': {}
             })
         except UserWallet.DoesNotExist:
             mangopay_user = NaturalUser.get(request.user.mangopay_user_id)
             wallet = Wallet(owners=[mangopay_user],
                             description="Bankey wallet",
                             currency=currency.code)
             wallet.save()
             UserWallet.objects.create(user=request.user,
                                       currency=currency,
                                       mangopay_wallet_id=wallet.id)
             logger.info(
                 "{} wallet created successfully for {} currency.".format(
                     request.user.phone_no, currency.code))
             return Response({
                 'success': True,
                 'message': 'Successfully wallet created',
                 'data': {}
             })
     except Exception as e:
         logger.error("{}, error occured while creating wallet.".format(e))
         return Response({
             'success': False,
             'message': 'Error occured while creating wallet.',
             'data': {}
         })
예제 #15
0
def create_wallet(db, participant, currency):
    w = Wallet()
    w.Owners = [participant.mangopay_user_id]
    w.Description = str(participant.id)
    w.Currency = currency
    w.save()
    return db.one("""
        INSERT INTO wallets
                    (remote_id, balance, owner, remote_owner_id)
             VALUES (%s, %s, %s, %s)
          RETURNING *
    """, (w.Id, w.Balance, participant.id, participant.mangopay_user_id))
예제 #16
0
 def get_wallet(self):
     user = self.mangopay_user.get_user()
     return Wallet(id=self.mangopay_id,
                   owners=[user],
                   description=self.description,
                   currency=self.currency)
예제 #17
0
파일: models.py 프로젝트: ojr9/g39
 def get_balance(self):
     wallet = Wallet.get(self.cuenta.wid)
     if self.balance != wallet.Balance.Amount / 100:
         self.balance = wallet.Balance.Amount / 100
         self.save()
     return self.balance, self.currency
예제 #18
0
    def test_retrieve_users_transactions(self):
        self.mock_natural_user()
        self.mock_legal_user()
        self.mock_user_wallet()
        self.mock_card()

        self.register_mock([{
            'method':
            responses.GET,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/users/1167495',
            'body': {
                "FirstName": "Victor",
                "LastName": "Hugo",
                "Address": {
                    "AddressLine1": "AddressLine1",
                    "AddressLine2": "AddressLine2",
                    "City": "City",
                    "Region": "Region",
                    "PostalCode": "11222",
                    "Country": "FR"
                },
                "Birthday": today_timestamp,
                "Nationality": "FR",
                "CountryOfResidence": "FR",
                "Occupation": "Writer",
                "IncomeRange": 6,
                "ProofOfIdentity": None,
                "ProofOfAddress": None,
                "PersonType": "NATURAL",
                "Email": "*****@*****.**",
                "Id": "1169419",
                "Tag": "custom tag",
                "CreationDate": 1383321421,
                "KYCLevel": "LIGHT",
                "UserCategory": "OWNER"
            },
            'status':
            200
        }, {
            'method':
            responses.POST,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/transfers',
            'body': {
                "Id": "1169434",
                "Tag": "DefaultTag",
                "CreationDate": 1431648000,
                "AuthorId": "1167495",
                "CreditedUserId": "1167502",
                "DebitedFunds": {
                    "Currency": "EUR",
                    "Amount": 1000
                },
                "CreditedFunds": {
                    "Currency": "EUR",
                    "Amount": 900
                },
                "Fees": {
                    "Currency": "EUR",
                    "Amount": 100
                },
                "Status": "SUCCEEDED",
                "ResultCode": "000000",
                "ResultMessage": "Success",
                "ExecutionDate": today_timestamp,
                "Type": "TRANSFER",
                "Nature": "REGULAR",
                "DebitedWalletId": "1167496",
                "CreditedWalletId": "1167504"
            },
            'status':
            200
        }, {
            'method':
            responses.GET,
            'url':
            settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID +
            '/users/1169419/transactions',
            'body': [{
                "Id": "1174837",
                "Tag": "my transfer",
                "CreationDate": 1431648000,
                "AuthorId": "1167495",
                "CreditedUserId": "1167502",
                "DebitedFunds": {
                    "Currency": "EUR",
                    "Amount": 1000
                },
                "CreditedFunds": {
                    "Currency": "EUR",
                    "Amount": 900
                },
                "Fees": {
                    "Currency": "EUR",
                    "Amount": 100
                },
                "Status": "SUCCEEDED",
                "ResultCode": "000000",
                "ResultMessage": "Success",
                "ExecutionDate": today_timestamp,
                "Type": "TRANSFER",
                "Nature": "REGULAR",
                "CreditedWalletId": "1167496",
                "DebitedWalletId": "1167504"
            }],
            'status':
            200
        }])

        wallet_params = {
            'tag': 'My custom tag',
            'owners': [self.card.user],
            'description': 'Wallet of Victor Hugo',
            'currency': 'EUR'
        }
        wallet = Wallet(**wallet_params)
        wallet.save()

        # Create a transaction:
        params = {
            "author": self.card.user,
            "credited_user": self.legal_user,
            "debited_funds": Money(amount=10, currency='EUR'),
            "fees": Money(amount=1, currency='EUR'),
            "debited_wallet": wallet,
            "credited_wallet": self.legal_user_wallet,
            "tag": "custom tag"
        }
        transfer = Transfer(**params)
        transfer.save()

        # List wallet's transactions
        transactions = Transaction.all(**{"user_id": self.card.user.id})

        self.assertEqual(len(transactions), 1)
        self.assertEqual(transactions[0].type, 'TRANSFER')
예제 #19
0
파일: models.py 프로젝트: ojr9/g39
 def update_wallet(self):
     if not self.cuenta.wid:
         wallet = Wallet.get(self.cuenta.wid)
         wallet.update(self.cuenta.wid, Description=self.cuenta.description)
         wallet.save()
예제 #20
0
    def test_retrieve_users_transactions(self):
        self.mock_natural_user()
        self.mock_legal_user()
        self.mock_user_wallet()
        self.mock_card()

        self.register_mock([
            {
                'method': responses.GET,
                'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1167495',
                'body': {
                    "FirstName": "Victor",
                    "LastName": "Hugo",
                    "Address": {
                        "AddressLine1": "AddressLine1",
                        "AddressLine2": "AddressLine2",
                        "City": "City",
                        "Region": "Region",
                        "PostalCode": "11222",
                        "Country": "FR"
                    },
                    "Birthday": today_timestamp,
                    "Nationality": "FR",
                    "CountryOfResidence": "FR",
                    "Occupation": "Writer",
                    "IncomeRange": 6,
                    "ProofOfIdentity": None,
                    "ProofOfAddress": None,
                    "PersonType": "NATURAL",
                    "Email": "*****@*****.**",
                    "Id": "1169419",
                    "Tag": "custom tag",
                    "CreationDate": 1383321421,
                    "KYCLevel": "LIGHT"
                },
                'status': 200
            },
            {
                'method': responses.POST,
                'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/transfers',
                'body': {
                    "Id": "1169434",
                    "Tag": "DefaultTag",
                    "CreationDate": 1431648000,
                    "AuthorId": "1167495",
                    "CreditedUserId": "1167502",
                    "DebitedFunds": {
                        "Currency": "EUR",
                        "Amount": 1000
                    },
                    "CreditedFunds": {
                        "Currency": "EUR",
                        "Amount": 900
                    },
                    "Fees": {
                        "Currency": "EUR",
                        "Amount": 100
                    },
                    "Status": "SUCCEEDED",
                    "ResultCode": "000000",
                    "ResultMessage": "Success",
                    "ExecutionDate": today_timestamp,
                    "Type": "TRANSFER",
                    "Nature": "REGULAR",
                    "DebitedWalletId": "1167496",
                    "CreditedWalletId": "1167504"
                },
                'status': 200
            },
            {
                'method': responses.GET,
                'url': settings.MANGOPAY_API_SANDBOX_URL + settings.MANGOPAY_CLIENT_ID + '/users/1169419/transactions',
                'body': [
                    {
                        "Id": "1174837",
                        "Tag": "my transfer",
                        "CreationDate": 1431648000,
                        "AuthorId": "1167495",
                        "CreditedUserId": "1167502",
                        "DebitedFunds": {
                            "Currency": "EUR",
                            "Amount": 1000
                        },
                        "CreditedFunds": {
                            "Currency": "EUR",
                            "Amount": 900
                        },
                        "Fees": {
                            "Currency": "EUR",
                            "Amount": 100
                        },
                        "Status": "SUCCEEDED",
                        "ResultCode": "000000",
                        "ResultMessage": "Success",
                        "ExecutionDate": today_timestamp,
                        "Type": "TRANSFER",
                        "Nature": "REGULAR",
                        "CreditedWalletId": "1167496",
                        "DebitedWalletId": "1167504"
                    }
                ],
                'status': 200
            }
        ])

        wallet_params = {
            'tag': 'My custom tag',
            'owners': [self.card.user],
            'description': 'Wallet of Victor Hugo',
            'currency': 'EUR'
        }
        wallet = Wallet(**wallet_params)
        wallet.save()

        # Create a transaction:
        params = {
            "author": self.card.user,
            "credited_user": self.legal_user,
            "debited_funds": Money(amount=10, currency='EUR'),
            "fees": Money(amount=1, currency='EUR'),
            "debited_wallet": wallet,
            "credited_wallet": self.legal_user_wallet,
            "tag": "custom tag"
        }
        transfer = Transfer(**params)
        transfer.save()

        # List wallet's transactions
        transactions = Transaction.all(**{"user_id": self.card.user.id})

        self.assertEqual(len(transactions), 1)
        self.assertEqual(transactions[0].type, 'TRANSFER')
예제 #21
0
 def Get(self, wallet_id):
     wallet = Wallet()
     wallet.id = wallet_id
     wallet.Balance = Money(10000, currency="EUR")
     return wallet