def post(self): parser = CustomRequestParser() parser.add_argument('amount', type=str, required=True, nullable=False, location='json') parsed_args = parser.parse_args() api = cryptopay_api() url = '{}/member/create_charge_order'.format( current_app.config['CRYPTOPAY_BASE_URL']) currency_overt = CurrencyConvertApi() current_covert = currency_overt.get() for item in current_covert: if item['symbol'] == 'BTC': BTC = float(parsed_args['amount']) / float(item['price_usd']) elif item['symbol'] == 'ETH': ETH = float(parsed_args['amount']) / float(item['price_usd']) payments = 'BTC={};ETH={}'.format(BTC, ETH) data = { 'number': str(uuid.uuid4()), 'amount': parsed_args['amount'], 'payments': payments, 'extra': '' } try: result = api.post(url, data) except CryptoPayApiError as e: abort(e.http_status_code, code=e.code, message=e.message) result['currency_address_qr_code'] = current_app.config[ 'CRYPTOPAY_BASE_URL'] + '/currency_address_qr_code' return result
def pay_order(order_number): api = cryptopay_api() url = '{}/member/pay_order'.format( current_app.config['CRYPTOPAY_BASE_URL']) data = {'number': order_number} try: return api.post(url, data) except CryptoPayApiError as e: abort(e.http_status_code, code=e.code, message=e.message)
def create_transaction_order(order_number, address, amount, fee, type=2): api = cryptopay_api() url = '{}/member/create_transaction_order'.format( current_app.config['CRYPTOPAY_BASE_URL']) data = { 'number': order_number, 'address': address, 'amount': str(amount), 'fee': str(fee), 'extra': json.dumps({'type': type}) } try: return api.post(url, data) except CryptoPayApiError as e: abort(e.http_status_code, code=e.code, message=e.message)
def generate_wallet(user_id, currency_list): api = cryptopay_api() url = '{}/member/create_wallet'.format( current_app.config['CRYPTOPAY_BASE_URL']) data = {'currency_list': currency_list} try: wallet_list = api.post(url, data) for w in wallet_list['objects']: address_qr_code = '%s/currency_address_qr_code/%s' % ( current_app.config['CRYPTOPAY_BASE_URL'], w['address']) wallet = Wallet(user_id=user_id, currency_id=w['currency_id'], address=w['address'], address_qr_code=address_qr_code) db.session.add(wallet) db.session.commit() except CryptoPayApiError as e: abort(e.http_status_code, code=e.code, message=e.message)
def query_wallet(wallet_list): address_list = [] for wallet in wallet_list: address_list.append(wallet.address) api = cryptopay_api() url = '{}/member/query_wallet'.format( current_app.config['CRYPTOPAY_BASE_URL']) data = {'address_list': ','.join(address_list)} try: address_balance_dict = {} query_wallet_list = api.post(url, data) for query_wallet in query_wallet_list['objects']: address_balance_dict[ query_wallet['address']] = query_wallet['balance'] for wallet in wallet_list: wallet.balance = address_balance_dict.get(wallet.address, '0') except CryptoPayApiError as e: abort(e.http_status_code, code=e.code, message=e.message)