Last active
December 6, 2024 16:50
-
-
Save HallexCosta/ae375d1403abdb0c20adc9161a045439 to your computer and use it in GitHub Desktop.
openpix-sdk-cofiguration.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
console.log(window.$openpixSDK) | |
window.$openpixSDK.addEvent('beforeCreateCharge', async (nextFn, products, productId) => { | |
console.log('beforeHook inside Called') | |
console.log({ nextFn, products, productId }) | |
const order = await createOrderWC(products.get(productId)) | |
if (!order) { | |
return | |
} | |
const orderId = order.orderId | |
const oldProductOrder = window.$openpixSDK.get(productId, 'products') | |
console.log({oldProductOrder}) | |
window.$openpixSDK.updateIn(productId, 'products', { | |
...oldProductOrder, | |
orderId, | |
comment: `WooCoommerce #${orderId}`, | |
additionalInfo: `orderId:${orderId},productId:${productId},${oldProductOrder.additionalInfo}`, | |
productId | |
}) | |
console.log('calling nextFn') | |
return nextFn() | |
}) | |
async function createOrderWC(order) { | |
// ...logic to create order in external application | |
await new Promise(resolve => setTimeout(resolve, 2000)) | |
return { | |
orderId: Math.random() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment