Bladeren bron

修复订阅失败钩子

lang 3 jaren geleden
bovenliggende
commit
f83f324d9e
1 gewijzigde bestanden met toevoegingen van 9 en 4 verwijderingen
  1. 9 4
      Controller/PaymentCycle.py

+ 9 - 4
Controller/PaymentCycle.py

@@ -516,7 +516,6 @@ class PaypalCycleNotify(View):
             event_type = json_obj.get('event_type')
             event_type = json_obj.get('event_type')
             summary = json_obj.get('summary')
             summary = json_obj.get('summary')
             resource_type = json_obj.get('resource_type')
             resource_type = json_obj.get('resource_type')
-            billing_agreement_id = paypal_body.get('id')
             paypal_transaction_id = paypal_body.get('id')
             paypal_transaction_id = paypal_body.get('id')
             amount = paypal_body.get('amount')
             amount = paypal_body.get('amount')
 
 
@@ -530,17 +529,24 @@ class PaypalCycleNotify(View):
             if not response:
             if not response:
                 return HttpResponse('Fail', status=500)
                 return HttpResponse('Fail', status=500)
             event_type_code = 0
             event_type_code = 0
+            billing_agreement_id = ''
             if event_type == 'PAYMENT.SALE.COMPLETED':
             if event_type == 'PAYMENT.SALE.COMPLETED':
                 event_type_code = 1
                 event_type_code = 1
+                billing_agreement_id = paypal_body.get('billing_agreement_id')
             elif event_type == 'PAYMENT.SALE.REVERSED':
             elif event_type == 'PAYMENT.SALE.REVERSED':
+                billing_agreement_id = paypal_body.get('billing_agreement_id')
                 event_type_code = 2
                 event_type_code = 2
             elif event_type == 'BILLING.SUBSCRIPTION.CANCELLED':
             elif event_type == 'BILLING.SUBSCRIPTION.CANCELLED':
+                billing_agreement_id = paypal_body.get('id')
                 event_type_code = 3
                 event_type_code = 3
             elif event_type == 'BILLING.SUBSCRIPTION.SUSPENDED':
             elif event_type == 'BILLING.SUBSCRIPTION.SUSPENDED':
+                billing_agreement_id = paypal_body.get('id')
                 event_type_code = 4
                 event_type_code = 4
             elif event_type == 'BILLING.SUBSCRIPTION.PAYMENT.FAILED':
             elif event_type == 'BILLING.SUBSCRIPTION.PAYMENT.FAILED':
+                billing_agreement_id = paypal_body.get('id')
                 event_type_code = 5
                 event_type_code = 5
             elif event_type == 'PAYMENT.SALE.REFUNDED':
             elif event_type == 'PAYMENT.SALE.REFUNDED':
+                billing_agreement_id = paypal_body.get('billing_agreement_id')
                 event_type_code = 6
                 event_type_code = 6
 
 
             PaypalWebHookEventInsert = {
             PaypalWebHookEventInsert = {
@@ -557,11 +563,10 @@ class PaypalCycleNotify(View):
                 PaypalWebHookEvent.objects.create(**PaypalWebHookEventInsert)
                 PaypalWebHookEvent.objects.create(**PaypalWebHookEventInsert)
                 return HttpResponse('success')
                 return HttpResponse('success')
 
 
-            agreement_id = paypal_body.get('billing_agreement_id')
-            billing_agreement = paypalrestsdk.BillingAgreement.find(agreement_id)
+            billing_agreement = paypalrestsdk.BillingAgreement.find(billing_agreement_id)
             # 记录钩子日志
             # 记录钩子日志
             PaypalWebHookEventInsert['agreement_desc'] = repr(billing_agreement)
             PaypalWebHookEventInsert['agreement_desc'] = repr(billing_agreement)
-            PaypalWebHookEventInsert['agreement_id'] = agreement_id
+            PaypalWebHookEventInsert['agreement_id'] = billing_agreement_id
             PaypalWebHookEventInsert['orderID'] = billing_agreement.description
             PaypalWebHookEventInsert['orderID'] = billing_agreement.description
             PaypalWebHookEvent.objects.create(**PaypalWebHookEventInsert)
             PaypalWebHookEvent.objects.create(**PaypalWebHookEventInsert)
             return HttpResponse('success')
             return HttpResponse('success')