def subscribe(self, user, plan): """ Create remote Customer instance """ if not settings.CHEDDAR_GETTER_CREATE_USER or self.free: return authorize_CG_gateway() customer = create_customer(user, plan) sub = customer.subscription sub.plan = Plan.get(plan.code) if not self.free: update_subscription(sub, self.cleaned_data, user) customer.save()
def handle_noargs(self, **options): """ Compare existing payment plans """ # authorize on remote server CG.auth(settings.CHEDDAR_GETTER_USER, settings.CHEDDAR_GETTER_PASS) CG.set_product_code(settings.CHEDDAR_GETTER_PRODUCT) # fetch plans plans_remote = Plan.all() plans_map = dict([(x.code, x) for x in plans_remote]) plans_local = SubscriptionPlan.objects.all() # compare by name for plan in plans_local: is_match = plan.code in plans_map print plan.name, '..', 'match' if is_match else 'NO MATCH'
def subscribe(self, user, plan): """ Update remote Customer instance """ authorize_CG_gateway() try: code = settings.CHEDDAR_GETTER_CUSTOMER_CODE_PREFIX + str(user.id) customer = Customer.get(code) new_customer = False except NotFound: if not self.free: customer = create_customer(user, plan) new_customer = True else: return if self.free: return customer.delete() sub = customer.subscription sub.plan = Plan.get(plan.code) update_subscription(sub, self.cleaned_data, user) sub.save() if new_customer: customer.save()