-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
18,468 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ public/spree | |
.ruby-gemset | ||
gemfiles/*.gemfile.lock | ||
vendor/cache | ||
.byebug_history | ||
.byebug_history | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ruby 3.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions
44
app/assets/javascripts/vpago/vpago_payments/request_process_payment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.