|
@@ -1968,27 +1968,33 @@ class CloudStorageView(View):
|
|
|
price = order_qs[0]['price'] # 订单金额
|
|
|
refunded_amount = order_qs[0]['refunded_amount'] # 已退款金额
|
|
|
currency = order_qs[0]['currency'] # 货币
|
|
|
- paymentID = order_qs[0]['paymentID'] # 退款id
|
|
|
|
|
|
# 判断是否符合付款条件
|
|
|
if refunded_amount == float(price): # 已全额退款
|
|
|
return response.json(805)
|
|
|
- if float(refund_amount) + refunded_amount >= float(price): # 退款金额超出订单价格
|
|
|
+ if refund_amount + refunded_amount > float(price): # 退款金额超出订单价格
|
|
|
return response.json(805)
|
|
|
# 部分退款标识
|
|
|
- is_partial_refund = True if(float(price) > float(refund_amount) + refunded_amount) else False
|
|
|
+ is_partial_refund = True if(float(price) > refund_amount + refunded_amount) else False
|
|
|
|
|
|
out_request_no = str(time.strftime('%Y%m%d%H%M%S', time.localtime(now_time))) # 退款请求号
|
|
|
# 根据支付类型处理退款
|
|
|
if payType == 1: # PayPal
|
|
|
+ paymentID = order_qs[0]['paymentID'] # PayPal PAYMENT_ID
|
|
|
+ if not paymentID:
|
|
|
+ return response.json(805)
|
|
|
paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
payment = paypalrestsdk.Payment.find(paymentID)
|
|
|
- print(payment)
|
|
|
+ print('payment', payment)
|
|
|
related_resources = payment['transactions'][0]['related_resources']
|
|
|
+ print('related_resources: ', related_resources)
|
|
|
if not related_resources:
|
|
|
return response.json(805)
|
|
|
sale = related_resources[0]['sale']
|
|
|
- if sale['state'] != 'completed':
|
|
|
+ print('sale: ', sale)
|
|
|
+ # 没退款过 'state' 不为 'completed' 或 已退款过但 'state' 不为 'partially_refunded'
|
|
|
+ if (refunded_amount == 0 and sale['state'] != 'completed') or \
|
|
|
+ (refunded_amount != 0 and sale['state'] != 'partially_refunded'):
|
|
|
return response.json(805)
|
|
|
sale_id = sale['id']
|
|
|
paypalSale = paypalrestsdk.Sale.find(sale_id)
|
|
@@ -2007,9 +2013,9 @@ class CloudStorageView(View):
|
|
|
refund_success = True if(refund_response['code'] == '10000') else False
|
|
|
elif payType == 3: # 微信
|
|
|
wechatPayObj = WechatPayObject()
|
|
|
- refund_amount = int(float(refund_amount) * 100) # 退款金额,单位为分,只能为整数
|
|
|
+ refund_fee = int(refund_amount * 100) # 退款金额,单位为分,只能为整数
|
|
|
success = wechatPayObj.refund(out_trade_no=orderID, out_refund_no=out_request_no,
|
|
|
- total_fee=refund_amount, refund_fee=refund_amount)
|
|
|
+ total_fee=refund_fee, refund_fee=refund_fee)
|
|
|
refund_success = True if success else False
|
|
|
else: # 不支持退款的支付类型
|
|
|
return response.json(805)
|
|
@@ -2018,7 +2024,7 @@ class CloudStorageView(View):
|
|
|
update_dict = {'updTime': now_time}
|
|
|
if refund_success:
|
|
|
update_dict['status'] = 6 if is_partial_refund else 5
|
|
|
- update_dict['refunded_amount'] = float(refund_amount)
|
|
|
+ update_dict['refunded_amount'] = refunded_amount + refund_amount
|
|
|
else:
|
|
|
update_dict['status'] = 4
|
|
|
order_qs.update(**update_dict)
|