- wip payment

- already solved success and failure messages and redirection
  - solved increase date multiple times
- users redirection works if error AND partner to posts instead of project
This commit is contained in:
asus
2024-03-05 17:22:11 +01:00
parent 620aa9329b
commit 917d51a097
12 changed files with 181 additions and 154 deletions

View File

@@ -37,25 +37,30 @@ export async function onApprove(data, actions) {
} else if (!orderData.purchase_units) {
throw new Error(JSON.stringify(orderData));
} else {
// (3) Successful transaction -> Show confirmation or thank you message
// Or go to another URL: actions.redirect('thank_you.html');
const transaction =
orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
// to show a message on page
//resultMessage(`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`,);
console.log(
"Capture result",
orderData,
JSON.stringify(orderData, null, 2),
);
actions.redirect('https://local_fipfcard_plugin.com/');
try {
// (3) Successful transaction -> Show confirmation or thank you message
// Or go to another URL: actions.redirect('thank_you.html');
const transaction =
orderData?.purchase_units?.[0]?.payments?.captures?.[0] ||
orderData?.purchase_units?.[0]?.payments?.authorizations?.[0];
// to show a message on page
//resultMessage(`Transaction ${transaction.status}: ${transaction.id}<br><br>See console for all available details`);
resultMessage(eval(PLGNTLS_data.paypal_message_success));
console.log(
"Capture result",
orderData,
JSON.stringify(orderData, null, 2),
);
actions.redirect(PLGNTLS_data.paypal_redirection_success);
} catch (error) {
console.error("payment ok but error on traitment afterwards : ", error);
}
}
} catch (error) {
console.error(error);
resultMessage(
`Sorry, your transaction could not be processed...<br><br>${error}`,
);
//resultMessage(`Sorry, your transaction could not be processed...<br><br>${error}`);
resultMessage(eval(PLGNTLS_data.paypal_message_failure));
actions.redirect(PLGNTLS_data.paypal_redirection_failure);
}
}

View File

@@ -2,6 +2,8 @@
// Example function to show a result to the user. Your site's UI library can be used instead.
//function resultMessage(message) {
export function resultMessage(message) {
const buttons = document.querySelector("#paypal-button-container");
const container = document.querySelector("#result-message");
buttons.style.display = 'none';
container.innerHTML = message;
}