Эх сурвалжийг харах

修改更新PayPal交易号位置

locky 1 жил өмнө
parent
commit
92dafd90b7
1 өөрчлөгдсөн 10 нэмэгдсэн , 23 устгасан
  1. 10 23
      Controller/PaymentCycle.py

+ 10 - 23
Controller/PaymentCycle.py

@@ -307,25 +307,6 @@ class PaypalCycleNotify(View):
                 red_url = "{SERVER_DOMAIN_SSL}web/paid2/en_fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
             return HttpResponseRedirect(red_url)
 
-    @staticmethod
-    def paypal_webhook_log(**params):
-        """
-        webhook日志存库
-        @param params:
-        @return:
-        """
-        logger = logging.getLogger('pay')
-        try:
-            params['agreement_desc'] = 'webhook'
-            PaypalWebHookEvent.objects.create(**params)
-            logger.info('《Webhook日志存库Success......》')
-            return True
-        except Exception as e:
-            logger.info(e.args)
-            ex = traceback.format_exc()
-            logger.info(ex)
-            return True
-
     def do_paypal_webhook_notify(self, request_dict, request, response):
         PAY_LOGGER.info('--------进入周期扣款钩子--------')
         if not request.body:
@@ -349,6 +330,7 @@ class PaypalCycleNotify(View):
             billing_agreement_id = paypal_body.get('billing_agreement_id')
             paypal_transaction_id = paypal_body.get('id')
             amount = paypal_body.get('amount')
+
             PaypalWebHookEventInsert = {
                 'webhook_event_id': json_obj.get('id'),
                 'resource_type': json_obj.get('resource_type'),
@@ -358,7 +340,7 @@ class PaypalCycleNotify(View):
                 'resource': json_agreement_str,
                 'created_time': int(time.time()),
             }
-            self.paypal_webhook_log(**PaypalWebHookEventInsert)
+
             if event_type != 'PAYMENT.SALE.COMPLETED':
                 PAY_LOGGER.info('----event_type异常:{}----'.format(event_type))
 
@@ -389,13 +371,16 @@ class PaypalCycleNotify(View):
                         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, trade_no=paypal_transaction_id)
+                    order_qs.update(status=1, updTime=nowTime)
                     PAY_LOGGER.info('PayPal周期扣款成功---更新交易id:{}'.format(paypal_transaction_id))
                     return HttpResponse('success')
                 else:
@@ -426,6 +411,9 @@ class PaypalCycleNotify(View):
                 PAY_LOGGER.info('PayPal周期扣款失败---根据order_id查询订单数据不存在')
                 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']
@@ -435,8 +423,7 @@ class PaypalCycleNotify(View):
             UID = order_qs[0]['UID']
             # PayPal周期扣款首次扣款
             if billing_agreement.agreement_details.cycles_completed == '0':
-                # 更新order表,paypal的商家交易号
-                order_qs.update(status=1, updTime=nowTime, trade_no=paypal_transaction_id)
+                order_qs.update(status=1, updTime=nowTime)
                 PAY_LOGGER.info('{} PayPal周期扣款首次扣款成功'.format(UID))
                 return HttpResponse('success')