Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(payments): separate redirect constructor from authorization hook #57

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,12 @@ def create_charge_on_braintree(self):
if self.data.reference_doctype and self.data.reference_docname:
custom_redirect_to = None
try:
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.reference_doctype, self.data.reference_docname
).run_method("on_payment_authorized", self.flags.status_changed_to)
).run_method("on_payment_authorized_redirect", self.flags.status_changed_to)
braintree_success_page = frappe.get_hooks("braintree_success_page")
if braintree_success_page:
custom_redirect_to = frappe.get_attr(braintree_success_page[-1])(self.data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ def create_charge_on_gocardless(self):
if "reference_doctype" in self.data and "reference_docname" in self.data:
custom_redirect_to = None
try:
custom_redirect_to = frappe.get_doc(
frappe.get_doc(
self.data.get("reference_doctype"), self.data.get("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_redirect", self.flags.status_changed_to)
except Exception:
frappe.log_error("Gocardless redirect failed")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,15 @@ def confirm_payment(token):
)

if data.get("reference_doctype") and data.get("reference_docname"):
frappe.get_doc(data.get("reference_doctype"), data.get("reference_docname")).run_method(
"on_payment_authorized", "Completed"
)

frappe.db.commit()

custom_redirect_to = frappe.get_doc(
data.get("reference_doctype"), data.get("reference_docname")
).run_method("on_payment_authorized", "Completed")
frappe.db.commit()
).run_method("on_payment_authorized_redirect", "Completed")

redirect_url = "payment-success?doctype={}&docname={}".format(
data.get("reference_doctype"), data.get("reference_docname")
Expand Down Expand Up @@ -399,10 +404,16 @@ def create_recurring_profile(token, payerid):
data["subscription_id"] = response.get("PROFILEID")[0]

frappe.flags.data = data

frappe.get_doc(data.get("reference_doctype"), data.get("reference_docname")).run_method(
"on_payment_authorized", status_changed_to
)

frappe.db.commit()

custom_redirect_to = frappe.get_doc(
data.get("reference_doctype"), data.get("reference_docname")
).run_method("on_payment_authorized", status_changed_to)
frappe.db.commit()
).run_method("on_payment_authorized_redirect", status_changed_to)

redirect_url = "payment-success?doctype={}&docname={}".format(
data.get("reference_doctype"), data.get("reference_docname")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,13 @@ def finalize_request(order_id, transaction_response):
if transaction_data.reference_doctype and transaction_data.reference_docname:
custom_redirect_to = None
try:
custom_redirect_to = frappe.get_doc(
frappe.get_doc(
transaction_data.reference_doctype, transaction_data.reference_docname
).run_method("on_payment_authorized", "Completed")

custom_redirect_to = frappe.get_doc(
transaction_data.reference_doctype, transaction_data.reference_docname
).run_method("on_payment_authorized_redirect", "Completed")
request.db_set("status", "Completed")
except Exception:
request.db_set("status", "Failed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,12 @@ def authorize_payment(self):
custom_redirect_to = None
try:
frappe.flags.data = data
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.reference_doctype, self.data.reference_docname
).run_method("on_payment_authorized", self.flags.status_changed_to)
).run_method("on_payment_authorized_redirect", self.flags.status_changed_to)

except Exception:
frappe.log_error(frappe.get_traceback())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,13 @@ def finalize_request(self):
if self.data.reference_doctype and self.data.reference_docname:
custom_redirect_to = None
try:
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.reference_doctype, self.data.reference_docname
).run_method("on_payment_authorized", self.flags.status_changed_to)
).run_method("on_payment_authorized_redirect", self.flags.status_changed_to)
except Exception:
frappe.log_error(frappe.get_traceback())

Expand Down
Loading