|
@@ -100,12 +100,6 @@ class CloudVodView(View):
|
|
|
return self.do_pay_ok()
|
|
|
elif operation == 'payError':
|
|
|
return self.do_pay_error()
|
|
|
- elif operation == 'aliPayCallback':
|
|
|
- return self.do_ali_pay_callback(request)
|
|
|
- elif operation == 'dopaypalcallback':
|
|
|
- return self.do_pay_by_paypal_callback(request)
|
|
|
- elif operation == 'doalicallback':
|
|
|
- return self.do_pay_by_ali_callback(request)
|
|
|
else:
|
|
|
token = request_dict.get('token', None)
|
|
|
# 设备主键uid
|
|
@@ -114,9 +108,7 @@ class CloudVodView(View):
|
|
|
if tko.code != 0:
|
|
|
return response.json(tko.code)
|
|
|
userID = tko.userID
|
|
|
- if operation == 'createOrder':
|
|
|
- return self.do_create_order(request_dict, userID, response)
|
|
|
- elif operation == 'status':
|
|
|
+ if operation == 'status':
|
|
|
return self.do_change_status(request_dict, userID, response)
|
|
|
elif operation == 'details':
|
|
|
return self.do_get_details(request_dict, response)
|
|
@@ -124,149 +116,11 @@ class CloudVodView(View):
|
|
|
return self.do_filter_playlist(request_dict, userID, response)
|
|
|
elif operation == 'findVod':
|
|
|
return self.do_find_playlist(request_dict, userID, response)
|
|
|
- # 支付宝支付
|
|
|
- elif operation == 'aliPayCreateOrder':
|
|
|
- return self.do_pay_by_ali(request_dict, userID, response)
|
|
|
elif operation == 'orderStatus':
|
|
|
return self.do_pay_status(request_dict, userID, response)
|
|
|
- elif operation == 'createPayOrder':
|
|
|
- return self.do_create_pay_order(request_dict, userID, response)
|
|
|
- # elif operation == 'queryAlipayOrder':
|
|
|
- # return self.query_alipay_order(request_dict, userID, response)
|
|
|
- # elif operation == 'alipayCancel':
|
|
|
- # return self.do_alipay_cancel(request_dict, userID, response)
|
|
|
- # elif operation == 'alipayRefund':
|
|
|
- # return self.do_alipay_refund(request_dict, userID, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
|
- def do_ali_pay_callback(self, request):
|
|
|
- response = ResponseObject()
|
|
|
- data = request.POST.dict()
|
|
|
- signature = data["sign"]
|
|
|
- data.pop('sign')
|
|
|
- orderID = data['out_trade_no']
|
|
|
-
|
|
|
- order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
|
|
|
- print(order_qs)
|
|
|
-
|
|
|
- if not order_qs.exists():
|
|
|
- return response.json(404)
|
|
|
- print(json.dumps(data))
|
|
|
- print(signature)
|
|
|
- # verify
|
|
|
- aliPayObj = AliPayObject()
|
|
|
- alipay = aliPayObj.conf()
|
|
|
- success = alipay.verify(data, signature)
|
|
|
- if success and data["trade_status"] in ("TRADE_SUCCESS", "TRADE_FINISHED"):
|
|
|
- print("trade succeed")
|
|
|
- nowTime = int(time.time())
|
|
|
- order_list = order_qs.values("UID", "rank__id", "channel")
|
|
|
- rank_id = order_list[0]['rank__id']
|
|
|
- print(rank_id)
|
|
|
- UID = order_list[0]['UID']
|
|
|
- channel = order_list[0]['channel']
|
|
|
- order_qs.update(status=1, updTime=nowTime, trade_no=data['trade_no'])
|
|
|
-
|
|
|
- smqs = Store_Meal.objects.filter(id=rank_id).values("day", "bucket_id", "bucket__storeDay")
|
|
|
- bucketId = smqs[0]['bucket_id']
|
|
|
- if not smqs.exists():
|
|
|
- return response.json(0, '套餐已删除')
|
|
|
- addTime = int(smqs[0]["day"]) * 24 * 3600
|
|
|
- ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel). \
|
|
|
- values("bucket_id", "endTime", "bucket__storeDay")
|
|
|
- nowTime = int(time.time())
|
|
|
- if ubqs.exists():
|
|
|
- # 判断是否过期了
|
|
|
- if nowTime > ubqs[0]['endTime']:
|
|
|
- ubqs.update(endTime=nowTime + addTime)
|
|
|
- else:
|
|
|
- # 同一个bucket续费
|
|
|
- if bucketId == ubqs[0]['bucket_id']:
|
|
|
- ubqs.update(endTime=ubqs[0]['endTime'] + addTime)
|
|
|
- else:
|
|
|
- if ubqs[0]['bucket__storeDay'] > smqs[0]['bucket__storeDay']:
|
|
|
- return response.json(10, '不可选低级别套餐')
|
|
|
- else:
|
|
|
- # 升级
|
|
|
- origin_storeDay = int(ubqs[0]['bucket__storeDay'])
|
|
|
- upgrade_storeDay = int(smqs[0]['bucket__storeDay'])
|
|
|
- ctcTime = ubqs[0]['endTime'] - nowTime
|
|
|
- multiple = math.ceil(upgrade_storeDay / origin_storeDay)
|
|
|
- ubqs.update(endTime=ctcTime / multiple + addTime + ubqs[0]['endTime'], bucket_id=bucketId)
|
|
|
- # 付款成功把oss token删除
|
|
|
- OssCrdModel.objects.filter(uid=UID, channel=channel).delete()
|
|
|
- # 新增模式
|
|
|
- else:
|
|
|
- print('create')
|
|
|
- UID_Bucket.objects.create(uid=UID, channel=channel,
|
|
|
- bucket_id=bucketId, endTime=nowTime + addTime)
|
|
|
- red_url = "{SERVER_DOMAIN}cloudVod/payOK".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
- return HttpResponseRedirect(red_url)
|
|
|
- return response.json(0, signature)
|
|
|
-
|
|
|
- #发起支付宝支付
|
|
|
- def do_pay_by_ali(self, request_dict, userID, response):
|
|
|
- uid = request_dict.get('uid', None)
|
|
|
- rank = request_dict.get('rank', None)
|
|
|
- channel = request_dict.get('channel', None)
|
|
|
- qs = Device_Info.objects.filter(userID_id=userID, UID=uid, isShare=False)
|
|
|
- if not qs.exists():
|
|
|
- return response.json(12)
|
|
|
- if not channel or not rank:
|
|
|
- return response.json(444, 'channel,rank')
|
|
|
- smqs = Store_Meal.objects.filter(id=rank). \
|
|
|
- values("title", "currency", "price", "content", "day", "bucket__storeDay", "bucket__region", "type")
|
|
|
- if not smqs.exists():
|
|
|
- # 套餐不存在
|
|
|
- return response.json(173)
|
|
|
- if smqs[0]['type'] != 1:
|
|
|
- return response.json(10, '不支持支付宝支付')
|
|
|
- currency = smqs[0]['currency']
|
|
|
- price = smqs[0]['price']
|
|
|
- content = smqs[0]['content']
|
|
|
- day = smqs[0]['day']
|
|
|
- nowTime = int(time.time())
|
|
|
- ubqs = UID_Bucket.objects.filter(uid=uid, channel=channel, endTime__gte=nowTime). \
|
|
|
- values("bucket__storeDay", "bucket__region")
|
|
|
- if ubqs.exists():
|
|
|
- if ubqs[0]['bucket__region'] != smqs[0]['bucket__region']:
|
|
|
- return response.json(712) # 区域不一致
|
|
|
- elif ubqs[0]['bucket__storeDay'] != smqs[0]['bucket__storeDay']:
|
|
|
- return response.json(713) # 不可更改套餐
|
|
|
- # 续费流程
|
|
|
- nowTime = int(time.time())
|
|
|
- # 新增流程
|
|
|
- orderID = CommonService.createOrderID()
|
|
|
-
|
|
|
- try:
|
|
|
- aliPayObj = AliPayObject()
|
|
|
- alipay = aliPayObj.conf()
|
|
|
- order_string = alipay.api_alipay_trade_wap_pay(
|
|
|
- out_trade_no=orderID,
|
|
|
- total_amount=price,
|
|
|
- subject=smqs[0]['title'],
|
|
|
- return_url="{SERVER_DOMAIN_SSL}cloudVod/payOK".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL),
|
|
|
- notify_url="{SERVER_DOMAIN_SSL}cloudVod/aliPayCallback".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
- # return_url="http://192.168.136.40/cloudVod/payOK",
|
|
|
- # notify_url="http://192.168.136.40/cloudVod/aliPayCallback"
|
|
|
- )
|
|
|
- print(order_string)
|
|
|
- except Exception as e:
|
|
|
- print(repr(e))
|
|
|
- return response.json(10, repr(e))
|
|
|
- if order_string:
|
|
|
- redirectUrl = aliPayObj.alipay_prefix + order_string
|
|
|
- Order_Model.objects.create(orderID=orderID, UID=uid, channel=channel, userID_id=userID, desc=content,
|
|
|
- price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
|
- endTime=nowTime + int(day) * 3600 * 24, rank_id=rank, payType=1)
|
|
|
- return JsonResponse(status=200,
|
|
|
- data={'result_code': 0, 'reason': 'success',
|
|
|
- 'result': {"redirectUrl": redirectUrl, "orderID": orderID},
|
|
|
- 'error_code': 0})
|
|
|
- else:
|
|
|
- return response.json(10, '生成订单错误')
|
|
|
-
|
|
|
def do_get_details(self, request_dict, response):
|
|
|
uid = request_dict.get('uid', None)
|
|
|
dvqs = Device_Info.objects.filter(UID=uid, isShare=False)
|
|
@@ -438,262 +292,6 @@ class CloudVodView(View):
|
|
|
'''
|
|
|
return response
|
|
|
|
|
|
- def do_pay_by_ali_callback(self, request):
|
|
|
- response = ResponseObject()
|
|
|
- data = request.POST.dict()
|
|
|
- signature = data["sign"]
|
|
|
- data.pop('sign')
|
|
|
- orderID = data['out_trade_no']
|
|
|
-
|
|
|
- order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
|
|
|
- print(order_qs)
|
|
|
-
|
|
|
- if not order_qs.exists():
|
|
|
- return response.json(404)
|
|
|
- print(json.dumps(data))
|
|
|
- print(signature)
|
|
|
- # verify
|
|
|
- aliPayObj = AliPayObject()
|
|
|
- alipay = aliPayObj.conf()
|
|
|
- success = alipay.verify(data, signature)
|
|
|
- if success and data["trade_status"] in ("TRADE_SUCCESS", "TRADE_FINISHED"):
|
|
|
- print("trade succeed")
|
|
|
- nowTime = int(time.time())
|
|
|
- order_list = order_qs.values("UID", "commodity_code", "channel")
|
|
|
- UID = order_list[0]['UID']
|
|
|
- channel = order_list[0]['channel']
|
|
|
- commodity_code = order_list[0]['commodity_code']
|
|
|
- order_qs.update(status=1, updTime=nowTime)
|
|
|
- smqs = Store_Meal.objects.filter(commodity_code=commodity_code).\
|
|
|
- values("day", "bucket_id", "bucket__storeDay")
|
|
|
- bucketId = smqs[0]['bucket_id']
|
|
|
- if not smqs.exists():
|
|
|
- return response.json(0, '套餐已删除')
|
|
|
- addTime = int(smqs[0]["day"]) * 24 * 3600
|
|
|
- ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel). \
|
|
|
- values("bucket_id", "endTime", "bucket__storeDay")
|
|
|
- nowTime = int(time.time())
|
|
|
- if ubqs.exists():
|
|
|
- ubqs_count = ubqs.count()
|
|
|
- ubq = ubqs[ubqs_count - 1, ubqs_count]
|
|
|
- new_starTime = ubq['endTime'] + 1
|
|
|
- UID_Bucket.objects.create(uid=UID, channel=channel, bucket_id=bucketId, endTime=new_starTime + addTime)
|
|
|
- else:
|
|
|
- UID_Bucket.objects.create(uid=UID, channel=channel, bucket_id=bucketId, endTime=nowTime + addTime)
|
|
|
- red_url = "{SERVER_DOMAIN}cloudVod/payOK".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
- return HttpResponseRedirect(red_url)
|
|
|
- return response.json(0, signature)
|
|
|
-
|
|
|
- def do_pay_by_paypal_callback(self, request_dict, response):
|
|
|
- paymentId = request_dict.get('paymentId', None)
|
|
|
- PayerID = request_dict.get('PayerID', None)
|
|
|
- orderID = request_dict.get('orderID', None)
|
|
|
- if not paymentId or not PayerID or not orderID:
|
|
|
- red_url = "{SERVER_DOMAIN}cloudVod/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
- return HttpResponseRedirect(red_url)
|
|
|
- paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
- # ID of the payment. This ID is provided when creating payment.
|
|
|
- payment = paypalrestsdk.Payment.find(paymentId)
|
|
|
- payres = payment.execute({"payer_id": PayerID})
|
|
|
- print(payres)
|
|
|
- if not payres:
|
|
|
- red_url = "{SERVER_DOMAIN}cloudVod/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
- return HttpResponseRedirect(red_url)
|
|
|
- print("Payment execute successfully")
|
|
|
- order_qs = Order_Model.objects.filter(orderID=orderID)
|
|
|
- nowTime = int(time.time())
|
|
|
- order_qs.update(status=1, updTime=nowTime)
|
|
|
- order_list = order_qs.values("UID", "channel", "commodity_code")
|
|
|
- UID = order_list[0]['UID']
|
|
|
- channel = order_list[0]['channel']
|
|
|
- commodity_code = order_list[0]['commodity_code']
|
|
|
- smqs = Store_Meal.objects.filter(commodity_code=commodity_code).\
|
|
|
- values("day", "bucket_id", "bucket__storeDay")
|
|
|
- bucketId = smqs[0]['bucket_id']
|
|
|
- if not smqs.exists():
|
|
|
- return response.json(0, '套餐已删除')
|
|
|
- addTime = int(smqs[0]["day"]) * 24 * 3600
|
|
|
- # ##
|
|
|
- ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel, endTime__gte=nowTime). \
|
|
|
- values("bucket__storeDay", "bucket__region", "endTime")
|
|
|
- if ubqs.exists():
|
|
|
- ubqs_count = ubqs.count()
|
|
|
- ubq = ubqs[ubqs_count - 1, ubqs_count]
|
|
|
- new_starTime = ubq['endTime'] + 1
|
|
|
- UID_Bucket.objects.create(uid=UID, channel=channel, bucket_id=bucketId, endTime=new_starTime + addTime)
|
|
|
- else:
|
|
|
- UID_Bucket.objects.create(uid=UID, channel=channel, bucket_id=bucketId, endTime=nowTime + addTime)
|
|
|
- # return response.json(0)
|
|
|
- red_url = "{SERVER_DOMAIN}cloudVod/payOK".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
- return HttpResponseRedirect(red_url)
|
|
|
-
|
|
|
- def do_create_pay_order(self, request_dict, userID, response):
|
|
|
- uid = request_dict.get('uid', None)
|
|
|
- channel = request_dict.get('channel', None)
|
|
|
- commodity_code = request_dict.get('commodity_code', None)
|
|
|
- pay_type = int(request_dict.get('pay_type', None))
|
|
|
- dv_qs = Device_Info.objects.filter(userID_id=userID, UID=uid, isShare=False, isExist=1)
|
|
|
- if not dv_qs.exists():
|
|
|
- return response.json(12)
|
|
|
- smqs = Store_Meal.objects.filter(commodity_code=commodity_code, type=pay_type). \
|
|
|
- values('currency', 'price', 'content', 'day', 'commodity_type', 'title', 'content')
|
|
|
- if not smqs.exists():
|
|
|
- return response.json(10, '套餐不存在')
|
|
|
- currency = smqs[0]['currency']
|
|
|
- price = smqs[0]['price']
|
|
|
- content = smqs[0]['content']
|
|
|
- day = smqs[0]['day']
|
|
|
- commodity_type = smqs[0]['commodity_type']
|
|
|
- # ubqs = UID_Bucket.objects.filter(uid=uid, channel=channel, endTime__gte=nowTime). \
|
|
|
- # values("bucket__storeDay", "bucket__region", "endTime")
|
|
|
- # if ubqs.exists():
|
|
|
- # ubqs_count = ubqs.count()
|
|
|
- # ubq = ubqs[ubqs_count - 1, ubqs_count]
|
|
|
- # new_starTime = ubq['endTime'] + 1
|
|
|
- nowTime = int(time.time())
|
|
|
- orderID = CommonService.createOrderID()
|
|
|
- if pay_type == 0:
|
|
|
- call_sub_url = "{SERVER_DOMAIN}cloudVod/dopaypalcallback?orderID={orderID}". \
|
|
|
- format(SERVER_DOMAIN=SERVER_DOMAIN, orderID=orderID)
|
|
|
- # call_sub_url = "http://192.168.136.40:8077/cloudVod/payExecute?orderID={orderID}".format(
|
|
|
- # SERVER_DOMAIN=SERVER_DOMAIN, orderID=orderID)
|
|
|
- call_clc_url = "{SERVER_DOMAIN}cloudVod/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
- paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
- payment = paypalrestsdk.Payment({
|
|
|
- "intent": "sale",
|
|
|
- "payer": {"payment_method": "paypal"},
|
|
|
- "redirect_urls": {"return_url": call_sub_url, "cancel_url": call_clc_url},
|
|
|
- "transactions": [{
|
|
|
- "item_list": {
|
|
|
- "items": [
|
|
|
- {"name": "Cloud video", "sku": "1", "price": price, "currency": "USD", "quantity": 1}]},
|
|
|
- "amount": {"total": price, "currency": currency},
|
|
|
- "description": content
|
|
|
- }]})
|
|
|
- if payment.create():
|
|
|
- print("Payment created successfully")
|
|
|
- else:
|
|
|
- print(payment.error)
|
|
|
- return response.json(10, payment.error)
|
|
|
- print(payment)
|
|
|
- for link in payment.links:
|
|
|
- if link.rel == "approval_url":
|
|
|
- approval_url = str(link.href)
|
|
|
- print("Redirect for approval: %s" % (approval_url))
|
|
|
- Order_Model.objects.create(orderID=orderID, UID=uid, channel=channel, userID_id=userID,
|
|
|
- desc=content,
|
|
|
- price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
|
- endTime=(nowTime + int(day) * 3600 * 24), paypal=approval_url,
|
|
|
- commodity_code=commodity_code, commodity_type=commodity_type)
|
|
|
- return response.json(0, {"redirectUrl": approval_url, "orderID": orderID})
|
|
|
- return response.json(10, 'generate_order_false')
|
|
|
- else:
|
|
|
- try:
|
|
|
- aliPayObj = AliPayObject()
|
|
|
- alipay = aliPayObj.conf()
|
|
|
- subject = smqs[0]['title'] + smqs[0]['content']
|
|
|
- order_string = alipay.api_alipay_trade_wap_pay(
|
|
|
- out_trade_no=orderID,
|
|
|
- total_amount=price,
|
|
|
- subject=subject,
|
|
|
- return_url="{SERVER_DOMAIN_SSL}cloudVod/payOK".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL),
|
|
|
- notify_url="{SERVER_DOMAIN_SSL}cloudVod/doalicallback".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
- # return_url="http://192.168.136.40/cloudVod/payOK",
|
|
|
- # notify_url="http://192.168.136.40/cloudVod/aliPayCallback"
|
|
|
- )
|
|
|
- except Exception as e:
|
|
|
- print(repr(e))
|
|
|
- return response.json(10, repr(e))
|
|
|
- else:
|
|
|
- if order_string:
|
|
|
- redirectUrl = aliPayObj.alipay_prefix + order_string
|
|
|
- Order_Model.objects.create(orderID=orderID, UID=uid, channel=channel, userID_id=userID,
|
|
|
- desc=content, price=price, currency=currency, addTime=nowTime,
|
|
|
- updTime=nowTime, endTime=nowTime + int(day) * 3600 * 24,
|
|
|
- commodity_code=commodity_code, commodity_type=commodity_type,
|
|
|
- paypal='', payType=1)
|
|
|
- return JsonResponse(status=200, data={'result_code': 0, 'reason': 'success',
|
|
|
- 'result': {"redirectUrl": redirectUrl, "orderID": orderID},
|
|
|
- 'error_code': 0})
|
|
|
- else:
|
|
|
- return response.json(10, '生成订单错误')
|
|
|
-
|
|
|
- # 发起paypal支付
|
|
|
- def do_create_order(self, request_dict, userID, response):
|
|
|
- uid = request_dict.get('uid', None)
|
|
|
- rank = request_dict.get('rank', None)
|
|
|
- channel = request_dict.get('channel', None)
|
|
|
- if not uid or not channel or not rank:
|
|
|
- return response.json(444, 'channel,rank')
|
|
|
- qs = Device_Info.objects.filter(userID_id=userID, UID=uid, isShare=False)
|
|
|
-
|
|
|
- if not qs.exists():
|
|
|
- return response.json(12)
|
|
|
- smqs = Store_Meal.objects.filter(id=rank). \
|
|
|
- values("currency", "price", "content", "day", "bucket__storeDay", "bucket__region", "type")
|
|
|
- if not smqs.exists():
|
|
|
- return response.json(10, '套餐不存在')
|
|
|
- if smqs[0]['type'] != 0:
|
|
|
- return response.json(10, '套餐不支持paypal支付')
|
|
|
- currency = smqs[0]['currency']
|
|
|
- price = smqs[0]['price']
|
|
|
- content = smqs[0]['content']
|
|
|
- day = smqs[0]['day']
|
|
|
- nowTime = int(time.time())
|
|
|
- ubqs = UID_Bucket.objects.filter(uid=uid, channel=channel, endTime__gte=nowTime). \
|
|
|
- values("bucket__storeDay", "bucket__region")
|
|
|
- if ubqs.exists():
|
|
|
- if ubqs[0]['bucket__region'] != smqs[0]['bucket__region']:
|
|
|
- return response.json(712) # 区域不一致
|
|
|
- # elif ubqs[0]['bucket__storeDay'] > smqs[0]['bucket__storeDay']:
|
|
|
- # return response.json(711) # 不可降级
|
|
|
- elif ubqs[0]['bucket__storeDay'] != smqs[0]['bucket__storeDay']:
|
|
|
- return response.json(713) # 不可更改套餐
|
|
|
- # 续费流程
|
|
|
- nowTime = int(time.time())
|
|
|
- # 判断是否存在未完成订单
|
|
|
- # hasOrder = Order_Model.objects.filter(UID=uid, channel=channel, addTime__gte=nowTime - 3600, status=0,
|
|
|
- # rank_id=rank, userID_id=userID).values('paypal')
|
|
|
- # if hasOrder.exists():
|
|
|
- # approval_url = hasOrder[0]['paypal']
|
|
|
- # return response.json(0, {"redirectUrl": approval_url})
|
|
|
- # 新增流程
|
|
|
- orderID = CommonService.createOrderID()
|
|
|
- call_sub_url = "{SERVER_DOMAIN}cloudVod/payExecute?orderID={orderID}". \
|
|
|
- format(SERVER_DOMAIN=SERVER_DOMAIN, orderID=orderID)
|
|
|
- # call_sub_url = "http://192.168.136.40:8077/cloudVod/payExecute?orderID={orderID}".format(
|
|
|
- # SERVER_DOMAIN=SERVER_DOMAIN, orderID=orderID)
|
|
|
- call_clc_url = "{SERVER_DOMAIN}cloudVod/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
- paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
- payment = paypalrestsdk.Payment({
|
|
|
- "intent": "sale",
|
|
|
- "payer": {"payment_method": "paypal"},
|
|
|
- "redirect_urls": {"return_url": call_sub_url, "cancel_url": call_clc_url},
|
|
|
- "transactions": [{
|
|
|
- "item_list": {
|
|
|
- "items": [{"name": "Cloud video", "sku": "1", "price": price, "currency": "USD", "quantity": 1}]},
|
|
|
- "amount": {"total": price, "currency": currency},
|
|
|
- "description": content
|
|
|
- }]})
|
|
|
- if payment.create():
|
|
|
- print("Payment created successfully")
|
|
|
- else:
|
|
|
- print(payment.error)
|
|
|
- return response.json(10, payment.error)
|
|
|
- print(payment)
|
|
|
- for link in payment.links:
|
|
|
- if link.rel == "approval_url":
|
|
|
- approval_url = str(link.href)
|
|
|
- print("Redirect for approval: %s" % (approval_url))
|
|
|
- Order_Model.objects.create(orderID=orderID, UID=uid, trade_no=payment['id'], channel=channel, userID_id=userID, desc=content,
|
|
|
- price=price, currency=currency, addTime=nowTime, updTime=nowTime,
|
|
|
- endTime=nowTime + int(day) * 3600 * 24,
|
|
|
- rank_id=rank,
|
|
|
- paypal=approval_url)
|
|
|
- return response.json(0, {"redirectUrl": approval_url, "orderID": orderID})
|
|
|
- return response.json(10, 'generate_order_false')
|
|
|
-
|
|
|
-
|
|
|
def do_getSts(self, request_dict, ip, response):
|
|
|
uidToken = request_dict.get('uidToken', None)
|
|
|
utko = UidTokenObject(uidToken)
|