first attempt at process_webhook
This commit is contained in:
@@ -13,6 +13,8 @@ queue = django_rq.get_queue('default')
|
||||
queuelow = django_rq.get_queue('low')
|
||||
queuehigh = django_rq.get_queue('low')
|
||||
|
||||
from braintree.exceptions.invalid_signature_error import InvalidSignatureError
|
||||
|
||||
from rowers.utils import myqueue
|
||||
from rowers.tasks import (
|
||||
handle_send_email_transaction,
|
||||
@@ -52,17 +54,37 @@ else:
|
||||
from rowers.models import Rower,PaidPlan, CoachingGroup
|
||||
from rowers.utils import ProcessorCustomerError
|
||||
|
||||
def process_webhook(notification):
|
||||
if notification.kind == 'subscription_charged_successfully':
|
||||
subscription_id = notification.subscription.id
|
||||
rs = Rower.objects.filter(subscription_id=subscription_id)
|
||||
if rs.count == 0:
|
||||
return 0
|
||||
else:
|
||||
r = rs[0]
|
||||
fakturoid_contact_id = fakturoid.get_contacts(r)
|
||||
if not fakturoid_contact_id:
|
||||
fakturoid_contact_id = fakturoid.create_contact(rower)
|
||||
transactions = result.subscription.transactions
|
||||
if transactions:
|
||||
amount = transactions[0].amount
|
||||
fakturoid.create_invoice(r,amount)
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
def webhook(request):
|
||||
try:
|
||||
webhook_notification = gateway.webhook_notification.parse(
|
||||
str(request.POST['bt_signature']),
|
||||
request.POST['bt_payload'])
|
||||
except:
|
||||
print(sys.exc_info())
|
||||
except InvalidSignatureError:
|
||||
return 4
|
||||
|
||||
# Example values for webhook notification properties
|
||||
print(webhook_notification.kind) # "subscription_went_past_due"
|
||||
print(webhook_notification.timestamp) # "Sun Jan 1 00:00:00 UTC 2012"
|
||||
result = process_webhook(webhook_notification)
|
||||
|
||||
|
||||
return result
|
||||
|
||||
def create_customer(rower,force=False):
|
||||
if not rower.customer_id or force:
|
||||
|
||||
Reference in New Issue
Block a user