Example #1
0
def confirm_payment(redirect_flow_id, reference_doctype, reference_docname):

    gateway_controller = get_gateway_controller(reference_doctype,
                                                reference_docname)
    settings = frappe.get_doc("GoCardless Settings", gateway_controller)
    client = settings.initialize_client()

    try:
        redirect_flow = client.redirect_flows.complete(
            redirect_flow_id, params={"session_token": reference_docname})

        confirmation_url = frappe.utils.get_url(
            '/integrations/payment-success')
        gocardless_success_page = frappe.get_hooks('gocardless_success_page')
        if gocardless_success_page:
            confirmation_url = frappe.get_attr(gocardless_success_page[-1])\
             (reference_doctype, reference_docname)

        data = {
            "mandate": redirect_flow.links.mandate,
            "customer": redirect_flow.links.customer,
            "redirect_to": confirmation_url,
            "redirect_message": "Mandate successfully created",
            "reference_doctype": reference_doctype,
            "reference_docname": reference_docname
        }

        create_mandate(data)
        return settings.create_payment_request(data)

    except Exception as e:
        frappe.log_error(e, "GoCardless Payment Error")
        return {"redirect_to": '/integrations/payment-failed'}
Example #2
0
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
Example #3
0
def redirect_to_gocardless(data):
    data = frappe.parse_json(data)

    gateway_controller = get_gateway_controller(data["reference_doctype"],
                                                data["reference_docname"])
    client = frappe.get_doc("GoCardless Settings",
                            gateway_controller).initialize_client()

    success_url = data.get("success_url")
    if not success_url:
        success_url = get_url("./integrations/gocardless_confirmation?reference_doctype="\
         + data["reference_doctype"] + "&reference_docname=" + data["reference_docname"])

    try:
        redirect_flow = client.redirect_flows.create(
            params={
                "description":
                _("Pay {0}").format(
                    fmt_money(data['amount'], currency=data['currency'])),
                "session_token":
                data["reference_docname"],
                "success_redirect_url":
                success_url,
                "prefilled_customer":
                get_prefilled_customer(data)
            })

        return {"redirect_to": redirect_flow.redirect_url}

    except Exception as e:
        frappe.log_error(e, "GoCardless Payment Error")
        return {"redirect_to": '/integrations/payment-failed'}
Example #4
0
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
Example #5
0
def make_subscription(data, stripe_token_id):
	data = frappe.parse_json(data)
	data.update({
		"stripe_token_id": stripe_token_id
	})

	gateway_controller = get_gateway_controller(data["reference_doctype"], data["reference_docname"])
	return frappe.get_doc("Stripe Settings", gateway_controller).create_subscription(data)
Example #6
0
def make_payment(payload_nonce, data):
    data = frappe.parse_json(data)
    data.update({"payload_nonce": payload_nonce})

    gateway_controller = get_gateway_controller(data["reference_doctype"],
                                                data["reference_docname"])
    return frappe.get_doc("Braintree Settings",
                          gateway_controller).create_payment_request(data)
Example #7
0
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
Example #8
0
def make_payment_intent(data, intent):
	data = frappe.parse_json(data)

	gateway_controller = get_gateway_controller(data["reference_doctype"], data["reference_docname"])
	return frappe.get_doc("Stripe Settings", gateway_controller).create_payment_intent(data, intent)