Skip to content

Commit

Permalink
feat: switch payment method after selecting
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Jun 8, 2024
1 parent 037e566 commit c232c7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
4 changes: 4 additions & 0 deletions payments/www/pay.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ <h5 class='page-card-head text-center'>
</div>
{% endif %}
{% if render_buttons %}
{% if render_widget or render_capture %}
<hr/>
<div class='text-info text-center small my-3'>{{ _("or change payment method") }}:</div>
{% endif %}
<div id="select-button-errors" class='text-danger text-center small my-3' style='display: none;'></div>
{% set primary_button = payment_buttons[0] %}
{% set secondary_buttons = payment_buttons[1:] %}
Expand Down
41 changes: 20 additions & 21 deletions payments/www/pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,35 @@ def get_context(context):
# A terminal error state would require operator intervention, first
if psl.status not in terminal_states.keys():
# First Pass: chose payment button
if not psl.button:
context.render_widget = False
context.render_buttons = True
context.render_capture = False
context.logo = frappe.get_website_settings("app_logo") or frappe.get_hooks("app_logo_url")[-1]
filters = {"enabled": True}

# gateway was preselected; e.g. on the backend
if psl.gateway:
filters.update(json.loads(psl.gateway))
# gateway was preselected; e.g. on the backend
filters = {"enabled": True}
if psl.gateway:
filters.update(json.loads(psl.gateway))

buttons = frappe.get_list(
"Payment Button",
fields=["name", "icon", "label"],
filters=filters,
)

buttons = frappe.get_list(
context.payment_buttons = [
(load_icon(entry.get("icon")), entry.get("name"), entry.get("label"))
for entry in frappe.get_list(
"Payment Button",
fields=["name", "icon", "label"],
filters=filters,
)
]
context.render_buttons = True

if not psl.button:
context.render_widget = False
context.render_capture = False
context.logo = frappe.get_website_settings("app_logo") or frappe.get_hooks("app_logo_url")[-1]

context.payment_buttons = [
(load_icon(entry.get("icon")), entry.get("name"), entry.get("label"))
for entry in frappe.get_list(
"Payment Button",
fields=["name", "icon", "label"],
filters=filters,
)
]
# Second Pass (Data Capture): capture additonal data if the button requires it
elif psl.requires_data_capture:
context.render_widget = False
context.render_buttons = False
context.render_capture = True
context.logo = frappe.get_website_settings("app_logo") or frappe.get_hooks("app_logo_url")[-1]

Expand All @@ -108,7 +108,6 @@ def get_context(context):
# Second Pass (Third Party Widget): let the third party widget manage data capture and flow
else:
context.render_widget = True
context.render_buttons = False
context.render_capture = False
context.logo = frappe.get_website_settings("app_logo") or frappe.get_hooks("app_logo_url")[-1]

Expand Down

0 comments on commit c232c7e

Please sign in to comment.