Skip to content

Commit 230bcfc

Browse files
committed
Add event listener for Open Collective donation success to update URL with OrderId
1 parent 4a4179d commit 230bcfc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

app/views/funds/donate.html.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@
102102

103103
<iframe src="<%= @fund.open_collective_project_embed_url(redirect_url: request.original_url) %>" style="width: 100%; min-height: 100vh;" sandbox="allow-scripts allow-top-navigation"></iframe>
104104

105+
<script>
106+
window.addEventListener('message', event => {
107+
if (event.origin.endsWith('<%= ENV['OPENCOLLECTIVE_DOMAIN'] %>')) {
108+
console.log(event);
109+
if (event.data && event.data.event === 'success') {
110+
const url = new URL(window.location.href);
111+
url.searchParams.set('OrderId', event.data.payload.order.id);
112+
window.location.href = url.toString();
113+
}
114+
}
115+
});
116+
</script>
117+
105118
</div>
106119
<div class="col-12 col-lg-4 page-content">
107120
<h3 class="mt-lg-0">How donating works</h3>

0 commit comments

Comments
 (0)