def get(self): payments = Payment.objects(payer_id=current_user.id, confirm=True) buy_orders = Order.objects(buyer_id=current_user.id, status__ne=ORDER_STATUS["CANCEL"]) sell_orders = Order.objects(product_id__in=Product.objects(seller_id=current_user.id), status=ORDER_STATUS["COMPLETE"]) records = list() for payment in payments: record = Record("儲值", payment.amount, payment.create_time) records.append(record) for order in buy_orders: if order.product_id.bidding == False: if order.coupon_id == None: record = Record("購買" + order.product_id.name, -1 * int(order.product_id.price * order.product_id.discount), order.create_time) else: record = Record("購買" + order.product_id.name, -1 * max(0, int(order.product_id.price * order.product_id.discount - order.coupon_id.discount)), order.create_time) else: record = Record("購買" + order.product_id.name, -1 * order.product_id.bid.now_price, order.create_time) records.append(record) for order in sell_orders: if order.product_id.bidding == False: record = Record("販賣" + order.product_id.name, int(order.product_id.price * RATE), order.finish_time) else: record = Record("販賣" + order.product_id.name, int(order.product_id.bid.now_price * RATE), order.finish_time) records.append(record) records = sorted(records, key=lambda k: k.time, reverse=True) return render_template('user/hicoin/record.html', records=records)
def get(self): payment = Payment.objects( payer_id=current_user.id, transaction_id=request.args.get('transactionId')).first() headers = { "X-LINE-ChannelId": app.config['CHANNEL_ID'], "X-LINE-ChannelSecret": app.config['CHANNEL_SECRET'], "Content-Type": "application/json; charset=UTF-8" } data = {"amount": payment.amount, "currency": payment.currency} response = requests.post(app.config['CHANNEL_CONFIRM_URL'].format( payment.transaction_id), headers=headers, data=json.dumps(data).encode('utf-8')) if int(json.loads(response.text)['returnCode']) == 0: payment.confirm = True payment.save() current_user.hicoin += payment.amount current_user.save() return redirect(url_for('user.payment'))