adding some model changes around paid plans
This commit is contained in:
53
rowers/braintreestuff.py
Normal file
53
rowers/braintreestuff.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import braintree
|
||||
|
||||
from rowsandall_app.settings import (
|
||||
BRAINTREE_MERCHANT_ID,BRAINTREE_PUBLIC_KEY,BRAINTREE_PRIVATE_KEY
|
||||
)
|
||||
|
||||
gateway = braintree.BraintreeGateway(
|
||||
braintree.Configuration(
|
||||
braintree.Environment.Sandbox,
|
||||
merchant_id=BRAINTREE_MERCHANT_ID,
|
||||
public_key=BRAINTREE_PUBLIC_KEY,
|
||||
private_key=BRAINTREE_PRIVATE_KEY,
|
||||
)
|
||||
)
|
||||
|
||||
from rowers.models import Rower,PaidPlan
|
||||
from rowers.utils import ProcessorCustomerError
|
||||
|
||||
def create_customer(rower):
|
||||
if not rower.customer_id:
|
||||
result = gateway.customer.create(
|
||||
{
|
||||
'first_name':rower.user.first_name,
|
||||
'last_name':rower.user.last_name,
|
||||
'email':rower.user.email,
|
||||
})
|
||||
if not result.is_success:
|
||||
raise ProcessorCustomerError
|
||||
else:
|
||||
rower.customer_id = result.customer.id
|
||||
rower.save()
|
||||
else:
|
||||
return rower.customer_id
|
||||
|
||||
def get_client_token(rower):
|
||||
client_token = gateway.client_token.generate({
|
||||
"customer_id":rower.customer_id,
|
||||
})
|
||||
|
||||
return client_token
|
||||
|
||||
def get_plans_costs():
|
||||
plans = gateway.plan.all()
|
||||
|
||||
localplans = PaidPlan.object.all()
|
||||
|
||||
for plan in localplans:
|
||||
for btplan in btplans:
|
||||
if int(btplan.id) == plan.braintree_id:
|
||||
plan.price = float(x)
|
||||
plan.save()
|
||||
|
||||
return plans
|
||||
Reference in New Issue
Block a user