peng hai 10 meses
pai
achega
883fbe03c1
Modificáronse 2 ficheiros con 15 adicións e 21 borrados
  1. 4 7
      Ansjer/cn_config/config_test.py
  2. 11 14
      Controller/PaymentCycle.py

+ 4 - 7
Ansjer/cn_config/config_test.py

@@ -57,13 +57,10 @@ PAYPAL_CRD = {
               "client_secret": "EAjEU9b7bwrtk1uDgB-0e3gQ2Sa2jOKR1n2xLL38zFK3HYkARwx-F02_-5fXeakh_3aBr_QGySuiPYNh"}
 }
 
-# zosi web_hook_id
-PAYPAL_WEB_HOOK_ID = '6TS30758D98835230'
-PAYPAL_WEB_HOOK_ID_TWO = '2BH56575UJ9324151'
-
-#
-VSEES_PAYPAL_WEB_HOOK_ID = '9TG90006CD6031031'
-VSEES_PAYPAL_WEB_HOOK_ID_TWO = '4UK33415UG369440K'
+PAYPAL_WEB_HOOK_ID = {
+    'Zosi': {'paypalCycleNotify': '6TS30758D98835230', 'subscriptionBreakNotify': '2BH56575UJ9324151'},
+    'Vsees': {'paypalCycleNotify': '9TG90006CD6031031', 'subscriptionBreakNotify': '4UK33415UG369440K'},
+}
 
 # 数据库dyanamo品牌日志数据库
 USER_BRAND = 'test_user_brand'

+ 11 - 14
Controller/PaymentCycle.py

@@ -10,8 +10,8 @@ from django.db.models import Q, F
 from django.http import HttpResponseRedirect, HttpResponse
 from django.views.generic.base import View
 
-from Ansjer.config import PAYPAL_CRD, SERVER_DOMAIN_SSL, PAYPAL_WEB_HOOK_ID, PAYPAL_WEB_HOOK_ID_TWO, CONFIG_INFO, \
-    CONFIG_US, CONFIG_EUR, VSEES_PAYPAL_WEB_HOOK_ID, VSEES_PAYPAL_WEB_HOOK_ID_TWO
+from Ansjer.config import PAYPAL_CRD, SERVER_DOMAIN_SSL, PAYPAL_WEB_HOOK_ID, CONFIG_INFO, \
+    CONFIG_US, CONFIG_EUR
 from Controller import CloudStorage
 from Model.models import PayCycleConfigModel, Store_Meal, UID_Bucket, PromotionRuleModel, \
     Unused_Uid_Meal, Device_Info, CouponModel, Order_Model, PaypalWebHookEvent, CountryModel, AiService
@@ -390,10 +390,7 @@ class PaypalCycleNotify(View):
             agreement_id = paypal_body.get('billing_agreement_id')
             paypal_transaction_id = paypal_body.get('id')
             amount = paypal_body.get('amount')
-            if 'transaction_fee' in paypal_body:
-                fee = paypal_body['transaction_fee']['value']
-            else:
-                fee = 0
+            fee = paypal_body['transaction_fee']['value'] if 'transaction_fee' in paypal_body else 0
             PaypalWebHookEventInsert = {
                 'webhook_event_id': json_obj.get('id'),
                 'resource_type': json_obj.get('resource_type'),
@@ -410,14 +407,14 @@ class PaypalCycleNotify(View):
             if resource_type == 'sale' and paypal_body.get('state') == 'completed':
                 paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
                 response = paypalrestsdk.WebhookEvent.verify(
-                    transmission_id, transmission_time, PAYPAL_WEB_HOOK_ID, json_agreement_str, cert_url,
-                    transmission_sig, auth_algo)
+                    transmission_id, transmission_time, PAYPAL_WEB_HOOK_ID['Zosi']['paypalCycleNotify'],
+                    json_agreement_str, cert_url, transmission_sig, auth_algo)
                 app_type = 1
                 if not response:
                     paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
                     response = paypalrestsdk.WebhookEvent.verify(
-                        transmission_id, transmission_time, VSEES_PAYPAL_WEB_HOOK_ID, json_agreement_str, cert_url,
-                        transmission_sig, auth_algo)
+                        transmission_id, transmission_time, PAYPAL_WEB_HOOK_ID['Vsees']['paypalCycleNotify'],
+                        json_agreement_str, cert_url, transmission_sig, auth_algo)
                     if not response:
                         PAY_LOGGER.info('PayPal周期扣款失败---签名验证失败')
                         return HttpResponse('Fail', status=500)
@@ -722,15 +719,15 @@ class PaypalCycleNotify(View):
             # self.get_plan_desc('P-4CG284532S612303METMEINY')
             paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
             response = paypalrestsdk.WebhookEvent.verify(
-                transmission_id, transmission_time, PAYPAL_WEB_HOOK_ID_TWO, json_agreement_str, cert_url,
-                transmission_sig, auth_algo)
+                transmission_id, transmission_time, PAYPAL_WEB_HOOK_ID['Zosi']['subscriptionBreakNotify'],
+                json_agreement_str, cert_url, transmission_sig, auth_algo)
             logger.info('----验证签名----')
             logger.info(response)
             if not response:
                 paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
                 response = paypalrestsdk.WebhookEvent.verify(
-                    transmission_id, transmission_time, VSEES_PAYPAL_WEB_HOOK_ID_TWO, json_agreement_str, cert_url,
-                    transmission_sig, auth_algo)
+                    transmission_id, transmission_time, PAYPAL_WEB_HOOK_ID['Vsees']['subscriptionBreakNotify'],
+                    json_agreement_str, cert_url, transmission_sig, auth_algo)
                 logger.info('----验证签名----')
                 logger.info(response)
                 if not response: