Browse Source

优化PayPal判断用户地区是否跟服务器地区匹配函数

locky 2 năm trước cách đây
mục cha
commit
5c4bf9146a
1 tập tin đã thay đổi với 20 bổ sung4 xóa
  1. 20 4
      Controller/PaymentCycle.py

+ 20 - 4
Controller/PaymentCycle.py

@@ -384,13 +384,15 @@ class PaypalCycleNotify(View):
                 paymentID = paypal_body.get('parent_payment')
                 paymentID = paypal_body.get('parent_payment')
                 if paymentID and paypal_transaction_id:
                 if paymentID and paypal_transaction_id:
                     # 查询客户地区信息,地区跟服务器配置不匹配,返回500
                     # 查询客户地区信息,地区跟服务器配置不匹配,返回500
-                    order_qs = Order_Model.objects.filter(paymentID=paymentID).values('userID__region_country')
+                    order_qs = Order_Model.objects.filter(paymentID=paymentID).values('UID', 'userID__region_country')
                     if not order_qs.exists():
                     if not order_qs.exists():
                         PAY_LOGGER.info('PayPal周期扣款失败---根据paymentID查询订单数据不存在')
                         PAY_LOGGER.info('PayPal周期扣款失败---根据paymentID查询订单数据不存在')
                         return HttpResponse('Fail', status=500)
                         return HttpResponse('Fail', status=500)
 
 
+                    # 判断用户地区是否跟服务器地区匹配
+                    uid = order_qs[0]['UID']
                     country_id = order_qs[0]['userID__region_country']
                     country_id = order_qs[0]['userID__region_country']
-                    if not self.config_match_region(country_id):
+                    if not self.config_match_region(uid, country_id):
                         return HttpResponse('Fail', status=500)
                         return HttpResponse('Fail', status=500)
 
 
                     order_qs.update(status=1, updTime=nowTime, trade_no=paypal_transaction_id)
                     order_qs.update(status=1, updTime=nowTime, trade_no=paypal_transaction_id)
@@ -424,8 +426,10 @@ class PaypalCycleNotify(View):
                 PAY_LOGGER.info('PayPal周期扣款失败---根据order_id查询订单数据不存在')
                 PAY_LOGGER.info('PayPal周期扣款失败---根据order_id查询订单数据不存在')
                 return HttpResponse('fail', status=500)
                 return HttpResponse('fail', status=500)
 
 
+            # 判断用户地区是否跟服务器地区匹配
+            uid = order_qs[0]['UID']
             country_id = order_qs[0]['userID__region_country']
             country_id = order_qs[0]['userID__region_country']
-            if not self.config_match_region(country_id):
+            if not self.config_match_region(uid, country_id):
                 return HttpResponse('Fail', status=500)
                 return HttpResponse('Fail', status=500)
 
 
             UID = order_qs[0]['UID']
             UID = order_qs[0]['UID']
@@ -542,9 +546,21 @@ class PaypalCycleNotify(View):
             return HttpResponse('fail', status=500)
             return HttpResponse('fail', status=500)
 
 
     @staticmethod
     @staticmethod
-    def config_match_region(country_id):
+    def config_match_region(uid, country_id):
+        """
+        判断用户地区是否跟服务器地区匹配
+        @param uid: uid
+        @param country_id: 国家表id
+        @return: bool
+        """
         country_qs = CountryModel.objects.filter(id=country_id).values('region_id')
         country_qs = CountryModel.objects.filter(id=country_id).values('region_id')
+        # 不确定用户地区信息,默认美洲
+        if not country_qs.exists() and CONFIG_INFO == CONFIG_EUR:
+            PAY_LOGGER.info('PayPal周期扣款失败---不确定地区的用户请求欧洲服,uid:{},country_id:{}'.format(uid, country_id))
+            return False
+
         region_id = country_qs[0]['region_id']
         region_id = country_qs[0]['region_id']
+        PAY_LOGGER.info('uid{}的用户地区信息: country_id:{}, region_id:{}'.format(uid, country_id, region_id))
         if (CONFIG_INFO == CONFIG_US and region_id == 4) or (CONFIG_INFO == CONFIG_EUR and region_id != 4):
         if (CONFIG_INFO == CONFIG_US and region_id == 4) or (CONFIG_INFO == CONFIG_EUR and region_id != 4):
             PAY_LOGGER.info('PayPal周期扣款失败---服务器跟用户地区不匹配')
             PAY_LOGGER.info('PayPal周期扣款失败---服务器跟用户地区不匹配')
             return False
             return False