|
@@ -109,6 +109,8 @@ class CloudStorageView(View):
|
|
|
return self.do_vod_msg_end(request_dict)
|
|
|
elif operation == 'vodMsgNotice': # 云存操作系统消息
|
|
|
return self.do_vod_msg_Notice(request_dict)
|
|
|
+ elif operation == 'doRefund': # 退款
|
|
|
+ return self.do_refund(request_dict, response)
|
|
|
|
|
|
else:
|
|
|
token = request_dict.get('token', None)
|
|
@@ -818,6 +820,7 @@ class CloudStorageView(View):
|
|
|
paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
# ID of the payment. This ID is provided when creating payment.
|
|
|
payment = paypalrestsdk.Payment.find(paymentId)
|
|
|
+ print(payment)
|
|
|
payres = payment.execute({"payer_id": PayerID})
|
|
|
print(payres)
|
|
|
if not payres:
|
|
@@ -1065,7 +1068,6 @@ class CloudStorageView(View):
|
|
|
|
|
|
orderID = CommonService.createOrderID()
|
|
|
if pay_type == 1:
|
|
|
-
|
|
|
cal_url = "{SERVER_DOMAIN_SSL}web/paid2/fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
if lang != 'cn':
|
|
|
cal_url = "{SERVER_DOMAIN_SSL}web/paid2/en_fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
@@ -1090,6 +1092,7 @@ class CloudStorageView(View):
|
|
|
print(payment.error)
|
|
|
return response.json(10, payment.error)
|
|
|
print(payment)
|
|
|
+ paymentID = payment['id'] # 获取paymentID
|
|
|
for link in payment.links:
|
|
|
if link.rel == "approval_url":
|
|
|
approval_url = str(link.href)
|
|
@@ -1099,7 +1102,7 @@ class CloudStorageView(View):
|
|
|
price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
|
pay_url=approval_url, isSelectDiscounts=is_select_discount,
|
|
|
commodity_code=commodity_code, commodity_type=commodity_type,
|
|
|
- rank_id=rank)
|
|
|
+ rank_id=rank, paymentID=paymentID)
|
|
|
return response.json(0, {"redirectUrl": approval_url, "orderID": orderID})
|
|
|
return response.json(10, 'generate_order_false')
|
|
|
elif pay_type == 2:
|
|
@@ -1668,6 +1671,67 @@ class CloudStorageView(View):
|
|
|
res = aliSms.send_code_sms_cloud(phone=phone, params = params, sign_name=sign_ms,
|
|
|
temp_msg=temp_msg)
|
|
|
|
|
|
+ def do_refund(self, request_dict, response):
|
|
|
+ orderID = request_dict.get('orderID', None) # 商户订单号
|
|
|
+ if not orderID:
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=orderID).\
|
|
|
+ values('status', 'payType', 'price', 'currency', 'paymentID')
|
|
|
+ if not order_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+
|
|
|
+ # 支付状态不为支付成功和退款失败
|
|
|
+ status = order_qs[0]['status']
|
|
|
+ if status != 1 and status != 4:
|
|
|
+ return response.json(805)
|
|
|
+
|
|
|
+ now_time = int(time.time())
|
|
|
+ payType = order_qs[0]['payType']
|
|
|
+ refund_amount = order_qs[0]['price'] # 退款金额
|
|
|
+ currency = order_qs[0]['currency'] # 货币
|
|
|
+ paymentID = order_qs[0]['paymentID'] # 退款id
|
|
|
+ out_request_no = str(time.strftime('%Y%m%d%H%M%S', time.localtime(now_time))) # 退款请求号
|
|
|
+ # 根据支付类型处理退款
|
|
|
+ if payType == 1: # PayPal
|
|
|
+ paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
+ payment = paypalrestsdk.Payment.find(paymentID)
|
|
|
+ print(payment)
|
|
|
+ related_resources = payment['transactions'][0]['related_resources']
|
|
|
+ if not related_resources:
|
|
|
+ return response.json(805)
|
|
|
+ sale = related_resources[0]['sale']
|
|
|
+ if sale['state'] != 'completed':
|
|
|
+ return response.json(805)
|
|
|
+ sale_id = sale['id']
|
|
|
+ paypalSale = paypalrestsdk.Sale.find(sale_id)
|
|
|
+ refund = paypalSale.refund({
|
|
|
+ 'amount': {
|
|
|
+ 'total': refund_amount,
|
|
|
+ 'currency': currency
|
|
|
+ }
|
|
|
+ })
|
|
|
+ status = 5 if refund.success() else 4
|
|
|
+ elif payType == 2: # 支付宝
|
|
|
+ aliPayObj = AliPayObject()
|
|
|
+ alipay = aliPayObj.conf()
|
|
|
+ refund_response = alipay.api_alipay_trade_refund(refund_amount=refund_amount, out_trade_no=orderID,
|
|
|
+ out_request_no=out_request_no)
|
|
|
+ # 退款成功,修改订单支付状态为'退款成功',否则改为'退款失败'
|
|
|
+ status = 5 if refund_response['code'] == '10000' else 4
|
|
|
+ elif payType == 3: # 微信
|
|
|
+ wechatPayObj = WechatPayObject()
|
|
|
+ refund_amount = int(float(refund_amount) * 100) # 退款金额,单位为分,只能为整数
|
|
|
+ refund_success = wechatPayObj.refund(out_trade_no=orderID, out_refund_no=out_request_no,
|
|
|
+ total_fee=refund_amount, refund_fee=refund_amount)
|
|
|
+ status = 5 if refund_success else 4
|
|
|
+ else: # 不支持退款的支付类型
|
|
|
+ return response.json(805)
|
|
|
+ order_qs.update(status=status, updTime=now_time) # 更新订单状态
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
|
|
|
|
|
|
# 删除过期云存播放列表
|