mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
add onApprove endpoint to store order in session
This commit is contained in:
parent
7c2bc5a8da
commit
5824a40a08
10 changed files with 128 additions and 13 deletions
|
@ -1,4 +1,4 @@
|
|||
|
||||
import onApprove from "./onApprove";
|
||||
|
||||
class CartConfig {
|
||||
|
||||
|
@ -26,12 +26,9 @@ class CartConfig {
|
|||
return data.data.id;
|
||||
});
|
||||
}
|
||||
const onApprove = (data, actions) => {
|
||||
return actions.redirect(this.config.redirect);
|
||||
}
|
||||
return {
|
||||
createOrder,
|
||||
onApprove,
|
||||
onApprove:onApprove(this),
|
||||
onError: (error) => {
|
||||
this.errorHandler.message(error);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import ButtonsToggleListener from "./ButtonsToggleListener";
|
||||
import Product from "./Product";
|
||||
import onApprove from "./onApprove";
|
||||
class SingleProductConfig {
|
||||
|
||||
constructor(
|
||||
|
@ -29,12 +30,10 @@ class SingleProductConfig {
|
|||
);
|
||||
observer.init();
|
||||
}
|
||||
const onApprove = (data, actions) => {
|
||||
return actions.redirect(this.config.redirect);
|
||||
}
|
||||
|
||||
return {
|
||||
createOrder: this.createOrder(),
|
||||
onApprove,
|
||||
onApprove: onApprove(this),
|
||||
onError: (error) => {
|
||||
this.errorHandler.message(error);
|
||||
}
|
||||
|
@ -123,5 +122,4 @@ class SingleProductConfig {
|
|||
return this.formElement.classList.contains('grouped_form');
|
||||
}
|
||||
}
|
||||
|
||||
export default SingleProductConfig;
|
22
modules.local/ppcp-button/resources/js/modules/onApprove.js
Normal file
22
modules.local/ppcp-button/resources/js/modules/onApprove.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const onApprove = (context) => {
|
||||
return (data, actions) => {
|
||||
return fetch(context.config.ajax.approve_order.endpoint, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
nonce: context.config.ajax.approve_order.nonce,
|
||||
order_id:data.orderID
|
||||
})
|
||||
}).then((res)=>{
|
||||
return res.json();
|
||||
}).then((data)=>{
|
||||
if (!data.success) {
|
||||
//Todo: Error handling
|
||||
return;
|
||||
}
|
||||
location.href = context.config.redirect;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default onApprove;
|
Loading…
Add table
Add a link
Reference in a new issue