|
@@ -516,7 +516,6 @@ class PaypalCycleNotify(View):
|
|
|
event_type = json_obj.get('event_type')
|
|
|
summary = json_obj.get('summary')
|
|
|
resource_type = json_obj.get('resource_type')
|
|
|
- billing_agreement_id = paypal_body.get('id')
|
|
|
paypal_transaction_id = paypal_body.get('id')
|
|
|
amount = paypal_body.get('amount')
|
|
|
|
|
@@ -530,17 +529,24 @@ class PaypalCycleNotify(View):
|
|
|
if not response:
|
|
|
return HttpResponse('Fail', status=500)
|
|
|
event_type_code = 0
|
|
|
+ billing_agreement_id = ''
|
|
|
if event_type == 'PAYMENT.SALE.COMPLETED':
|
|
|
event_type_code = 1
|
|
|
+ billing_agreement_id = paypal_body.get('billing_agreement_id')
|
|
|
elif event_type == 'PAYMENT.SALE.REVERSED':
|
|
|
+ billing_agreement_id = paypal_body.get('billing_agreement_id')
|
|
|
event_type_code = 2
|
|
|
elif event_type == 'BILLING.SUBSCRIPTION.CANCELLED':
|
|
|
+ billing_agreement_id = paypal_body.get('id')
|
|
|
event_type_code = 3
|
|
|
elif event_type == 'BILLING.SUBSCRIPTION.SUSPENDED':
|
|
|
+ billing_agreement_id = paypal_body.get('id')
|
|
|
event_type_code = 4
|
|
|
elif event_type == 'BILLING.SUBSCRIPTION.PAYMENT.FAILED':
|
|
|
+ billing_agreement_id = paypal_body.get('id')
|
|
|
event_type_code = 5
|
|
|
elif event_type == 'PAYMENT.SALE.REFUNDED':
|
|
|
+ billing_agreement_id = paypal_body.get('billing_agreement_id')
|
|
|
event_type_code = 6
|
|
|
|
|
|
PaypalWebHookEventInsert = {
|
|
@@ -557,11 +563,10 @@ class PaypalCycleNotify(View):
|
|
|
PaypalWebHookEvent.objects.create(**PaypalWebHookEventInsert)
|
|
|
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_id'] = agreement_id
|
|
|
+ PaypalWebHookEventInsert['agreement_id'] = billing_agreement_id
|
|
|
PaypalWebHookEventInsert['orderID'] = billing_agreement.description
|
|
|
PaypalWebHookEvent.objects.create(**PaypalWebHookEventInsert)
|
|
|
return HttpResponse('success')
|