Browse Source

webhook请求参数存库

zhangdongming 2 years ago
parent
commit
6442851cf5
1 changed files with 22 additions and 0 deletions
  1. 22 0
      Controller/PaymentCycle.py

+ 22 - 0
Controller/PaymentCycle.py

@@ -1,3 +1,5 @@
+import traceback
+
 from Ansjer.config import PAYPAL_CRD, SERVER_DOMAIN, SERVER_DOMAIN_SSL, PAYPAL_WEB_HOOK_ID, PAYPAL_WEB_HOOK_ID_TWO
 from Model.models import PayCycleConfigModel, Order_Model, Store_Meal, UID_Bucket, PromotionRuleModel, \
     Unused_Uid_Meal, Device_Info, CouponModel, Order_Model, PaypalWebHookEvent
@@ -306,6 +308,25 @@ 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):
         logger = logging.getLogger('pay')
         logger.info('--------进入周期扣款钩子--------')
@@ -338,6 +359,7 @@ class PaypalCycleNotify(View):
                 'resource': json_agreement_str,
                 'created_time': int(time.time()),
             }
+            self.paypal_webhook_log(**PaypalWebHookEventInsert)
             if event_type != 'PAYMENT.SALE.COMPLETED':
                 logger.info('----钩子异常----')
             self.find_subscription_transactions(billing_agreement_id)