0.0.4 • Published 8 months ago
beta-package-of-my-checkout v0.0.4
beta-package-of-my-checkout
Introduction
Beta package of my-checkout.
The primary purpose of this beta package is testing and to obtain feedback.
!!! Should not be used in production !!!
How to use
TypeScript example
Install package and import:
import * as mycheckout from 'beta-package-of-my-checkout';
Instantiate MyCheckout class:
let myCheckout = new mycheckout.MyCheckout(initData, 'container-my-checkout', { /* options */ });
Show my-checkout in container-my-checkout
:
myCheckout.show({ /* options */ });
What is initData?
Before being able to use MyCheckout class, an API request to Direct mycheckouts
endpoint needs to be sent:
POST https://payment.preprod.direct.worldline-solutions.com/v2/***merchant***/mycheckouts
with at least the following mandatory fields:
{
"myCheckoutSpecificInput": {
"countryCode": "BE",
"locale": "en-gb",
"returnUrl": "https://merchant.return.url"
},
"order": {
"amountOfMoney": {
"amount": 7000,
"currencyCode": "EUR"
},
"references": {
"merchantReference": "unique-merchant-reference"
}
}
}
The response will contain 3 fields:
initData
: pass this as the first argument of MyCheckout constructor.myCheckoutId
: keep this reference linked to your order.returnMac
: keep this value for comparison receiving redirection to your webshop.
In the HTML
In your HTML page, add:
<script type="text/javascript">
globalThis.createTokenizer = (url, containerId, opt) => new Tokenizer(url, containerId, opt);
</script>
<script type="importmap">
{
"imports": {
"beta-package-of-my-checkout": "https://url.to.mycheckout.js"
}
}
</script>
The import map allows the browser to know which file to load when parsing the import:
import * as mycheckout from 'beta-package-of-my-checkout';
The globalThis.createTokenizer
is temporary and won't be necessary in the future (work in progress).