Skip to content

Commit

Permalink
feat: add redirect after milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Jul 3, 2024
1 parent 19fb58f commit e5a9d14
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions payments/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class Proceeded:
class ActionAfterProcessed:
href: str
label: str
redirect_after_milliseconds: int | None = None


@dataclass
Expand Down
1 change: 1 addition & 0 deletions payments/www/pay.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ <h5 class='page-card-head text-center'>
class='btn btn-primary btn-sm btn-block'
style='display: none;'
></a>
<p class="text-center small my-3" style="display: none;" id="action-redirect-message">{{ _("Redirecting in") }} <span id="action-redirect-message-seconds">10</span> {{ _("seconds") }}</p>
{{ gateway_wrapper }}
</div>
{% endif %}
Expand Down
15 changes: 15 additions & 0 deletions payments/www/pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,20 @@ $(document).on("payment-processed", function (e, r) {
cta.attr("href", r.message.action.href)
cta.toggle(true)
cta.focus()
if (r.message.action.redirect_after_milliseconds) {
const message = $("#action-redirect-message");
const secondsCounter = $("#action-redirect-message-seconds");
let seconds = Math.floor(r.message.action.redirect_after_milliseconds / 1000);
secondsCounter.html(seconds);
function updateCounter() {
seconds--;
secondsCounter.html(seconds);
}
message.toggle(true)
setInterval(updateCounter, 1000);
setTimeout(function() {
window.location.href = r.message.action.href
}, r.message.action.redirect_after_milliseconds);
}
}
})

0 comments on commit e5a9d14

Please sign in to comment.