Skip to content

Instantly share code, notes, and snippets.

@HallexCosta
Last active December 6, 2024 16:50
Show Gist options
  • Save HallexCosta/ae375d1403abdb0c20adc9161a045439 to your computer and use it in GitHub Desktop.
Save HallexCosta/ae375d1403abdb0c20adc9161a045439 to your computer and use it in GitHub Desktop.
openpix-sdk-cofiguration.js
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