All Collections
Developers
Generating a _ZapietID
Generating a _ZapietID
Sam Forde avatar
Written by Sam Forde
Updated over a week ago

We use _ZapietID to generate rates for a checkout method. To use the rates feature in custom implementations of Zapiet - Pickup + Delivery, you will need to get a valid _ZapietId.


Getting the _ZapietId

This code will work only on widget version 1 and above.

function encodeZapietId(params) {
return Object.keys(params)
.filter(function (key) {
return !!params[key];
})
.map(function (key) {
return key + '=' + params[key];
})
.join('&');
}
function getMethodKey(method) {
if (method == 'delivery') {
return 'D';
}
if (method == 'pickup') {
return 'P';
}
return 'S';
}
function getZapietId(params) {
var formatted_date = '';
if (params.date && !params.time) {
formatted_date = params.date.replace(/\//g, '-');
formatted_date = formatted_date + 'T00:00:00Z';
} else if (params.date && params.start_time) {
formatted_date = params.date.replace(/\//g, '-');
formatted_date = formatted_date + 'T' + params.start_time + ':00Z';
}
return encodeZapietId({
M: getMethodKey(params.method),
L: params.location_id ? params.location_id : '',
D: formatted_date,
P: '',
});
}
Did this answer your question?