Example #1
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
Example #2
0
    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
Example #3
0
 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()
Example #4
0
File: models.py Project: 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()
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))
Example #6
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
Example #7
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': {}
         })
Example #8
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)
    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')
Example #10
0
 def Get(self, wallet_id):
     wallet = Wallet()
     wallet.id = wallet_id
     wallet.Balance = Money(10000, currency="EUR")
     return wallet