def get_details(plan, request=None): return { RentalPlan.PlanA: { "plan": plan, "title": "Limited Monthly 1 Game Plan", "slug": "limited", "allowed_games": 1, "out_per_month": 2, "amount_to_charge": RentalPlan.get_start_payment_amount(plan), "price": RentalPlan.get_prices(plan)[1], "price_first_month": RentalPlan.get_prices(plan)[0], }, RentalPlan.PlanB: { "plan": plan, "title": "Unlimited Monthly 2 Game Plan", "slug": "unlimited", "allowed_games": 2, "out_per_month": None, "amount_to_charge": RentalPlan.get_start_payment_amount(plan), "price": RentalPlan.get_prices(plan)[1], "price_first_month": RentalPlan.get_prices(plan)[0], }, }[plan]
def clean(self): data = super(ConfirmPlanChangingForm, self).clean() if not self._errors: request = self.request wizard = self.request.rent_wizard f = wizard.get_form(0, self.request.POST) f.is_valid() # it's a long way to get info from here plan = int(f.cleaned_data['plan']) _profile = request.user.get_profile() current_plan = MemberRentalPlan.get_current_plan(_profile.user) self.current_plan = current_plan if current_plan and current_plan.plan == plan: self.rent_plan = None return data card = self.cached_card['data'] card['display_number'] = self.cached_card['display_number'] aim_data = { 'x_customer_ip': self.request.META.get('REMOTE_ADDR'), 'x_cust_id': _profile.user.id, 'x_email': _profile.user.email, } shipping_address = _profile.get_shipping_address_data() shipping_address.update(_profile.get_name_data()) shipping_address['country'] = 'USA' billing_address = _profile.get_billing_data() billing_address['country'] = 'USA' downgrade = current_plan and plan <= current_plan.plan self.downgrade = downgrade if downgrade: return data self.rent_plan = MemberRentalPlan.create(_profile.user, plan, downgrade) self.billing_history = None amount = RentalPlan.get_start_payment_amount(plan) #malcala: changs to capture money #do_capture = False do_capture = True if current_plan: last_payment = current_plan.get_last_payment() if last_payment and last_payment.status == TransactionStatus.Passed: orders = RentOrder.objects.filter( user=current_plan.user, date_rent__gte=current_plan.created ).exclude(status__in=[RentOrderStatus.Prepared, RentOrderStatus.Canceled]) if orders.count(): if last_payment.debit < amount: amount -= (current_plan.next_payment_amount or RentalPlan.get_start_payment_amount(current_plan.plan)) do_capture = True tax = Tax.get_value(billing_address['state'], billing_address['county']) tax_amount = decimal.Decimal('%.2f' % (amount * tax / decimal.Decimal('100.0'))) aim_data['x_tax'] = tax_amount self.billing_history = BillingHistory.create(_profile.user, card['display_number'], debit=amount, reason='rent', type=TransactionType.RentPayment) self.billing_history.tax = tax_amount invoice_num, description = self.rent_plan.get_payment_description(False, self.billing_history.id) self.billing_history.description = description self.billing_history.save() if do_capture: res, aim_response, applied_credits, applied_amount = self.rent_plan.take_money(amount, tax_amount, invoice_num, description, card=card, shipping_data=shipping_address, billing_data=billing_address, aim_data=aim_data, profile=_profile) self.billing_history.applied_credits = applied_credits self.billing_history.status = TransactionStatus.Passed self.billing_history.setted = True else: res, aim_response = self.rent_plan.authorize_money(amount, tax_amount, invoice_num, description, card=card, shipping_data=shipping_address, billing_data=billing_address, aim_data=aim_data) self.billing_history.status = TransactionStatus.Authorized self.billing_history.setted = False if aim_response: self.billing_history.aim_transaction_id = aim_response.transaction_id self.billing_history.aim_response = aim_response._as_dict self.billing_history.message = aim_response.response_reason_text if not res: self.billing_history.status = TransactionStatus.Declined self.billing_history.save() self.rent_plan.delete() raise forms.ValidationError(self.rent_plan.status_message) self.billing_history.card_data = self.cached_card['data'] self.billing_history.save() return data