|
@@ -5,7 +5,6 @@ from Service.CommonService import CommonService
|
|
|
from django.http import JsonResponse, HttpResponseRedirect, HttpResponse
|
|
|
import requests
|
|
|
import time
|
|
|
-import datetime as date_time
|
|
|
import sys
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
@@ -20,7 +19,7 @@ from paypalrestsdk.notifications import WebhookEvent
|
|
|
import logging
|
|
|
import json
|
|
|
from paypalrestsdk import BillingPlan
|
|
|
-
|
|
|
+import datetime as date_time
|
|
|
|
|
|
# 周期扣款相关
|
|
|
class Paypal:
|
|
@@ -178,25 +177,6 @@ class PaypalCycleNotify(View):
|
|
|
logger.info('----订阅详情----')
|
|
|
logger.info(billing_agreement_response)
|
|
|
agreement_id = billing_agreement_response.id
|
|
|
- # 列出订阅的事务 https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_transactions
|
|
|
- try:
|
|
|
- billing_agreement = paypalrestsdk.BillingAgreement.find(agreement_id)
|
|
|
- today = date_time.date.today()
|
|
|
- oneday = date_time.timedelta(days=1)
|
|
|
- yesterday = today - oneday
|
|
|
- start_date = yesterday.strftime('%Y-%m-%d')
|
|
|
- end_date = today.strftime('%Y-%m-%d')
|
|
|
- transactions = billing_agreement.search_transactions(start_date, end_date)
|
|
|
- if transactions.agreement_transaction_list:
|
|
|
- for item in transactions.agreement_transaction_list:
|
|
|
- logger.info('--->首次订阅扣款事务:{}'.format(item))
|
|
|
- except Exception as e:
|
|
|
- logger.info('出错了~查询订阅的事务异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
- red_url = "{SERVER_DOMAIN_SSL}web/paid2/fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
- if lang != 'cn':
|
|
|
- red_url = "{SERVER_DOMAIN_SSL}web/paid2/en_fail.html".format(SERVER_DOMAIN_SSL=SERVER_DOMAIN_SSL)
|
|
|
- return HttpResponseRedirect(red_url)
|
|
|
-
|
|
|
order_qs = Order_Model.objects.filter(orderID=orderID, status=0)
|
|
|
order_list = order_qs.values("UID", "channel", "commodity_code", "rank", "isSelectDiscounts",
|
|
|
"userID__userID",
|
|
@@ -348,10 +328,9 @@ class PaypalCycleNotify(View):
|
|
|
billing_agreement_id = paypal_body.get('billing_agreement_id')
|
|
|
paypal_transaction_id = paypal_body.get('id')
|
|
|
amount = paypal_body.get('amount')
|
|
|
-
|
|
|
if event_type != 'PAYMENT.SALE.COMPLETED':
|
|
|
logger.info('----钩子异常----')
|
|
|
- logger.info('--->webhook回调参数:{}'.format(paypal_body))
|
|
|
+ self.find_subscription_transactions(billing_agreement_id)
|
|
|
# self.get_plan_desc('P-4CG284532S612303METMEINY')
|
|
|
if resource_type == 'sale' and paypal_body.get('state') == 'completed':
|
|
|
paypalrestsdk.configure(PAYPAL_CRD)
|
|
@@ -550,6 +529,30 @@ class PaypalCycleNotify(View):
|
|
|
logger.info(repr(e))
|
|
|
return HttpResponse('fail', status=500)
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def find_subscription_transactions(billing_agreement_id):
|
|
|
+ """
|
|
|
+ 列出当前订阅扣款事务
|
|
|
+ @param billing_agreement_id: 协议id
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ if not billing_agreement_id:
|
|
|
+ return False
|
|
|
+ logger = logging.getLogger('pay')
|
|
|
+ try:
|
|
|
+ paypalrestsdk.configure(PAYPAL_CRD)
|
|
|
+ billing_agreement = paypalrestsdk.BillingAgreement.find(billing_agreement_id)
|
|
|
+ today = date_time.date.today()
|
|
|
+ oneday = date_time.timedelta(days=1)
|
|
|
+ yesterday = today - oneday
|
|
|
+ start_date = yesterday.strftime('%Y-%m-%d')
|
|
|
+ end_date = today.strftime('%Y-%m-%d')
|
|
|
+ transactions = billing_agreement.search_transactions(start_date, end_date)
|
|
|
+ logger.info('--->列出当前扣款事务'.format(transactions))
|
|
|
+ except Exception as e:
|
|
|
+ logger.info('出错了~查询订阅的事务异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+
|
|
|
def do_subscription_break_notify(self, request_dict, request, response):
|
|
|
logger = logging.getLogger('pay')
|
|
|
logger.info('--------进入订阅失败,付款失败,暂停--------')
|