|
@@ -1,25 +1,21 @@
|
|
|
-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
|
|
|
-from Service.CommonService import CommonService
|
|
|
-from django.http import JsonResponse, HttpResponseRedirect, HttpResponse
|
|
|
-import requests
|
|
|
+import datetime as date_time
|
|
|
+import json
|
|
|
+import logging
|
|
|
import time
|
|
|
-import sys
|
|
|
-from Object.TokenObject import TokenObject
|
|
|
-from Object.UidTokenObject import UidTokenObject
|
|
|
-from Object.ResponseObject import ResponseObject
|
|
|
+
|
|
|
import paypalrestsdk
|
|
|
-from paypalrestsdk import BillingAgreement
|
|
|
-from django.views.generic.base import View
|
|
|
from django.db import transaction
|
|
|
+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
|
|
|
from Controller import CloudStorage
|
|
|
-from django.db.models import Q, F, Count
|
|
|
-from paypalrestsdk.notifications import WebhookEvent
|
|
|
-import logging
|
|
|
-import json
|
|
|
-from paypalrestsdk import BillingPlan
|
|
|
-import datetime as date_time
|
|
|
+from Model.models import PayCycleConfigModel, Store_Meal, UID_Bucket, PromotionRuleModel, \
|
|
|
+ Unused_Uid_Meal, Device_Info, CouponModel, Order_Model, PaypalWebHookEvent
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+from Service.CommonService import CommonService
|
|
|
|
|
|
|
|
|
# 周期扣款相关
|
|
@@ -307,10 +303,14 @@ class PaypalCycleNotify(View):
|
|
|
return HttpResponseRedirect(red_url)
|
|
|
|
|
|
@staticmethod
|
|
|
- def paypal_webhook_log(sub_id, **params):
|
|
|
- params['agreement_id'] = sub_id
|
|
|
- params['agreement_desc'] = 'webhook'
|
|
|
- PaypalWebHookEvent.objects.create(**params)
|
|
|
+ def paypal_webhook_log(**params):
|
|
|
+ try:
|
|
|
+ params['agreement_desc'] = 'webhook'
|
|
|
+ PaypalWebHookEvent.objects.create(**params)
|
|
|
+ return True
|
|
|
+ except Exception as e:
|
|
|
+ print(repr(e))
|
|
|
+ return True
|
|
|
|
|
|
def do_paypal_webhook_notify(self, request_dict, request, response):
|
|
|
logger = logging.getLogger('pay')
|
|
@@ -344,7 +344,7 @@ class PaypalCycleNotify(View):
|
|
|
'resource': json_agreement_str,
|
|
|
'created_time': int(time.time()),
|
|
|
}
|
|
|
- self.paypal_webhook_log(billing_agreement_id, **PaypalWebHookEventInsert)
|
|
|
+ self.paypal_webhook_log(**PaypalWebHookEventInsert)
|
|
|
if event_type != 'PAYMENT.SALE.COMPLETED':
|
|
|
logger.info('----钩子异常----')
|
|
|
self.find_subscription_transactions(billing_agreement_id)
|