Private
Public Access
1
0

adding some model changes around paid plans

This commit is contained in:
Sander Roosendaal
2018-12-18 19:22:27 +01:00
parent 6d7d9f5792
commit 75261118c2
9 changed files with 401 additions and 15 deletions

53
rowers/braintreestuff.py Normal file
View 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