def f(): if "invoice_id" in request.session: invoice = f5.invoice_details(request, request.session["invoice_id"]) plan = f5.plan_details(request, invoice['plan']) return InvoiceInfo().setDataforInvoice( invoice['amount'], plan, request.session['invoice_id']) plan = f5.plan_details(request, request.session["plan"]) return InvoiceInfo().setDataforDevice(plan)
def f(): tup = f5.invoice_details(request, invoice_id) if tup == {} or not tup: return None plan = f5.plan_details(request, tup[u'plan']) dev = get_object_or_404(Device, pk=int(tup['subscription']['uuid']), user=request.user) return InvoiceInfo(tup, plan, f5.sales_refrence_id(request, invoice_id), dev.id)
def gift_create(request): try: plan = request.POST["plan"] request.session["plan"] = plan from apps.panel.f5adapter import plan_details request.session["price"] = plan_details(request, plan)["price"] subscribeUrl = settings.FPAN['host'] + settings.FPAN['urls']['v2gift'] auth = (settings.FPAN['auth']['username'], settings.FPAN['auth']['password']) form = request.session['giftform'] payload = { 'plan': plan, 'giver_id': form.instance.giver_id, 'getter_id': form.instance.getter_id, 'giver_email': form.instance.giver_email, 'getter_email': form.instance.getter_email, 'giver_name': form.instance.giver_name, 'getter_name': form.instance.getter_name, 'callback_url': request.build_absolute_uri(reverse('gift_callback')), 'callback_token': request.session.session_key } r = requests.post(subscribeUrl, headers=f5.get_api_header(), data=payload, verify=False) res = r.json() if (res['success']): analytics.track(request.session['user_id'], 'gift_choose_plan', {"plan": get_plan_label(res["label"])}) request.session['plan_label'] = res["label"] request.session['token'] = res['token'] del res['token'] for bank in res['active_invoice_payment_url']: res['active_invoice_payment_url'][bank] = reverse( 'start_pay', kwargs={'gateway': bank}) return HttpResponse(json.dumps(res)) except: import sys print sys.exc_info() import traceback print traceback.format_exc() return HttpResponse( json.dumps({ 'error': True, 'errors': u"خطا در مراحل ثبت درخواست پرداخت" }))
def add_device_for_user(request, form_initial, data): """ Get a request object, device form_initialization data and user data to make a device object for user and return proper bank gateway to pay. """ form = NewForm(data or None, initial=form_initial) if form.is_valid(): request.session['deviceform'] = form.instance request.session["plan"] = data["plan"] from apps.panel.f5adapter import plan_details request.session["price"] = plan_details(request, data["plan"])["price"] subscribeUrl = settings.FPAN['host'] + settings.FPAN['urls'][ 'v2subscribe'] auth = (settings.FPAN['auth']['username'], settings.FPAN['auth']['password']) payload = { 'plan': form.cleaned_data['plan'], 'email': form.instance.email, 'callback_url': request.build_absolute_uri(reverse('payment_callback')), 'callback_token': request.session.session_key } r = requests.post(subscribeUrl, headers=f5.get_api_header(), data=payload, verify=False) try: res = r.json() if (res['success']): request.session['token'] = res['token'] del res['token'] if request.user.is_authenticated(): analytics.track(request.session['user_id'], 'choose_plan', {"plan": get_plan_label(res["label"])}) else: analytics.track(request.session['user_id'], 'choose_plan', {"plan": get_plan_label(res["label"])}) # If user uses a referral link and the referredBy attribute is registered in our system # give him discount if configured so in F5 referredBy = request.session.get('referredBy', None) if referredBy: # Generate new promo code if user haven't one yet if request.session.get('referral_promo', None): promo = request.session['referral_promo'] elif get_user_by_id(referredBy): # In case user doesn't have referral_promo, # Generate, apply and save it referrer_name = get_user_by_id(referredBy).username promo = gen_promo('referred', partner=referrer_name) else: promo = gen_promo('campaign', campaign=referredBy) if promo: request.session['referral_promo'] = promo # Apply promo if any generated. ppromo = process_promo(request, promo['code']) if ppromo and 'success' in ppromo: res['referral_promo'] = ppromo for bank in res['active_invoice_payment_url']: res['active_invoice_payment_url'][bank] = reverse( 'start_pay', kwargs={'gateway': bank}) return res except: import sys print sys.exc_info() import traceback print traceback.format_exc() return {'error': True, 'errors': u"خطا در مراحل ثبت درخواست پرداخت"} else: return {'error': True, 'errors': dict(form.errors.items())}