|
@@ -1270,7 +1270,7 @@ class CloudVodView(View):
|
|
|
|
|
|
order = order_qs[0]
|
|
|
if refund_amount > order.price:
|
|
|
- return response.json(10, '退款金额大于订单价格')
|
|
|
+ return response.json(801)
|
|
|
|
|
|
try:
|
|
|
# extra = {
|
|
@@ -1293,6 +1293,51 @@ class CloudVodView(View):
|
|
|
print(repr(e))
|
|
|
return response.json(10, repr(e))
|
|
|
|
|
|
+ def do_paypal_refund(self, request_dict, userID, response):
|
|
|
+ out_trade_no = request_dict.get('out_trade_no', None)
|
|
|
+ refund_amount = request_dict.get('refund_amount', None)
|
|
|
+
|
|
|
+ order_qs = Order_Model.objects.filter(orderID=out_trade_no, userID__userID=userID)
|
|
|
+
|
|
|
+ if not order_qs.exists():
|
|
|
+ return response.json(800)
|
|
|
+
|
|
|
+ order = order_qs[0]
|
|
|
+
|
|
|
+ refund_amount = float(refund_amount)
|
|
|
+ if order.price < refund_amount:
|
|
|
+ return response.json(801)
|
|
|
+
|
|
|
+ paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
+ payment = paypalrestsdk.Payment.find(order.trade_no)
|
|
|
+ transactions = payment['transactions']
|
|
|
+ transaction = transactions[0]
|
|
|
+ related_resources = transaction['related_resources']
|
|
|
+ if len(related_resources) > 0:
|
|
|
+ related_resource = related_resources[0]
|
|
|
+ sale = related_resource['sale']
|
|
|
+ id = sale['id']
|
|
|
+
|
|
|
+ if sale['state'] == 'completed':
|
|
|
+ paypalSale = paypalrestsdk.Sale.find(id)
|
|
|
+ refund = paypalSale.refund({
|
|
|
+ 'amount': {
|
|
|
+ 'total': refund_amount,
|
|
|
+ 'currency': order.currency
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if refund.success():
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(10, refund.error)
|
|
|
+ elif sale['state'] == 'refunded':
|
|
|
+ return response.json(804)
|
|
|
+ else:
|
|
|
+ return response.json(804)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
def deleteVodHls(request):
|
|
|
response = ResponseObject()
|