예제 #1
0
    def setUp(self):
        super(UpdateWithdrawAddressTestCase, self).setUp()

        PaymentMethod.objects.all().delete()

        method_data = {
            'bin': 426101,
            'fee': 0.0,
            'is_slow': 0,
            'name': 'Alpha Bank Visa'
        }
        payment_method = PaymentMethod(**method_data)
        payment_method.save()

        pref_data = {
            'user': self.user,
            'identifier': str(payment_method.bin),
            'comment': 'Just testing'
        }
        pref = PaymentPreference(**pref_data)
        pref.save()
        pref.currency.add(self.USD)
        pref.save()
        """Creates an order"""
        data = {
            'amount_cash': Decimal(30674.85),
            'amount_btc': Decimal(1.00),
            'currency': self.USD,
            'user': self.user,
            'admin_comment': 'test Order',
            'unique_reference': '12345',
            'payment_preference': pref
        }

        order = Order(**data)
        # TODO: patch and uncomment
        # order.full_clean()  # ensure is initially correct
        order.save()
        self.order = order

        pk = self.order.pk
        self.url = reverse('core.update_withdraw_address', kwargs={'pk': pk})

        self.addr_data = {
            'type': 'W',
            'name': '17NdbrSGoUotzeGCcMMCqnFkEvLymoou9j',
            'address': '17NdbrSGoUotzeGCcMMCqnFkEvLymoou9j',
        }
        self.addr = Address(**self.addr_data)
        self.addr.user = self.user
        self.addr.save()

        # The 'other' address for the Transaction
        user = User.objects.create_user(username='******')
        addr2 = Address(**self.addr_data)
        addr2.user = user
        addr2.save()
예제 #2
0
 def _create_withdraw_adress(self, currency, address):
     addr_data = {
         'type': 'W',
         'name': address,
         'address': address,
         'currency': currency
     }
     addr = Address(**addr_data)
     addr.user = self.user
     addr.save()
     return addr
예제 #3
0
def create_withdraw_address(request, order_pk):
    error_message = 'Error creating address: %s'
    order = Order.objects.get(pk=order_pk)
    if not order.user.profile.is_verified and not order.exchange:
        pm = order.payment_preference.payment_method
        if pm.required_verification_buy or order.user.profile.anonymous_login:
            resp = {
                'status':
                'ERR',
                'msg':
                'You need to be a verified user to set withdrawal '
                'address for order with payment method \'{}\''
                ''.format(pm.name)
            }
            return JsonResponse(resp, safe=False)

    address = request.POST.get('value')
    addr = Address()
    addr.type = Address.WITHDRAW
    addr.user = request.user
    addr.address = address
    if order.order_type == Order.BUY:
        currency = order.pair.base
    else:
        currency = order.pair.quote
    addr.currency = currency

    try:
        if currency.code == 'BTC':
            validate_btc(addr.address)
        elif currency.code == 'LTC':
            validate_ltc(addr.address)
        elif currency.code == 'ETH':
            validate_eth(addr.address)
        else:
            validate_address(addr.address)
        addr.save()
        resp = {'status': 'OK', 'pk': addr.pk, 'target': addr.currency.code}

    except ValidationError:
        resp = {'status': 'ERR', 'msg': 'The supplied address is invalid.'}

    except Exception as e:
        msg = error_message % (e)
        resp = {'status': 'ERR', 'msg': msg}

    return JsonResponse(resp, safe=False)
예제 #4
0
def create_withdraw_address(request):
    error_message = 'Error creating address: %s'

    address = request.POST.get('value')

    addr = Address()
    addr.type = Address.WITHDRAW
    addr.user = request.user
    addr.address = address

    try:
        validate_bc(addr.address)
        addr.save()
        resp = {'status': 'OK', 'pk': addr.pk}

    except ValidationError:
        resp = {'status': 'ERR', 'msg': 'The supplied address is invalid.'}

    except Exception as e:
        msg = error_message % (e)
        resp = {'status': 'ERR', 'msg': msg}

    return JsonResponse(resp, safe=False)