def get_context(context): context.no_cache = 1 # all these keys exist in form_dict if not (set(expected_keys) - set(list(frappe.form_dict))): for key in expected_keys: context[key] = frappe.form_dict[key] gateway_controller = get_gateway_controller(context.reference_doctype, context.reference_docname) context.publishable_key = get_api_key(context.reference_docname, gateway_controller) context.image = get_header_image(context.reference_docname, gateway_controller) context['amount'] = fmt_money(amount=context['amount'], currency=context['currency']) if frappe.db.get_value(context.reference_doctype, context.reference_docname, "is_a_subscription"): payment_plan = frappe.db.get_value(context.reference_doctype, context.reference_docname, "payment_plan") recurrence = frappe.db.get_value("Payment Plan", payment_plan, "recurrence") context['amount'] = context['amount'] + " " + _(recurrence) else: frappe.redirect_to_message(_('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.')) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def get_context(context): context.no_cache = 1 context.lang = frappe.local.lang # all these keys exist in form_dict if not set(EXPECTED_KEYS) - set(list(frappe.form_dict)): for key in EXPECTED_KEYS: context[key] = frappe.form_dict[key] context.client_secret = "no-secret" context.is_subscription = False gateway_controller = get_gateway_controller(context.reference_doctype, context.reference_docname) reference_document = frappe.get_doc(context.reference_doctype, context.reference_docname) if hasattr(reference_document, 'is_linked_to_a_subscription') and reference_document.is_linked_to_a_subscription(): context.is_subscription = True else: payment_intent = frappe.get_doc("Stripe Settings", gateway_controller)\ .create_payment_intent_on_stripe(amount=cint(context['amount'])*100, currency=context['currency']) context.client_secret = payment_intent.client_secret context.publishable_key = get_api_key(context.reference_docname, gateway_controller) context.image = get_header_image(context.reference_docname, gateway_controller) context.amount = fmt_money(amount=context.amount, currency=context.currency) else: frappe.redirect_to_message(_('Invalid link'),\ _('This link is not valid.<br>Please contact us.')) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def signup(full_name, email, subdomain, plan=None, distribution="erpnext", res=None): status = _signup(full_name, email, subdomain, plan=plan, distribution=distribution, reseller=res) if status == 'success': location = frappe.redirect_to_message( _('Verify your Email'), """<div><p>You will receive an email at <strong>{}</strong>, asking you to verify this account request.<p><br> <p>It may take a few minutes before you receive this email. If you don't find it, please check your SPAM folder.</p> </div>""".format(email), indicator_color='blue') elif status == 'retry': return {} else: # something went wrong location = frappe.redirect_to_message( _('Something went wrong'), 'Please try again or drop an email to [email protected]', indicator_color='red') return {'location': location}
def get_context(context): context.no_cache = 1 # all these keys exist in form_dict if not set(EXPECTED_KEYS) - set(list(frappe.form_dict)): for key in EXPECTED_KEYS: context[key] = frappe.form_dict[key] gateway_controller = get_gateway_controller(context.reference_doctype, context.reference_docname) settings = frappe.get_doc("Braintree Settings", gateway_controller) context.formatted_amount = fmt_money(amount=context.amount, currency=context.currency) context.locale = frappe.local.lang context.header_img = frappe.db.get_value("Braintree Settings", gateway_controller, "header_img") context.client_token = settings.generate_token(context) else: frappe.redirect_to_message(_('Invalid link'),\ _('This link is not valid.<br>Please contact us.')) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def error_message(self, error_number=500, title=None, error=None): if error is None: error = frappe.get_traceback() frappe.log_error(error, title) if error_number == 201: return { "redirect_to": frappe.redirect_to_message(_('Payment error'),\ _("It seems that your payment has not been fully accepted by your bank.<br>We will get in touch with you as soon as possible.")), "status": 201, "error": error } elif error_number == 402: return { "redirect_to": frappe.redirect_to_message(_('Server Error'),\ _("It seems that there is an issue with our Stripe integration.<br>In case of failure, the amount will get refunded to your account.")), "status": 402, "error": error } else: return { "redirect_to": frappe.redirect_to_message(_('Server Error'), _("It seems that there is an issue with our Stripe integration.<br>In case of failure, the amount will get refunded to your account.")), "status": 500, "error": error }
def verify_account(name, code): site = frappe.get_doc("Site", name) if not site: return { "location": frappe.redirect_to_message( _('Verification Error'), "<p class='text-danger'>Invalid Site Name!</p>") } if site.status != "Email Sent": return { "location": frappe.redirect_to_message( _('Verification Error'), "<p class='text-danger'>Code arlead used!</p>") } if site.email_verification_code == code: site.status = "Site Verified" site.save(ignore_permissions=True) frappe.db.commit() return { "location": frappe.redirect_to_message( _('Site Verified'), "Site successfully verified! Continue to <a href='/setup?name=" + site.name + "&code=" + site.email_verification_code + "'><strong>Setup</strong></a>") } else: return { "location": frappe.redirect_to_message( _('Verification Error'), "<p class='text-danger'>Invalid Code!</p>") }
def get_context(context): context.no_cache = 1 context.api_key = get_api_key() try: doc = frappe.get_doc("Integration Request", frappe.form_dict["token"]) payment_details = json.loads(doc.data) for key in expected_keys: context[key] = payment_details[key] context["token"] = frappe.form_dict["token"] context["amount"] = flt(context["amount"]) context["subscription_id"] = (payment_details["subscription_id"] if payment_details.get("subscription_id") else "") except Exception as e: frappe.redirect_to_message( _("Invalid Token"), _("Seems token you are using is invalid!"), http_status_code=400, indicator_color="red", ) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def signup(full_name, email, subdomain, plan="Free", distribution="erpnext"): status = _signup( full_name, email, subdomain, plan=plan, distribution='erpnext' if distribution == 'schools' else distribution) context = { 'pathname': 'schools/signup' if distribution == 'schools' else 'signup' } if status == 'success': location = frappe.redirect_to_message( _('Thank you for signing up'), """<div><p>You will receive an email at <strong>{}</strong>, asking you to verify this account request.<br> If you are unable to find the email in your inbox, please check your SPAM folder. It may take a few minutes before you receive this email.</p> <p>Once you click on the verification link, your account will be ready in a few minutes.</p> </div>""".format(email), context=context) elif status == 'retry': return {} else: # something went wrong location = frappe.redirect_to_message( _('Something went wrong'), 'Please try again or drop an email to [email protected]', context=context) return {'location': location}
def signup(full_name, email, phone_number, subdomain, industry_type, plan=None, distribution="erpnext", res=None, number_of_users=1, passphrase=None, country=None, timezone=None, currency=None, language=None): resp = _signup(full_name, email, phone_number, subdomain, industry_type, plan=plan, distribution=distribution, reseller=res, users=number_of_users, password=passphrase, country=country, timezone=timezone, currency=currency, language=language) if resp.get("redirect_to"): return { "location": resp['redirect_to'] } elif resp['status'] == 'success': location = frappe.redirect_to_message(_('Verify your Email'), """<div><p>You will receive an email at <strong>{}</strong>, asking you to verify this account request.<p><br> <p>It may take a few minutes before you receive this email. If you don't find it, please check your SPAM folder.</p> </div>""".format(email), indicator_color='blue') elif resp['status']=='retry': return {} else: # something went wrong location = frappe.redirect_to_message(_('Something went wrong'), 'Please try again or drop an email to [email protected]', indicator_color='red') return { 'location': location }
def get_context(context): context.no_cache = 1 # all these keys exist in form_dict if not (set(expected_keys) - set(list(frappe.form_dict))): for key in expected_keys: context[key] = frappe.form_dict[key] gateway_controller = get_gateway_controller(context.reference_doctype, context.reference_docname) context.publishable_key = get_api_key(context.reference_docname, gateway_controller) context.image = get_header_image(context.reference_docname, gateway_controller) context['amount'] = fmt_money(amount=context['amount'], currency=context['currency']) if frappe.db.get_value(context.reference_doctype, context.reference_docname, "is_a_subscription"): payment_plan = frappe.db.get_value(context.reference_doctype, context.reference_docname, "payment_plan") recurrence = frappe.db.get_value("Payment Plan", payment_plan, "recurrence") context['amount'] = context['amount'] + " " + _(recurrence) else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def get_context(context): order_id = frappe.form_dict.order_id if order_id: order_info = frappe.get_doc("Order", order_id) if order_info: if order_info.payment_status == 'Pending': customers = frappe.db.get_all( 'Customers', filters={'user_id': frappe.session.user}, fields=['*']) customer = customers[0] if order_info.customer == customer.name: context.order_info = order_info context.customer = customer gateway_settings = frappe.get_single('CCAvenue Settings') if gateway_settings.working_key: context.catalog_settings = frappe.get_single( 'Catalog Settings') context.gateway_settings = gateway_settings else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def make_payment(iyzipay_payment_id, options, reference_doctype, reference_docname): try: iyzipay_payment = frappe.get_doc({ "doctype": "Iyzipay Payment", "iyzipay_payment_id": iyzipay_payment_id, "data": options, "reference_doctype": reference_doctype, "reference_docname": reference_docname }) iyzipay_payment.insert(ignore_permissions=True) if frappe.db.get_value("Iyzipay Payment", iyzipay_payment.name, "status") == "Authorized": return { "redirect_to": iyzipay_payment.flags.redirect_to or "iyzipay-payment-success", "status": 200 } except AuthenticationError as e: make_log_entry(e.message, options) return { "redirect_to": frappe.redirect_to_message( _('Server Error'), _("Seems issue with server's iyzipay config. Don't worry, in case of failure amount will get refunded to your account." )), "status": 401 } except InvalidRequest as e: make_log_entry(e.message, options) return { "redirect_to": frappe.redirect_to_message( _('Server Error'), _("Seems issue with server's iyzipay config. Don't worry, in case of failure amount will get refunded to your account." )), "status": 400 } except GatewayError as e: make_log_entry(e.message, options) return { "redirect_to": frappe.redirect_to_message( _('Server Error'), _("Seems issue with server's iyzipay config. Don't worry, in case of failure amount will get refunded to your account." )), "status": 500 }
def get_context(context): context.no_cache = 1 # get request name from query string request_name = frappe.form_dict.get("req") # or from pathname, this works better for redirection on auth errors if not request_name: path_parts = context.get("pathname", "").split('/') request_name = path_parts[-1] # attempt to fetch AuthorizeNet Request record try: request = frappe.get_doc("AuthorizeNet Request", request_name) except Exception as ex: request = None # Captured/Authorized transaction redirected to home page # TODO: Should we redirec to a "Payment already received" Page? if not request or (request and request.get('status') in ("Captured", "Authorized")): frappe.local.flags.redirect_location = '/' raise frappe.Redirect # list countries for billing address form context["authorizenet_countries"] = frappe.get_list( "Country", fields=["country_name", "name"]) if request_name and request: for key in expected_keys: context[key] = request.get(key) context["reference_doc"] = frappe.get_doc( request.get("reference_doctype"), request.get("reference_docname")) context["request_name"] = request_name context["year"] = datetime.today().year # get the authorizenet user record authnet_user = get_authorizenet_user(request.get("payer_name")) context["authnet_user"] = authnet_user #add=get_primary_address(request.get("payer_name"),'1509101163') #context['address']=add if authnet_user: context["stored_payments"] = authnet_user.get( "stored_payments", []) else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect return context
def get_context(self, context): newsletters = get_newsletter_list("Newsletter", None, None, 0) if newsletters: newsletter_list = [d.name for d in newsletters] if self.name not in newsletter_list: frappe.redirect_to_message(_('Permission Error'), _("You are not permitted to view the newsletter.")) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect else: context.attachments = get_attachments(self.name) context.no_cache = 1 context.show_sidebar = True
def get_context(context): context.no_cache = 1 # all these keys exist in form_dict if not (set(EXPECTED_KEYS) - set(frappe.form_dict.keys())): for key in EXPECTED_KEYS: context[key] = frappe.form_dict[key] else: frappe.redirect_to_message(_('Invalid link'),\ _('This link is not valid.<br>Please contact us.')) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def get_context(context): is_enabled = frappe.db.get_single_value("Appointment Booking Settings", "enable_scheduling") if is_enabled: return context else: frappe.redirect_to_message( _("Appointment Scheduling Disabled"), _("Appointment Scheduling has been disabled for this site"), http_status_code=302, indicator_color="red", ) raise frappe.Redirect
def get_context(context): context.no_cache = 1 context.api_key = get_api_key() # all these keys exist in form_dict if not (set(expected_keys) - set(frappe.form_dict.keys())): for key in expected_keys: context[key] = frappe.form_dict[key] context['amount'] = flt(context['amount']) else: frappe.redirect_to_message(_('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.')) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def get_context(context): context.no_cache = 1 # all these keys exist in form_dict if not (set(expected_keys) - set(frappe.form_dict.keys())): for key in expected_keys: context[key] = frappe.form_dict[key] else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def get_context(context): context.no_cache = 1 context.api_key = get_iyzipay_settings().api_key context.brand_image = (frappe.db.get_value("Iyzipay Settings", None, "brand_image") or './assets/erpnext/images/erp-icon.svg') if frappe.form_dict.payment_request: payment_req = frappe.get_doc('Payment Request', frappe.form_dict.payment_request) validate_transaction_currency(payment_req.currency) if payment_req.status == "Paid": frappe.redirect_to_message( _('Already Paid'), _('You have already paid for this order')) return reference_doc = frappe.get_doc(payment_req.reference_doctype, payment_req.reference_name) context.amount = payment_req.grand_total context.title = reference_doc.company context.description = payment_req.subject context.doctype = payment_req.doctype context.name = payment_req.name context.payer_name = reference_doc.customer_name context.payer_email = reference_doc.get( 'email_to') or frappe.session.user context.order_id = payment_req.name context.reference_doctype = payment_req.reference_doctype context.reference_name = payment_req.reference_name # all these keys exist in form_dict elif not (set(expected_keys) - set(frappe.form_dict.keys())): for key in expected_keys: context[key] = frappe.form_dict[key] context['amount'] = flt(context['amount']) context['reference_doctype'] = context['reference_name'] = None else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def create_request(self, data): self.data = frappe._dict(data) try: if frappe.db.exists("Integration Request", self.data.flutter_charge_reference): self.integration_request = frappe.get_doc( "Integration Request", self.data.flutter_charge_reference) return self.authorize_payment() else: self.integration_request = super(MoneywaveSettings, self).create_request(self.data, "Host", \ "Moneywave", self.data.flutter_charge_reference) return self.authorize_payment() except Exception: frappe.log_error(frappe.get_traceback()) return { "redirect_to": frappe.redirect_to_message( _('Server Error'), _("Seems issue with moneywave server's config. Don't worry, in case of failure amount will get refunded to your account." )), "status": 401 }
def create_stripe_subscription(gateway_controller, data): stripe_settings = frappe.get_doc("Stripe Settings", gateway_controller) stripe_settings.data = frappe._dict(data) stripe.api_key = stripe_settings.get_password(fieldname="secret_key", raise_exception=False) stripe.default_http_client = stripe.http_client.RequestsClient() try: stripe_settings.integration_request = create_request_log( stripe_settings.data, "Host", "Stripe") stripe_settings.payment_plans = frappe.get_doc( "Payment Request", stripe_settings.data.reference_docname).subscription_plans return create_subscription_on_stripe(stripe_settings) except Exception: frappe.log_error(frappe.get_traceback()) return { "redirect_to": frappe.redirect_to_message( _('Server Error'), _("It seems that there is an issue with the server's stripe configuration. In case of failure, the amount will get refunded to your account." )), "status": 401 }
def get_context(context): context.no_cache = 1 payment_req = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.docname) validate_transaction_currency if payment_req.status == "Paid": frappe.redirect_to_message(_('Already Paid'), _('You have already paid for this order')) return reference_doc = frappe.get_doc(payment_req.reference_doctype, payment_req.reference_name) context.customer_name = reference_doc.customer_name context.api_key = frappe.db.get_value("Razorpay Settings", None, "api_key") context.company = reference_doc.company context.doc = payment_req context.user = frappe.session.user
def get_context(context): context.no_cache = 1 # all these keys exist in form_dict if not (set(expected_keys) - set(list(frappe.form_dict))): for key in expected_keys: context[key] = frappe.form_dict[key] if frappe.form_dict['payer_email']: if frappe.form_dict['payer_email'] != frappe.session.user: frappe.throw(_("Not permitted"), frappe.PermissionError) else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect context.reference_docname = frappe.form_dict['order_id'] context.customercards = frappe.db.get_all( "Moneris Vault", fields={'*'}, filters={"user_id": frappe.session.user}, order_by="creation desc") gateway_controller = get_gateway_controller(context.reference_doctype, context.reference_docname) context['amount'] = fmt_money(amount=context['amount'], currency=context['currency']) if frappe.db.get_value(context.reference_doctype, context.reference_docname, "is_a_subscription"): payment_plan = frappe.db.get_value(context.reference_doctype, context.reference_docname, "payment_plan") recurrence = frappe.db.get_value("Payment Plan", payment_plan, "recurrence") context['amount'] = context['amount'] + " " + _(recurrence) else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def get_context(context): context.no_cache = 1 context.api_key = frappe.db.get_value("Razorpay Settings", None, "api_key") # all these keys exist in form_dict if not (set(expected_keys) - set(frappe.form_dict.keys())): for key in expected_keys: context[key] = frappe.form_dict[key] context['amount'] = flt(context['amount']) else: frappe.redirect_to_message( _('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.' )) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def get_context(context): context.no_cache = 1 # all these keys exist in form_dict if not (set(expected_keys) - set(frappe.form_dict.keys())): for key in expected_keys: context[key] = frappe.form_dict[key] context['amount'] = flt(context['amount']) gateway_controller = get_gateway_controller(context.reference_docname) context['header_img'] = frappe.db.get_value("GoCardless Settings", gateway_controller, "header_img") else: frappe.redirect_to_message(_('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.')) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def get_context(context): context.no_cache = 1 context.affirm_api_config = get_api_config() # all these keys exist in form_dict if not (set(expected_keys) - set(frappe.form_dict.keys())): checkout = dict() for key in expected_keys: checkout[key] = frappe.form_dict[key] context['checkout_data'] = create_order(**checkout) return context else: frappe.redirect_to_message(_('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.')) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def get_context(context): context.no_cache = 1 # all these keys exist in form_dict if not set(EXPECTED_KEYS) - set(frappe.form_dict.keys()): for key in EXPECTED_KEYS: context[key] = frappe.form_dict[key] context['amount'] = flt(context['amount']) gateway_controller = get_gateway_controller(context.reference_doctype, context.reference_docname) else: frappe.redirect_to_message(_('Invalid link'),\ _('This link is not valid.<br>Please contact us.')) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def error_message(self, error_number=500, title=None, error=None): if error is None: error = frappe.get_traceback() frappe.log_error(error, title) if error_number == 402: return { "redirect_to": frappe.redirect_to_message(_('Server Error'),\ _("It seems that there is an issue with our GoCardless integration.\ <br>In case of failure, the amount will get refunded to your account." )), "status": 402 } else: return { "redirect_to": frappe.redirect_to_message(_('Server Error'),\ _("It seems that there is an issue with our GoCardless integration.\ <br>In case of failure, the amount will get refunded to your account." )), "status": 500 }
def create_request(self, data): self.data = frappe._dict(data) try: self.integration_request = create_request_log(self.data, "Host", "Stripe") return self.create_charge_on_stripe() except Exception: frappe.log_error(frappe.get_traceback()) return{ "redirect_to": frappe.redirect_to_message(_('Server Error'), _("Seems issue with server's razorpay config. Don't worry, in case of failure amount will get refunded to your account.")), "status": 401 }
def verify_account(name, code): site = frappe.get_doc("Site", name) if not site: return { "location": frappe.redirect_to_message(_('Verification Error'),"<p class='text-danger'>Invalid Site Name!</p>") } if site.status != "Email Sent": return { "location": frappe.redirect_to_message(_('Verification Error'),"<p class='text-danger'>Code arlead used!</p>") } if site.email_verification_code == code: site.status = "Site Verified" site.save(ignore_permissions=True) frappe.db.commit() return { "location": frappe.redirect_to_message(_('Site Verified'),"Site successfully verified! Continue to <a href='/setup?name="+site.name+"&code="+site.email_verification_code+"'><strong>Setup</strong></a>") } else: return { "location": frappe.redirect_to_message(_('Verification Error'),"<p class='text-danger'>Invalid Code!</p>") }
def get_context(context): context.no_cache = 1 context.api_key = get_api_key() try: doc = frappe.get_doc("Integration Request", frappe.form_dict['token']) payment_details = json.loads(doc.data) for key in expected_keys: context[key] = payment_details[key] context['token'] = frappe.form_dict['token'] context['amount'] = flt(context['amount']) except Exception: frappe.redirect_to_message(_('Invalid Token'), _('Seems token you are using is invalid!'), http_status_code=400, indicator_color='red') frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def get_context(context): context.no_cache = 1 context.api_key = get_razorpay_settings().api_key context.brand_image = (frappe.db.get_value("Razorpay Settings", None, "brand_image") or './assets/erpnext/images/erp-icon.svg') if frappe.form_dict.payment_request: payment_req = frappe.get_doc('Payment Request', frappe.form_dict.payment_request) validate_transaction_currency(payment_req.currency) if payment_req.status == "Paid": frappe.redirect_to_message(_('Already Paid'), _('You have already paid for this order')) return reference_doc = frappe.get_doc(payment_req.reference_doctype, payment_req.reference_name) context.amount = payment_req.grand_total context.title = reference_doc.company context.description = payment_req.subject context.doctype = payment_req.doctype context.name = payment_req.name context.payer_name = reference_doc.customer_name context.payer_email = reference_doc.get('email_to') or frappe.session.user context.order_id = payment_req.name context.reference_doctype = payment_req.reference_doctype context.reference_name = payment_req.reference_name # all these keys exist in form_dict elif not (set(expected_keys) - set(frappe.form_dict.keys())): for key in expected_keys: context[key] = frappe.form_dict[key] context['amount'] = flt(context['amount']) context['reference_doctype'] = context['reference_name'] = None else: frappe.redirect_to_message(_('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.')) frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def create_payment_request(self, data): self.data = frappe._dict(data) try: self.integration_request = create_request_log(self.data, "Host", "Braintree") return self.create_charge_on_braintree() except Exception: frappe.log_error(frappe.get_traceback()) return{ "redirect_to": frappe.redirect_to_message(_('Server Error'), _("There seems to be an issue with the server's braintree configuration. Don't worry, in case of failure, the amount will get refunded to your account.")), "status": 401 }
def get_context(context): context.no_cache = 1 paytm_config = get_paytm_config() try: doc = frappe.get_doc("Integration Request", frappe.form_dict['order_id']) context.payment_details = get_paytm_params(json.loads(doc.data), doc.name, paytm_config) context.url = paytm_config.url except Exception: frappe.log_error() frappe.redirect_to_message(_('Invalid Token'), _('Seems token you are using is invalid!'), http_status_code=400, indicator_color='red') frappe.local.flags.redirect_location = frappe.local.response.location raise frappe.Redirect
def create_payment_request(self, data): self.data = frappe._dict(data) try: self.integration_request = create_request_log(self.data, "Host", "GoCardless") return self.create_charge_on_gocardless() except Exception: frappe.log_error(frappe.get_traceback()) return{ "redirect_to": frappe.redirect_to_message(_('Server Error'), _("There seems to be an issue with the server's GoCardless configuration. Don't worry, in case of failure, the amount will get refunded to your account.")), "status": 401 }
def create_request(self, data): self.data = frappe._dict(data) try: self.integration_request = frappe.get_doc("Integration Request", self.data.token) self.integration_request.update_status(self.data, 'Queued') return self.authorize_payment() except Exception: frappe.log_error(frappe.get_traceback()) return{ "redirect_to": frappe.redirect_to_message(_('Server Error'), _("Seems issue with server's razorpay config. Don't worry, in case of failure amount will get refunded to your account.")), "status": 401 }
def create_request(self, data): self.data = frappe._dict(data) try: self.integration_request = super(RazorpaySettings, self).create_request(self.data, "Host", \ "Razorpay") return self.authorize_payment() except Exception: frappe.log_error(frappe.get_traceback()) return{ "redirect_to": frappe.redirect_to_message(_('Server Error'), _("Seems issue with server's razorpay config. Don't worry, in case of failure amount will get refunded to your account.")), "status": 401 }
def create_request(self, data): self.data = frappe._dict(data) try: self.integration_request = frappe.get_doc("Integration Request", self.data.token) self.integration_request.update_status(self.data, 'Queued') return self.authorize_payment() except Exception: frappe.log_error(frappe.get_traceback()) return{ "redirect_to": frappe.redirect_to_message(_('Server Error'), _("Seems issue with server's midtrans config. Don't worry, in case of failure amount will get refunded to your account.")), "status": 401 }
def signup(email, domain_name, telephone="",_type='POST'): site = frappe.get_doc({ "doctype": "Site", "title": domain_name, "customer_name": domain_name, "status": "Pending Approval", "email": email, "telephone":telephone }) site.insert(ignore_permissions=True) frappe.db.commit() return { "location": frappe.redirect_to_message(_('Confirm Email'),"Thank you for registering. Check your email to complete registration") }
def signup(full_name, email, subdomain, plan="Free", distribution="erpnext", res=None): status = _signup(full_name, email, subdomain, plan=plan, distribution=distribution, reseller=res) if status == 'success': location = frappe.redirect_to_message(_('Verify your Email'), """<div><p>You will receive an email at <strong>{}</strong>, asking you to verify this account request.<p><br> <p>It may take a few minutes before you receive this email. If you don't find it, please check your SPAM folder.</p> </div>""".format(email), indicator_color='blue') elif status=='retry': return {} else: # something went wrong location = frappe.redirect_to_message(_('Something went wrong'), 'Please try again or drop an email to [email protected]', indicator_color='red') return { 'location': location }
def setup_account(name, telephone, business_name, password, domain): site = frappe.get_doc("Site", name) site.business_name = business_name site.telephone = telephone site.domain = domain site.save(ignore_permissions=True) frappe.db.commit() enqueue(create_site, site=site, admin_password=password) if site.domain == "custom": location = "Congatulations! Your website has been setup. You will shortly receive email with login details" else: location = "Congatulations! Your website has been setup. <a href='http://"+site.title+"'>Login</a>" return { "location": frappe.redirect_to_message(_('Website Setup'), location) }
def create_request(self, data): import stripe self.data = frappe._dict(data) stripe.api_key = self.get_password(fieldname="secret_key", raise_exception=False) stripe.default_http_client = stripe.http_client.RequestsClient() try: self.integration_request = create_request_log(self.data, "Host", "Stripe") return self.create_charge_on_stripe() except Exception: frappe.log_error(frappe.get_traceback()) return{ "redirect_to": frappe.redirect_to_message(_('Server Error'), _("It seems that there is an issue with the server's stripe configuration. In case of failure, the amount will get refunded to your account.")), "status": 401 }
def create_stripe_subscription(gateway_controller, data): stripe_settings = frappe.get_doc("Stripe Settings", gateway_controller) stripe_settings.data = frappe._dict(data) stripe.api_key = stripe_settings.get_password(fieldname="secret_key", raise_exception=False) stripe.default_http_client = stripe.http_client.RequestsClient() try: stripe_settings.integration_request = create_request_log(stripe_settings.data, "Host", "Stripe") stripe_settings.payment_plans = frappe.get_doc("Payment Request", stripe_settings.data.reference_docname).subscription_plans return create_subscription_on_stripe(stripe_settings) except Exception: frappe.log_error(frappe.get_traceback()) return{ "redirect_to": frappe.redirect_to_message(_('Server Error'), _("It seems that there is an issue with the server's stripe configuration. In case of failure, the amount will get refunded to your account.")), "status": 401 }
def make_payment(razorpay_payment_id, options, reference_doctype, reference_docname): try: razorpay_payment = frappe.get_doc({ "doctype": "Razorpay Payment", "razorpay_payment_id": razorpay_payment_id, "data": options, "reference_doctype": reference_doctype, "reference_docname": reference_docname }) razorpay_payment.insert(ignore_permissions=True) if frappe.db.get_value("Razorpay Payment", razorpay_payment.name, "status") == "Authorized": return { "redirect_to": razorpay_payment.flags.redirect_to or "razorpay-payment-success", "status": 200 } except AuthenticationError, e: make_log_entry(e.message, options) return{ "redirect_to": frappe.redirect_to_message(_('Server Error'), _("Seems issue with server's razorpay config. Don't worry, in case of failure amount will get refunded to your account.")), "status": 401 }
}) razorpay_payment.insert(ignore_permissions=True) if frappe.db.get_value("Razorpay Payment", razorpay_payment.name, "status") == "Authorized": return { "redirect_to": razorpay_payment.flags.redirect_to or "razorpay-payment-success", "status": 200 } except AuthenticationError, e: make_log_entry(e.message, options) return{ "redirect_to": frappe.redirect_to_message(_('Server Error'), _("Seems issue with server's razorpay config. Don't worry, in case of failure amount will get refunded to your account.")), "status": 401 } except InvalidRequest, e: make_log_entry(e.message, options) return { "redirect_to": frappe.redirect_to_message(_('Server Error'), _("Seems issue with server's razorpay config. Don't worry, in case of failure amount will get refunded to your account.")), "status": 400 } except GatewayError, e: make_log_entry(e.message, options) return { "redirect_to": frappe.redirect_to_message(_('Server Error'), _("Seems issue with server's razorpay config. Don't worry, in case of failure amount will get refunded to your account.")), "status": 500 }