Skip to content

Commit

Permalink
Add vpago_payments UI
Browse files Browse the repository at this point in the history
  • Loading branch information
theachoem committed Feb 28, 2025
1 parent a1c7d1a commit 6f943f5
Show file tree
Hide file tree
Showing 22 changed files with 18,468 additions and 74 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public/spree
.ruby-gemset
gemfiles/*.gemfile.lock
vendor/cache
.byebug_history
.byebug_history
node_modules/
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 3.2.0
2 changes: 2 additions & 0 deletions app/assets/config/spree_vpago_manifest.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
//= link_tree ../images
//= link vpago/vpago_payments/request_process_payment.js
//= link vpago/vpago_payments/user_informers/firebase.js
3 changes: 3 additions & 0 deletions app/assets/images/backend-process.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
async function requestProcessPayment({
params,
url,
maxRetries = 5,
retryDelayMs = 1000,
}) {
let attempt = 0;
const delay = () =>
new Promise((resolve) => setTimeout(resolve, retryDelayMs));

while (attempt < maxRetries) {
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-CSRF-Token": document
.querySelector('meta[name="csrf-token"]')
.getAttribute("content"),
},
body: JSON.stringify(params),
});

if (!response.ok) {
throw new Error(`Request failed with status: ${response.status}`);
}

console.log("Request succeeded:", await response.json());
break;
} catch (error) {
attempt++;
console.error(`Attempt ${attempt} failed: ${error.message}`);

if (attempt === maxRetries) {
console.error("Max retries reached. Request failed.");
} else {
console.log("Retrying...");
await delay();
}
}
}
}

window.requestProcessPayment = requestProcessPayment;
Loading

0 comments on commit 6f943f5

Please sign in to comment.