|
@@ -377,7 +377,7 @@ class PaypalCycleNotify(View):
|
|
|
event_type = json_obj.get('event_type')
|
|
|
summary = json_obj.get('summary')
|
|
|
resource_type = json_obj.get('resource_type')
|
|
|
- billing_agreement_id = paypal_body.get('billing_agreement_id')
|
|
|
+ agreement_id = paypal_body.get('billing_agreement_id')
|
|
|
paypal_transaction_id = paypal_body.get('id')
|
|
|
amount = paypal_body.get('amount')
|
|
|
|
|
@@ -408,7 +408,7 @@ class PaypalCycleNotify(View):
|
|
|
return HttpResponse('Fail', status=500)
|
|
|
|
|
|
nowTime = int(time.time())
|
|
|
- if not billing_agreement_id:
|
|
|
+ if not agreement_id:
|
|
|
# 记录钩子日志
|
|
|
PaypalWebHookEvent.objects.create(**PaypalWebHookEventInsert)
|
|
|
|
|
@@ -416,21 +416,55 @@ class PaypalCycleNotify(View):
|
|
|
paymentID = paypal_body.get('parent_payment')
|
|
|
if paymentID and paypal_transaction_id:
|
|
|
# 查询客户地区信息,地区跟服务器配置不匹配,返回500
|
|
|
- order_qs = Order_Model.objects.filter(paymentID=paymentID).values('UID', 'userID__region_country')
|
|
|
+ order_qs = Order_Model.objects.filter(paymentID=paymentID).values('UID', 'userID__region_country',
|
|
|
+ 'create_vod', 'orderID',
|
|
|
+ 'channel', 'rank__is_ai',
|
|
|
+ 'rank__expire',
|
|
|
+ 'rank__bucket__id',
|
|
|
+ 'isSelectDiscounts',
|
|
|
+ 'userID__username',
|
|
|
+ 'userID__userID', 'coupon_id')
|
|
|
if not order_qs.exists():
|
|
|
PAY_LOGGER.info('PayPal周期扣款失败---根据paymentID查询订单数据不存在')
|
|
|
return HttpResponse('Fail', status=500)
|
|
|
|
|
|
- # 更新PayPal交易号
|
|
|
- order_qs.update(trade_no=paypal_transaction_id)
|
|
|
-
|
|
|
# 判断用户地区是否跟服务器地区匹配
|
|
|
uid = order_qs[0]['UID']
|
|
|
country_id = order_qs[0]['userID__region_country']
|
|
|
if not self.config_match_region(uid, country_id):
|
|
|
return HttpResponse('Fail', status=500)
|
|
|
|
|
|
- order_qs.update(status=1, updTime=nowTime)
|
|
|
+ if order_qs[0]['create_vod']:
|
|
|
+ order_qs.update(status=1, trade_no=paypal_transaction_id, updTime=nowTime)
|
|
|
+ else:
|
|
|
+ # 是否有促销
|
|
|
+ expire = order_qs[0]['rank__expire']
|
|
|
+ isSelectDiscounts = order_qs[0]['isSelectDiscounts']
|
|
|
+ is_ai = order_qs[0]['rank__is_ai']
|
|
|
+ channel = order_qs[0]['channel']
|
|
|
+ bucketId = order_qs[0]['rank__bucket__id']
|
|
|
+ userid = order_qs[0]['userID__userID']
|
|
|
+ username = order_qs[0]['userID__username']
|
|
|
+ order_id = order_qs[0]['orderID']
|
|
|
+ coupon_id = order_qs[0]['coupon_id']
|
|
|
+ promotion = PromotionRuleModel.objects.filter(status=1, startTime__lte=nowTime,
|
|
|
+ endTime__gte=nowTime).values('id', 'ruleConfig')
|
|
|
+ if promotion.exists():
|
|
|
+ promotion_rule_id = promotion[0]['id']
|
|
|
+ expire = expire * 2
|
|
|
+ else:
|
|
|
+ promotion_rule_id = ''
|
|
|
+ if isSelectDiscounts:
|
|
|
+ expire = expire * 2
|
|
|
+ uid_bucket_id = self.create_vod(uid, expire, is_ai, nowTime, channel, bucketId, order_id,
|
|
|
+ userid, username)
|
|
|
+ order_qs.update(status=1, trade_no=paypal_transaction_id, updTime=nowTime,
|
|
|
+ uid_bucket_id=uid_bucket_id, create_vod=1,
|
|
|
+ promotion_rule_id=promotion_rule_id, agreement_id=agreement_id)
|
|
|
+ # 核销coupon
|
|
|
+ if coupon_id:
|
|
|
+ CouponModel.objects.filter(id=coupon_id).update(use_status=2, update_time=nowTime)
|
|
|
+
|
|
|
PAY_LOGGER.info('PayPal周期扣款成功---更新交易id:{}'.format(paypal_transaction_id))
|
|
|
return HttpResponse('success')
|
|
|
else:
|
|
@@ -438,7 +472,6 @@ class PaypalCycleNotify(View):
|
|
|
format(paymentID, paypal_transaction_id))
|
|
|
return HttpResponse('fail', status=500)
|
|
|
|
|
|
- agreement_id = paypal_body.get('billing_agreement_id')
|
|
|
billing_agreement = paypalrestsdk.BillingAgreement.find(agreement_id)
|
|
|
PAY_LOGGER.info('billing_agreement:{}'.format(billing_agreement))
|
|
|
|