![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@prestashopcorp/billing-cdc
Advanced tools
A component allowing easy integration of Prestashop Billing component, to create SaaS module.
This library allows you to display a subscription manager for the merchant which use your module.
<head>
<script src="https://unpkg.com/@prestashopcorp/billing-cdc@0.0.7/dist/bundle.js"></script>
</head>
<body>
<div id="ps-billing"></div>
<div id="ps-modal"></div>
<script>
const context = {
// see bellow information about context
}
window.psBilling.initialize(context, '#ps-billing', '#ps-modal', (type, data) => {
// Event hook listener
switch(type) {
case window.psBilling.EVENT_HOOK_TYPE.SUBSCRIPTION_UPDATED:
console.log('Sub updated', data);
break;
case window.psBilling.EVENT_HOOK_TYPE.SUBSCRIPTION_CANCELLED:
console.log('Sub cancelled', data);
break;
}
});
</script>
</body>
The methods initialize
takes 3 parameters :
object
): which giv toe the library some information about the shopstring
): the id of the div where the billing component should appearstring
): the id of the div where the modal component should appearHere is the data you need to pass through the context variable
Attribut | Type | Value | Example |
---|---|---|---|
emailSupport | string | Email to contact yout support (required) | support@your-company.com |
moduleName | string | Technical name of your module (required) | ps_metrics |
versionModule | string | Module's version | 0.0.1 |
versionPs | string | Prestashop's version | 1.7.8 |
accountApi | string | API to retrieve your Prestashop Account. You can get it dynamically in window.contextPsAccounts.adminAjaxLink (required) | https://my-shop.com/ps-admin/index.php?controller=AdminAjaxPsAccounts&ajax=1&token=1247657657657 |
shop.uuid | string | Uuid of the merchant shop (required) | Mn6ou86uATRBrtYjFUnkZf6Fc5e2 |
i18n.isoCode | string | Current lang of the merchant (required) | fr |
user.createdFromIp | string | Merchant ip address (required) | 12.34.56.78 |
user.email | string | Merchant's email (required) | user@mail.com |
Here is a full example :
{
"emailSupport": "support@your-company.com",
"moduleName": "ps_metrics",
"versionModule": "0.0.1",
"versionPs": "1.7.8",
"accountApi": "https://my-shop.com/ps-admin/index.php?controller=AdminAjaxPsAccounts&ajax=1&token=1247657657657",
"shop": {
"uuid": "Mn6ou86uATRBrtYjFUnkZf6Fc5e2"
},
"i18n": {
"isoCode": "fr"
},
"user": {
"createdFromIp": "12.34.56.78",
"email": "user@mail.com"
}
}
import Vue from 'vue';
import { CustomerComponent, ModalContainerComponent, EVENT_HOOK_TYPE } from "@prestashopcorp/billing-cdc/dist/bundle.umd";
Vue.component('app', {
data: function () {
return {
billingContext: window.psBillingContext,
modalType: '',
}
},
template: `<template>
<div>
<!-- You should add PsAccount: https://www.npmjs.com/package/prestashop_accounts_vue_components -->
<PsAccounts>
...
</PsAccounts>
<ps-billing-customer
v-if="billingContext.user.email"
ref="psBillingCustomerRef"
:context="billingContext"
:onOpenModal="openBillingModal"
/>
<ps-billing-modal
v-if="modalType !== ''"
:context="billingContext"
:type="modalType"
:onCloseModal="closeBillingModal"
:onEvent
/>
</div>
</template>`,
components: {
PsBillingCustomer: CustomerComponent.driver('vue', Vue),
PsBillingModal: ModalContainerComponent.driver('vue', Vue),
},
methods: {
openBillingModal(type, data) {
this.modalType = type;
this.billingContext = { ...billingContext, ...data };
},
closeBillingModal(data) {
this.modalType = '';
this.$refs.psBillingCustomerRef.parent.updateProps({
context: {
...this.context,
...data
}
});
},
eventHookHandler(type, data) {
switch(type) {
case EVENT_HOOK_TYPE.SUBSCRIPTION_UPDATED:
// Do what you want to do on sub update
break;
case EVENT_HOOK_TYPE.SUBSCRIPTION_CANCELLED:
// Do what you want to do on sub cancel
break;
}
}
}
}
});
var vm = new Vue({
el: '#container'
});
FAQs
Cross domain component for the billing UI app
The npm package @prestashopcorp/billing-cdc receives a total of 468 weekly downloads. As such, @prestashopcorp/billing-cdc popularity was classified as not popular.
We found that @prestashopcorp/billing-cdc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.