confirmation emails to buyers
This commit is contained in:
@@ -2,6 +2,20 @@ import braintree
|
||||
from django.utils import timezone
|
||||
import datetime
|
||||
|
||||
import django_rq
|
||||
queue = django_rq.get_queue('default')
|
||||
queuelow = django_rq.get_queue('low')
|
||||
queuehigh = django_rq.get_queue('low')
|
||||
|
||||
from rowers.utils import myqueue
|
||||
from rowers.tasks import (
|
||||
handle_send_email_transaction,
|
||||
handle_send_email_subscription_update,
|
||||
handle_send_email_subscription_create,
|
||||
handle_send_email_failed_cancel,
|
||||
)
|
||||
|
||||
|
||||
from rowsandall_app.settings import (
|
||||
BRAINTREE_MERCHANT_ID,BRAINTREE_PUBLIC_KEY,BRAINTREE_PRIVATE_KEY
|
||||
)
|
||||
@@ -68,7 +82,7 @@ def get_plans_costs():
|
||||
def make_payment(rower,data):
|
||||
nonce_from_the_client = data['payment_method_nonce']
|
||||
amount = data['amount']
|
||||
amount = str(amount)
|
||||
amount = '{amount:.f2}'.format(amount=amount)
|
||||
|
||||
result = gateway.transaction.sale({
|
||||
"amount": amount,
|
||||
@@ -80,6 +94,14 @@ def make_payment(rower,data):
|
||||
if result.is_success:
|
||||
transaction = result.transaction
|
||||
amount = transaction.amount
|
||||
name = '{f} {l}'.format(
|
||||
f = rower.user.first_name,
|
||||
l = rower.user.last_name,
|
||||
)
|
||||
|
||||
|
||||
job = myqueue(queuehigh,handle_send_email_transaction,
|
||||
name, rower.user.email, amount)
|
||||
|
||||
return amount
|
||||
else:
|
||||
@@ -91,7 +113,6 @@ def update_subscription(rower,data):
|
||||
nonce_from_the_client = data['payment_method_nonce']
|
||||
amount = data['amount']
|
||||
amount = '{amount:.2f}'.format(amount=amount)
|
||||
print amount,'aap'
|
||||
|
||||
gatewaydata = {
|
||||
"price": amount,
|
||||
@@ -122,6 +143,29 @@ def update_subscription(rower,data):
|
||||
rower.rowerplan = plan.shortname
|
||||
rower.subscription_id = result.subscription.id
|
||||
rower.save()
|
||||
name = '{f} {l}'.format(
|
||||
f = rower.user.first_name,
|
||||
l = rower.user.last_name,
|
||||
)
|
||||
|
||||
|
||||
transactions = result.subscription.transactions
|
||||
|
||||
if transactions:
|
||||
amount = transactions[0].amount
|
||||
else:
|
||||
amount = 0
|
||||
|
||||
|
||||
job = myqueue(queuehigh,
|
||||
handle_send_email_subscription_update,
|
||||
name, rower.user.email,
|
||||
plan.name,
|
||||
plan.paymenttype == 'recurring',
|
||||
plan.price,
|
||||
amount,
|
||||
result.subscription.billing_period_end_date.strftime('%Y-%m-%d'))
|
||||
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -153,13 +197,31 @@ def create_subscription(rower,data):
|
||||
|
||||
if result.is_success:
|
||||
rower.paidplan = plan
|
||||
rower.planexpires = timezone.now()+datetime.timedelta(days=365)
|
||||
rower.teamplanexpires = timezone.now()+datetime.timedelta(days=365)
|
||||
rower.planexpires = result.subscription.billing_period_end_date
|
||||
rower.teamplanexpires = result.subscription.billing_period_end_date
|
||||
rower.clubsize = plan.clubsize
|
||||
rower.paymenttype = plan.paymenttype
|
||||
rower.rowerplan = plan.shortname
|
||||
rower.subscription_id = result.subscription.id
|
||||
rower.save()
|
||||
name = '{f} {l}'.format(
|
||||
f = rower.user.first_name,
|
||||
l = rower.user.last_name,
|
||||
)
|
||||
|
||||
|
||||
recurring = plan.paymenttype == 'recurring',
|
||||
|
||||
job = myqueue(
|
||||
queuehigh,
|
||||
handle_send_email_subscription_create,
|
||||
name, rower.user.email,
|
||||
plan.name,
|
||||
recurring,
|
||||
plan.price,
|
||||
plan.price,
|
||||
result.subscription.billing_period_end_date.strftime('%Y-%m-%d')
|
||||
)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -174,7 +236,15 @@ def cancel_subscription(rower,id):
|
||||
result = gateway.subscription.cancel(id)
|
||||
messages.append("Subscription canceled")
|
||||
except:
|
||||
errormessages.append("We could not find the subscription record in our customer database")
|
||||
errormessages.append("We could not find the subscription record in our customer database. We have notified the site owner, who will contact you.")
|
||||
|
||||
name = '{f} {l}'.format(f = rower.user.first_name, l = rower.user.last_name)
|
||||
|
||||
|
||||
job = myqueue(queuehigh,
|
||||
handle_send_email_failed_cancel,
|
||||
name, rower.user.email,rower.user.username,id)
|
||||
|
||||
return False, themessages, errormessages
|
||||
|
||||
rower.paidplan = None
|
||||
|
||||
Reference in New Issue
Block a user