1
0

2 Incheckningar 6154343b71 ... 29734879fe

Upphovsman SHA1 Meddelande Datum
  peng 29734879fe vsees购买云存 8 månader sedan
  locky a787142e10 还原欧洲业务数据库配置 8 månader sedan

+ 6 - 2
AdminController/ServeManagementController.py

@@ -31,6 +31,7 @@ from Object.AppleInAppPurchaseSubscriptionObject import InAppPurchase
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.UnicomObject import UnicomObjeect
+from Object.utils.PayPalUtil import PayPalService
 from Service.CommonService import CommonService
 
 LOGGER = logging.getLogger('info')
@@ -152,10 +153,13 @@ class serveManagement(View):
         if not order_id:
             return response.json(444)
         order_qs = Order_Model.objects.filter(orderID=order_id)
-        order_qs = order_qs.filter(~Q(agreement_id='')).values("agreement_id")
+        order_qs = order_qs.filter(~Q(agreement_id='')).values("agreement_id", "app_type")
         if not order_qs.exists():
             return response.json(800)
-        paypalrestsdk.configure(PAYPAL_CRD)
+        if order_qs[0]['app_type'] == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif order_qs[0]['app_type'] == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         agreement_id = order_qs[0]['agreement_id']
         try:
             now_time = int(time.time())

+ 11 - 5
Ansjer/cn_config/config_formal.py

@@ -41,12 +41,18 @@ TUTK_PUSH_DOMAIN = 'http://push.iotcplatform.com/tpns'
 
 # PayPal
 PAYPAL_CRD = {
-    "mode": "sandbox",  # sandbox or live
-    "client_id": "AVLoQVq3xHZ6FrF4mxHwlCPgVBAw4Fw5RtMkuxmYd23SkUTIY643n2g3KdK-Al8wV05I28lza5uoQbAA",
-    "client_secret": "EO8kRc8yioDk0i2Qq-QMcVFfwkmyMJorTvBSLDTnxDJJ_wb9VoM_0jkUY9iEng2Flp1ze8wQOGpH5nB2"
+    "Zosi": {"mode": "sandbox",  # sandbox or live
+             "client_id": "AVLoQVq3xHZ6FrF4mxHwlCPgVBAw4Fw5RtMkuxmYd23SkUTIY643n2g3KdK-Al8wV05I28lza5uoQbAA",
+             "client_secret": "EO8kRc8yioDk0i2Qq-QMcVFfwkmyMJorTvBSLDTnxDJJ_wb9VoM_0jkUY9iEng2Flp1ze8wQOGpH5nB2"},
+    "Vsees": {"mode": "sandbox",  # sandbox or live
+              "client_id": "ARZJizedZhRXVxeKQNGdUDNHY1krCJm1cZaFb-pHoHkMP04iRCLCSTVR4p49ytVjwpfHXM9nZoo1N2_-",
+              "client_secret": "EAjEU9b7bwrtk1uDgB-0e3gQ2Sa2jOKR1n2xLL38zFK3HYkARwx-F02_-5fXeakh_3aBr_QGySuiPYNh"}
+}
+
+PAYPAL_WEB_HOOK_ID = {
+    'Zosi': {'paypalCycleNotify': '6TS30758D98835230', 'subscriptionBreakNotify': '2BH56575UJ9324151'},
+    'Vsees': {'paypalCycleNotify': '9TG90006CD6031031', 'subscriptionBreakNotify': '4UK33415UG369440K'},
 }
-PAYPAL_WEB_HOOK_ID = '6TS30758D98835230'
-PAYPAL_WEB_HOOK_ID_TWO = '2BH56575UJ9324151'
 
 # 数据库dyanamo品牌日志数据库
 USER_BRAND = 'user_brand'

+ 11 - 5
Ansjer/cn_config/config_test.py

@@ -50,12 +50,18 @@ OAUTH_REFRESH_TOKEN_SECRET = 'test_r+jbgnw%@1%zy^=@dn62%'
 
 # PayPal
 PAYPAL_CRD = {
-    "mode": "sandbox",  # sandbox or live
-    "client_id": "AVLoQVq3xHZ6FrF4mxHwlCPgVBAw4Fw5RtMkuxmYd23SkUTIY643n2g3KdK-Al8wV05I28lza5uoQbAA",
-    "client_secret": "EO8kRc8yioDk0i2Qq-QMcVFfwkmyMJorTvBSLDTnxDJJ_wb9VoM_0jkUY9iEng2Flp1ze8wQOGpH5nB2"
+    "Zosi": {"mode": "sandbox",  # sandbox or live
+             "client_id": "AVLoQVq3xHZ6FrF4mxHwlCPgVBAw4Fw5RtMkuxmYd23SkUTIY643n2g3KdK-Al8wV05I28lza5uoQbAA",
+             "client_secret": "EO8kRc8yioDk0i2Qq-QMcVFfwkmyMJorTvBSLDTnxDJJ_wb9VoM_0jkUY9iEng2Flp1ze8wQOGpH5nB2"},
+    "Vsees": {"mode": "sandbox",  # sandbox or live
+              "client_id": "ARZJizedZhRXVxeKQNGdUDNHY1krCJm1cZaFb-pHoHkMP04iRCLCSTVR4p49ytVjwpfHXM9nZoo1N2_-",
+              "client_secret": "EAjEU9b7bwrtk1uDgB-0e3gQ2Sa2jOKR1n2xLL38zFK3HYkARwx-F02_-5fXeakh_3aBr_QGySuiPYNh"}
+}
+
+PAYPAL_WEB_HOOK_ID = {
+    'Zosi': {'paypalCycleNotify': '6TS30758D98835230', 'subscriptionBreakNotify': '2BH56575UJ9324151'},
+    'Vsees': {'paypalCycleNotify': '9TG90006CD6031031', 'subscriptionBreakNotify': '4UK33415UG369440K'},
 }
-PAYPAL_WEB_HOOK_ID = '6TS30758D98835230'
-PAYPAL_WEB_HOOK_ID_TWO = '2BH56575UJ9324151'
 
 # 数据库dyanamo品牌日志数据库
 USER_BRAND = 'test_user_brand'

+ 11 - 5
Ansjer/eur_config/config_formal.py

@@ -41,12 +41,18 @@ TUTK_PUSH_DOMAIN = 'http://push.iotcplatform.com/tpns'
 
 # PayPal
 PAYPAL_CRD = {
-    "mode": "live",  # sandbox or live
-    "client_id": "AdSRd6WBn-qLl9OiQHQuNYTDFSx0ZX0RUttqa58au8bPzoGYQUrt8bc6591RmH8_pEAIPijdvVYSVXyI",
-    "client_secret": "ENT-J08N3Fw0B0uAokg4RukljAwO9hFHPf8whE6-Dwd8oBWJO8AWMgpdTKpfB1pOy89t4bsFEzMWDowm"
+    "Zosi": {"mode": "live",  # sandbox or live
+             "client_id": "AdSRd6WBn-qLl9OiQHQuNYTDFSx0ZX0RUttqa58au8bPzoGYQUrt8bc6591RmH8_pEAIPijdvVYSVXyI",
+             "client_secret": "ENT-J08N3Fw0B0uAokg4RukljAwO9hFHPf8whE6-Dwd8oBWJO8AWMgpdTKpfB1pOy89t4bsFEzMWDowm"},
+    "Vsees": {"mode": "live",  # sandbox or live
+              "client_id": "AYjKR4XQ4sNBvOPjLXkfxb_WKBCX79N0pUgA9DyKw2hOPx_B3lZ60gaelK1Fmh_zny7XfWrD4U0sxBW_",
+              "client_secret": "EEN5x9VMRcAbDTW2afGqaG2BXigQUliJG4st2Q73vuj0Uq76ciTW5XyOHnM2AWYQEKnRacxJtlJ711F6"}
+}
+
+PAYPAL_WEB_HOOK_ID = {
+    'Zosi': {'paypalCycleNotify': '3T5610747S126314V', 'subscriptionBreakNotify': '4VS84179T6193840G'},
+    'Vsees': {'paypalCycleNotify': '2K2138636P231921U', 'subscriptionBreakNotify': '93C557859T432760C'},
 }
-PAYPAL_WEB_HOOK_ID = '3T5610747S126314V'
-PAYPAL_WEB_HOOK_ID_TWO = '4VS84179T6193840G'
 
 # 数据库dyanamo品牌日志数据库
 USER_BRAND = 'user_brand'

+ 3 - 3
Ansjer/eur_config/formal_settings.py

@@ -76,9 +76,9 @@ WSGI_APPLICATION = 'Ansjer.eur_config.formal_wsgi.application'
 
 # 服务器类型
 DATABASE_DATA = 'Ansjer81'
-SERVER_HOST = '10.80.1.192'
-DATABASES_USER = 'root'
-DATABASES_PASS = '47vo87fikT19cekVoSq1..'
+SERVER_HOST = 'server-eur.chi0brrjyz8l.eu-west-1.rds.amazonaws.com'
+DATABASES_USER = 'azrds'
+DATABASES_PASS = '47vo87fikT19cekVoSq1'
 
 DATABASE_DATA2 = 'Ansjer81'
 SERVER_HOST2 = '10.80.1.216'

+ 11 - 5
Ansjer/us_config/config_formal.py

@@ -41,12 +41,18 @@ TUTK_PUSH_DOMAIN = 'http://push.iotcplatform.com/tpns'
 
 # PayPal
 PAYPAL_CRD = {
-    "mode": "live",  # sandbox or live
-    "client_id": "AdSRd6WBn-qLl9OiQHQuNYTDFSx0ZX0RUttqa58au8bPzoGYQUrt8bc6591RmH8_pEAIPijdvVYSVXyI",
-    "client_secret": "ENT-J08N3Fw0B0uAokg4RukljAwO9hFHPf8whE6-Dwd8oBWJO8AWMgpdTKpfB1pOy89t4bsFEzMWDowm"
+    "Zosi": {"mode": "live",  # sandbox or live
+             "client_id": "AdSRd6WBn-qLl9OiQHQuNYTDFSx0ZX0RUttqa58au8bPzoGYQUrt8bc6591RmH8_pEAIPijdvVYSVXyI",
+             "client_secret": "ENT-J08N3Fw0B0uAokg4RukljAwO9hFHPf8whE6-Dwd8oBWJO8AWMgpdTKpfB1pOy89t4bsFEzMWDowm"},
+    "Vsees": {"mode": "live",  # sandbox or live
+              "client_id": "AYjKR4XQ4sNBvOPjLXkfxb_WKBCX79N0pUgA9DyKw2hOPx_B3lZ60gaelK1Fmh_zny7XfWrD4U0sxBW_",
+              "client_secret": "EEN5x9VMRcAbDTW2afGqaG2BXigQUliJG4st2Q73vuj0Uq76ciTW5XyOHnM2AWYQEKnRacxJtlJ711F6"}
+}
+
+PAYPAL_WEB_HOOK_ID = {
+    'Zosi': {'paypalCycleNotify': '3YH86681TH784461T', 'subscriptionBreakNotify': '7TN87895N70389928'},
+    'Vsees': {'paypalCycleNotify': '6UG02331R33389344', 'subscriptionBreakNotify': '7AW63057F27584607'},
 }
-PAYPAL_WEB_HOOK_ID = '3YH86681TH784461T'
-PAYPAL_WEB_HOOK_ID_TWO = '7TN87895N70389928'
 
 # 数据库dyanamo品牌日志数据库
 USER_BRAND = 'user_brand'

+ 26 - 12
Controller/CloudStorage.py

@@ -975,7 +975,13 @@ class CloudStorageView(View):
                     red_url = red_url.replace('fail.html', 'en_fail.html')
                 return HttpResponseRedirect(red_url)
 
-            paypalrestsdk.configure(PAYPAL_CRD)
+            order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
+                                         "userID__userID", "userID__username", "coupon_id", "app_type")
+            app_type = order_list[0]['app_type']
+            if app_type == 1:
+                paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+            elif app_type == 2:
+                paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
             payment = paypalrestsdk.Payment.find(payment_id)
 
             logger.info("payment------")
@@ -989,9 +995,6 @@ class CloudStorageView(View):
                     red_url = red_url.replace('fail.html', 'en_fail.html')
                 redis_obj.del_data(key=order_id + 'do_notify')
                 return HttpResponseRedirect(red_url)
-
-            order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
-                                         "userID__userID", "userID__username", "coupon_id")
             userid = order_list[0]['userID__userID']
             username = order_list[0]['userID__username']
             uid = order_list[0]['UID']
@@ -1248,9 +1251,11 @@ class CloudStorageView(View):
         is_select_discount = request_dict.get('is_select_discount', 0)
         coupon_id = request_dict.get('coupon_id', 0)
         lang = request_dict.get('lang', 'en')
+        app_type = request_dict.get('app_type', 1)
         if not all([uid, channel, pay_type, rank]):
             return response.json(444)
         pay_type = int(pay_type)
+        app_type = int(app_type)
         logger.info(f'uid:{uid}创建订单云存订单, 时间戳为{int(time.time())}, 支付类型为{pay_type}')
         device_info_qs = Device_Info.objects.filter(userID_id=user_id, UID=uid, isShare=False, isExist=1).values(
             'vodPrimaryUserID',
@@ -1315,10 +1320,11 @@ class CloudStorageView(View):
             # 订阅周期扣款
             if store_qs[0]['cycle_config_id']:
                 # 查询是否有订阅过,活跃状态
-                check_has_subscribe = Paypal.checkSubscriptions(user_id, uid, rank)
+                check_has_subscribe = Paypal.checkSubscriptions(user_id, uid, rank, app_type)
                 if not check_has_subscribe:
                     return response.json(10050)
-                sub_info = Paypal.subscriptions(store_info=store_qs[0], lang=lang, orderID=order_id, price=price)
+                sub_info = Paypal.subscriptions(store_info=store_qs[0], lang=lang, orderID=order_id, price=price,
+                                                app_type=app_type)
                 if not sub_info:
                     return response.json(10048)
                 Order_Model.objects.create(orderID=order_id, UID=uid, channel=channel, userID_id=user_id,
@@ -1328,7 +1334,7 @@ class CloudStorageView(View):
                                            pay_url=sub_info['url'], isSelectDiscounts=is_select_discount,
                                            commodity_code=commodity_code, commodity_type=commodity_type,
                                            rank_id=rank, plan_id=sub_info['plan_id'], coupon_id=coupon_id,
-                                           ai_rank_id=1,
+                                           ai_rank_id=1, app_type=app_type,
                                            store_meal_name=store_meal_name)
                 return response.json(0, {"redirectUrl": sub_info['url'], "orderID": order_id})
             # 正常扣款
@@ -1337,8 +1343,12 @@ class CloudStorageView(View):
                 call_clc_url = call_clc_url.replace('fail.html', 'en_fail.html')
             call_sub_url = "{}cloudstorage/dopaypalcallback?orderID={}&lang={}".format(SERVER_DOMAIN_SSL, order_id,
                                                                                        lang)
-
-            paypalrestsdk.configure(PAYPAL_CRD)
+            if app_type == 1:
+                paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+            elif app_type == 2:
+                paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
+            else:
+                return response.json(444)
             payment = paypalrestsdk.Payment({
                 "intent": "sale",
                 "payer": {"payment_method": "paypal"},
@@ -1363,7 +1373,7 @@ class CloudStorageView(View):
                                                pay_url=approval_url, isSelectDiscounts=is_select_discount,
                                                commodity_code=commodity_code, commodity_type=commodity_type,
                                                rank_id=rank, paymentID=payment_id, coupon_id=coupon_id,
-                                               ai_rank_id=1,
+                                               ai_rank_id=1, app_type=app_type,
                                                store_meal_name=store_meal_name)
                     return response.json(0, {"redirectUrl": approval_url, "orderID": order_id})
             return response.json(10, 'generate_order_false')
@@ -2138,7 +2148,7 @@ class CloudStorageView(View):
         try:
             order_qs = Order_Model.objects.filter(orderID=order_id) \
                 .values('status', 'payType', 'price', 'refunded_amount',
-                        'currency', 'paymentID', 'trade_no')
+                        'currency', 'paymentID', 'trade_no', "app_type")
             if not order_qs.exists():
                 return response.json(173)
 
@@ -2167,8 +2177,12 @@ class CloudStorageView(View):
             if pay_type == 1:  # PayPal
                 payment_id = order_qs[0]['paymentID']  # PayPal PAYMENT_ID
                 trade_no = order_qs[0]['trade_no']
+                app_type = order_qs[0]['app_type']
                 sale_id = ''
-                paypalrestsdk.configure(PAYPAL_CRD)
+                if app_type == 1:
+                    paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+                elif app_type == 2:
+                    paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
                 if payment_id:
                     payment = paypalrestsdk.Payment.find(payment_id)
                     related_resources = payment['transactions'][0]['related_resources']

+ 13 - 7
Controller/CloudVod.py

@@ -405,17 +405,21 @@ class CloudVodView(View):
         if not paymentId or not PayerID or not orderID:
             red_url = "{SERVER_DOMAIN}cloudVod/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
             return HttpResponseRedirect(red_url)
-        paypalrestsdk.configure(PAYPAL_CRD)
+        order_qs = Order_Model.objects.filter(orderID=orderID)
+        nowTime = int(time.time())
+        order_qs.update(status=1, updTime=nowTime)
+        order_list = order_qs.values("UID", "rank_id", "channel", "app_type")
+        app_type = order_list[0]['app_type']
+        if app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         # ID of the payment. This ID is provided when creating payment.
         payment = paypalrestsdk.Payment.find(paymentId)
         payres = payment.execute({"payer_id": PayerID})
         if not payres:
             red_url = "{SERVER_DOMAIN}cloudVod/payError".format(SERVER_DOMAIN=SERVER_DOMAIN)
             return HttpResponseRedirect(red_url)
-        order_qs = Order_Model.objects.filter(orderID=orderID)
-        nowTime = int(time.time())
-        order_qs.update(status=1, updTime=nowTime)
-        order_list = order_qs.values("UID", "rank_id", "channel")
         rank_id = order_list[0]['rank_id']
         UID = order_list[0]['UID']
         channel = order_list[0]['channel']
@@ -726,8 +730,10 @@ class CloudVodView(View):
         refund_amount = float(refund_amount)
         if order.price < refund_amount:
             return response.json(801)
-
-        paypalrestsdk.configure(PAYPAL_CRD)
+        if order.app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif order.app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         payment = paypalrestsdk.Payment.find(order.trade_no)
         transactions = payment['transactions']
         transaction = transactions[0]

+ 15 - 6
Controller/Cron/CronTaskController.py

@@ -1722,10 +1722,13 @@ class CronComparedDataView(View):
             start_date = datetime.datetime(start_date.year, start_date.month, start_date.day)
             end_date = start_date + datetime.timedelta(days=1)
         try:
-            paypal_api = paypalrestsdk.Api(PAYPAL_CRD)
+            zosi_paypal_api = paypalrestsdk.Api(PAYPAL_CRD['Zosi'])
+            vsees_paypal_api = paypalrestsdk.Api(PAYPAL_CRD['Vsees'])
             paypal_url = 'v1/reporting/transactions?start_date={}-{}-{}T08:00:00-0800&end_date={}-{}-{}T08:00:00-0800&fields=all&page_size=500&page=1&transaction_status=S'.format(
                 start_date.year, start_date.month, start_date.day, end_date.year, end_date.month, end_date.day)
-            order_list = paypal_api.get(paypal_url)
+            zosi_order_list = zosi_paypal_api.get(paypal_url)
+            vsees_order_list = vsees_paypal_api.get(paypal_url)
+            order_list = zosi_order_list['transaction_details'] + vsees_order_list['transaction_details']
             # data = (
             #     ('start_date', '{}-{}-{}T08:00:00-0800'.format(start_date.year, start_date.month, start_date.day)),
             #     ('end_date', '{}-{}-{}T08:00:00-0800'.format(end_date.year, end_date.month, end_date.day)),
@@ -1736,7 +1739,7 @@ class CronComparedDataView(View):
             # )
             # order_list = PayPalService(PAYPAL_CRD['client_id'], PAYPAL_CRD['client_secret']).get_transactions(data)
             thread = threading.Thread(target=CronComparedDataView.thread_compared_paypal_order,
-                                      args=(order_list['transaction_details'], end_date))
+                                      args=(order_list, end_date))
             thread.start()  # 启动线程
             return response.json(0)
         except Exception as e:
@@ -1944,7 +1947,7 @@ class CronComparedDataView(View):
                                                                                      'desc', 'payType',
                                                                                      'price', 'status',
                                                                                      'refunded_amount', 'addTime',
-                                                                                     'updTime')
+                                                                                     'updTime', 'app_type')
             if CONFIG_INFO == CONFIG_EUR:
                 return response.json(0, list(order_qs))
             thread = threading.Thread(target=CronComparedDataView.thread_compared_ansjer_order,
@@ -1975,7 +1978,8 @@ class CronComparedDataView(View):
             total = 0
             all_order_list = order_list + eur_order_list
             count = len(all_order_list)
-            paypal_api = paypalrestsdk.Api(PAYPAL_CRD)
+            zosi_paypal_api = paypalrestsdk.Api(PAYPAL_CRD['Zosi'])
+            vsees_paypal_api = paypalrestsdk.Api(PAYPAL_CRD['Vsees'])
             for index, order in enumerate(all_order_list):
                 total += float(order['price'])
                 if not order['trade_no']:
@@ -1987,7 +1991,12 @@ class CronComparedDataView(View):
                 paypal_url = 'v1/reporting/transactions?start_date={}-{}-{}T00:00:00-0000&end_date={}-{}-{}T00:00:00-0000&transaction_id={}&fields=all&page_size=100&page=1'.format(
                     begin_date.year, begin_date.month, begin_date.day, end_date.year, end_date.month, end_date.day,
                     order['trade_no'])
-                paypal_order_list = paypal_api.get(paypal_url)
+                if order['app_type'] == 1:
+                    paypal_order_list = zosi_paypal_api.get(paypal_url)
+                elif order['app_type'] == 2:
+                    paypal_order_list = vsees_paypal_api.get(paypal_url)
+                else:
+                    continue
                 if not paypal_order_list['transaction_details']:
                     more_order_list.append(order['orderID'])
             total = round(total, 2)

+ 52 - 24
Controller/PaymentCycle.py

@@ -10,7 +10,7 @@ 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, \
+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, \
@@ -25,18 +25,21 @@ PAY_LOGGER = logging.getLogger('pay')
 # 周期扣款相关
 class Paypal:
     # 检查是否有重复订阅
-    def checkSubscriptions(userID, uid, rank):
-        hasOrder = Order_Model.objects.filter(UID=uid)
+    def checkSubscriptions(userID, uid, rank, app_type):
+        hasOrder = Order_Model.objects.filter(UID=uid, app_type=app_type)
         hasOrder = hasOrder.filter(~Q(agreement_id='')).values('agreement_id', 'orderID').order_by('-addTime')[0:1]
         if not hasOrder.exists():
             return True
-        paypalrestsdk.configure(PAYPAL_CRD)
+        if app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         billing_agreement = paypalrestsdk.BillingAgreement.find(hasOrder[0]['agreement_id'])
         if billing_agreement.state == 'Active':
             return False
         return True
 
-    def subscriptions(store_info, lang, orderID, price):
+    def subscriptions(store_info, lang, orderID, price, app_type):
         logger = logging.getLogger('pay')
         cycle_config = PayCycleConfigModel.objects.filter(id=store_info['cycle_config_id']).values()
         if not cycle_config:
@@ -46,8 +49,8 @@ class Paypal:
         cal_url = "{SERVER_DOMAIN_SSL}web/paid2/fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
         if lang != 'cn':
             cal_url = "{SERVER_DOMAIN_SSL}web/paid2/en_fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
-        return_url = "{SERVER_DOMAIN_SSL}payCycle/paypalCycleReturn?lang={lang}". \
-            format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL, lang=lang)
+        return_url = "{SERVER_DOMAIN_SSL}payCycle/paypalCycleReturn?lang={lang}&app_type={app_type}". \
+            format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL, lang=lang, app_type=app_type)
         # call_sub_url = "http://binbin.uicp.vip/cloudstorage/dopaypalcallback?orderID={orderID}".format(
         # SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL, orderID=orderID)
         # exit(price)
@@ -90,7 +93,10 @@ class Paypal:
             ],
             "type": "INFINITE",
         }
-        paypalrestsdk.configure(PAYPAL_CRD)
+        if app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         billing_plan = paypalrestsdk.BillingPlan(BillingPlan)
         if billing_plan.create():
             billing_plan.activate()  # 激活
@@ -199,11 +205,15 @@ class PaypalCycleNotify(View):
     def do_paypal_cycle_return(self, request_dict, response):
         lang = request_dict.get('lang', 'en')
         token = request_dict.get('token', None)
+        app_type = int(request_dict.get('app_type', 1))
 
         logger = logging.getLogger('pay')
         logger.info('--------进入paypay首次订阅付款回调--------')
         logger.info(request_dict)
-        paypalrestsdk.configure(PAYPAL_CRD)
+        if app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         billing_agreement = paypalrestsdk.BillingAgreement()
         billing_agreement_response = billing_agreement.execute(token)
         if billing_agreement_response.error:
@@ -380,7 +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')
-            fee = paypal_body['transaction_fee']['value']
+            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'),
@@ -395,13 +405,20 @@ class PaypalCycleNotify(View):
                 PAY_LOGGER.info('----event_type异常:{}----'.format(event_type))
 
             if resource_type == 'sale' and paypal_body.get('state') == 'completed':
-                paypalrestsdk.configure(PAYPAL_CRD)
+                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:
-                    PAY_LOGGER.info('PayPal周期扣款失败---签名验证失败')
-                    return HttpResponse('Fail', status=500)
+                    paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
+                    response = paypalrestsdk.WebhookEvent.verify(
+                        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)
+                    app_type = 2
             else:
                 PAY_LOGGER.info('PayPal周期扣款失败,付款状态有误,resource_type:{},state:{}----'.
                                 format(resource_type, paypal_body.get('state')))
@@ -597,7 +614,7 @@ class PaypalCycleNotify(View):
                     store_meal_name = '未知套餐'
                 Order_Model.objects.create(orderID=orderID, UID=UID, channel=channel, userID_id=userid,
                                            desc=desc, payType=pay_type, payTime=nowTime,
-                                           price=amount.get('total'),
+                                           price=amount.get('total'), app_type=app_type,
                                            currency=order_qs[0]['currency'], addTime=nowTime,
                                            updTime=nowTime, order_type=order_type,
                                            pay_url='', isSelectDiscounts=0, fee=fee,
@@ -663,7 +680,8 @@ class PaypalCycleNotify(View):
         # 不确定用户地区信息,默认美洲
         if not country_qs.exists():
             if CONFIG_INFO == CONFIG_EUR:
-                PAY_LOGGER.info('PayPal周期扣款失败---不确定地区的用户请求欧洲服,uid:{},country_id:{}'.format(uid, country_id))
+                PAY_LOGGER.info(
+                    'PayPal周期扣款失败---不确定地区的用户请求欧洲服,uid:{},country_id:{}'.format(uid, country_id))
                 return False
             else:
                 return True
@@ -699,14 +717,21 @@ class PaypalCycleNotify(View):
             amount = paypal_body.get('amount')
 
             # self.get_plan_desc('P-4CG284532S612303METMEINY')
-            paypalrestsdk.configure(PAYPAL_CRD)
+            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:
-                return HttpResponse('Fail', status=500)
+                paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
+                response = paypalrestsdk.WebhookEvent.verify(
+                    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:
+                    return HttpResponse('Fail', status=500)
             event_type_code = 0
             billing_agreement_id = ''
             if event_type == 'PAYMENT.SALE.COMPLETED':
@@ -820,11 +845,14 @@ class payCycle(View):
     def do_cancel_pay_cycle(self, request_dict, userID, response):
         orderID = request_dict.get('orderID', 'None')
         orderObject = Order_Model.objects.filter(orderID=orderID)
-        orderObject = orderObject.filter(~Q(agreement_id='')).values("agreement_id")
+        orderObject = orderObject.filter(~Q(agreement_id='')).values("agreement_id", "app_type")
         if not orderObject.exists():
             return response.json(800)
-
-        paypalrestsdk.configure(PAYPAL_CRD)
+        app_type = orderObject[0]['app_type']
+        if app_type == 1:
+            paypalrestsdk.configure(PAYPAL_CRD['Zosi'])
+        elif app_type == 2:
+            paypalrestsdk.configure(PAYPAL_CRD['Vsees'])
         BILLING_AGREEMENT_ID = orderObject[0]['agreement_id']
         try:
             billing_agreement = paypalrestsdk.BillingAgreement.find(BILLING_AGREEMENT_ID)

+ 1 - 0
Model/models.py

@@ -1686,6 +1686,7 @@ class Store_Meal(models.Model):
     # 备用字段
     pixel_level = models.SmallIntegerField(default=0, verbose_name='像素等级')  # 0:低于4k像素;1:大于等于4k像素
     is_ai = models.SmallIntegerField(default=0, verbose_name='是否支持AI')  # 0:不支持;1:支持
+    app_type = models.SmallIntegerField(default=0, verbose_name='app类型')  # 1:ZosiSmart苹果; 2:Vsees苹果
 
     def __str__(self):
         return self.id