Merge pull request #14945 from chdecultot/gocardless_corrections

Gocardless improvement and  payment request correction
diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py
index c58b185..e7371bd 100644
--- a/erpnext/accounts/doctype/payment_request/payment_request.py
+++ b/erpnext/accounts/doctype/payment_request/payment_request.py
@@ -244,10 +244,10 @@
 				success_url = shopping_cart_settings.payment_success_url
 				if success_url:
 					redirect_to = ({
-						"Orders": "orders",
-						"Invoices": "invoices",
-						"My Account": "me"
-					}).get(success_url, "me")
+						"Orders": "/orders",
+						"Invoices": "/invoices",
+						"My Account": "/me"
+					}).get(success_url, "/me")
 				else:
 					redirect_to = get_url("/orders/{0}".format(self.reference_name))
 
diff --git a/erpnext/erpnext_integrations/doctype/gocardless_settings/gocardless_settings.py b/erpnext/erpnext_integrations/doctype/gocardless_settings/gocardless_settings.py
index af15cf5..c65e3ce 100644
--- a/erpnext/erpnext_integrations/doctype/gocardless_settings/gocardless_settings.py
+++ b/erpnext/erpnext_integrations/doctype/gocardless_settings/gocardless_settings.py
@@ -145,11 +145,11 @@
 
 		if self.flags.status_changed_to == "Completed":
 			status = 'Completed'
-			if self.data.reference_doctype and self.data.reference_docname:
+			if 'reference_doctype' in self.data and 'reference_docname' in self.data:
 				custom_redirect_to = None
 				try:
-					custom_redirect_to = frappe.get_doc(self.data.reference_doctype,
-						self.data.reference_docname).run_method("on_payment_authorized", self.flags.status_changed_to)
+					custom_redirect_to = frappe.get_doc(self.data.get('reference_doctype'),
+						self.data.get('reference_docname')).run_method("on_payment_authorized", self.flags.status_changed_to)
 				except Exception:
 					frappe.log_error(frappe.get_traceback())
 
diff --git a/erpnext/templates/pages/integrations/gocardless_checkout.html b/erpnext/templates/pages/integrations/gocardless_checkout.html
index bbe5640..7193d75 100644
--- a/erpnext/templates/pages/integrations/gocardless_checkout.html
+++ b/erpnext/templates/pages/integrations/gocardless_checkout.html
@@ -9,7 +9,7 @@
 {% endblock %}
 
 {%- block page_content -%}
-<p class='lead text-center centered'>
+<p class='lead text-center'>
 	<span class='gocardless-loading'>{{ _("Loading Payment System") }}</span>
 </p>
 
diff --git a/erpnext/templates/pages/integrations/gocardless_confirmation.html b/erpnext/templates/pages/integrations/gocardless_confirmation.html
index 1567487..6ba154a 100644
--- a/erpnext/templates/pages/integrations/gocardless_confirmation.html
+++ b/erpnext/templates/pages/integrations/gocardless_confirmation.html
@@ -9,7 +9,7 @@
 {% endblock %}
 
 {%- block page_content -%}
-<p class='lead text-center centered'>
+<p class='lead text-center'>
 	<span class='gocardless-loading'>{{ _("Payment Confirmation") }}</span>
 </p>
 
diff --git a/erpnext/templates/pages/integrations/gocardless_confirmation.py b/erpnext/templates/pages/integrations/gocardless_confirmation.py
index 069d900..697ed3c 100644
--- a/erpnext/templates/pages/integrations/gocardless_confirmation.py
+++ b/erpnext/templates/pages/integrations/gocardless_confirmation.py
@@ -36,10 +36,15 @@
 				"session_token": frappe.session.user
 		})
 
+		confirmation_url = redirect_flow.confirmation_url
+		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": redirect_flow.confirmation_url,
+			"redirect_to": confirmation_url,
 			"redirect_message": "Mandate successfully created",
 			"reference_doctype": reference_doctype,
 			"reference_docname": reference_docname
@@ -53,7 +58,7 @@
 		gateway_controller = get_gateway_controller(reference_docname)
 		frappe.get_doc("GoCardless Settings", gateway_controller).create_payment_request(data)
 
-		return {"redirect_to": redirect_flow.confirmation_url}
+		return {"redirect_to": confirmation_url}
 
 	except Exception as e:
 		frappe.log_error(e, "GoCardless Payment Error")