Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions plugins/beckn-bpp-adapter/server/mappings/on_confirm.jsonata
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(
$itemBody := message[0].itemsBody;
{
"context": $context(context, $action),
"message": {
Expand Down Expand Up @@ -51,6 +53,9 @@
"value": $string(stock_quantity ? stock_quantity : 0),
"unit": quantity_unit
}
},
"selected": {
"count": $itemQuantity($itemBody, %.id)
}
},
"category_ids": $map(
Expand Down Expand Up @@ -94,7 +99,7 @@
"duration": service.time_slot_per_client_in_min ? $string(service.time_slot_per_client_in_min) : ""
}
}[],
"quote": $quote(message[0].items),
"quote": $quotePrice(message[0].items, message[0].itemsBody, context),
"billing": message.billing,
"fulfillments": $map(message.fulfillment, function($elem) {
$merge([$elem, {"state":{"descriptor": {
Expand All @@ -107,4 +112,5 @@
"cancellation_terms": $cancellationTerms(message[0].items)
}
}
}
}
)
186 changes: 96 additions & 90 deletions plugins/beckn-bpp-adapter/server/mappings/on_init.jsonata
Original file line number Diff line number Diff line change
@@ -1,99 +1,105 @@
{
"context": $context(context, $action),
"message": {
"order": {
"provider": message.{
"id": $string(id),
"descriptor": {
"name": provider_name,
"short_desc": short_desc ? short_desc : "",
"long_desc": long_desc ? long_desc : "",
"additional_desc": {
"url": provider_uri
(
$itemBody := message[0].itemsBody;
{
"context": $context(context, $action),
"message": {
"order": {
"provider": message.{
"id": $string(id),
"descriptor": {
"name": provider_name,
"short_desc": short_desc ? short_desc : "",
"long_desc": long_desc ? long_desc : "",
"additional_desc": {
"url": provider_uri
},
"images": items.image.{
"url": url ? url : "https://abc.com",
"size_type": size_type ? size_type : "sm"
}[]
},
"images": items.image.{
"url": url ? url : "https://abc.com",
"size_type": size_type ? size_type : "sm"
}[]
"categories": category_ids. {
"id": $string(id),
"descriptor": {
"name": value
}
}[],
"rating": provider_rating,
"short_desc": short_desc,
"fulfillments": $fulfillments(fulfillments, items),
"locations": $locations($append(location_id, [items.item_fulfillment_ids.location_id])),
"rateable": true
},
"categories": category_ids. {
"items": message.items.{
"id": $string(id),
"descriptor": {
"name": value
}
}[],
"rating": provider_rating,
"short_desc": short_desc,
"fulfillments": $fulfillments(fulfillments, items),
"locations": $locations($append(location_id, [items.item_fulfillment_ids.location_id])),
"rateable": true
},
"items": message.items.{
"id": $string(id),
"descriptor": {
"name": name ? name : "",
"code": code ? code : "",
"short_desc": short_desc ? short_desc : "",
"long_desc": long_desc ? long_desc : "",
"images": image.{
"url": url?url:"https://abc.com",
"size_type": size_type?size_type:"sm"
}[]
},
"rating":$string(sc_retail_product.average_rating),
"rateable": true,
"price": $price(sc_retail_product),
"quantity": sc_retail_product.{
"available": {
"count": stock_quantity ? stock_quantity : 0,
"measure":{
"value": $string(stock_quantity ? stock_quantity : 0),
"unit": quantity_unit
"name": name ? name : "",
"code": code ? code : "",
"short_desc": short_desc ? short_desc : "",
"long_desc": long_desc ? long_desc : "",
"images": image.{
"url": url?url:"https://abc.com",
"size_type": size_type?size_type:"sm"
}[]
},
"rating":$string(sc_retail_product.average_rating),
"rateable": true,
"price": $price(sc_retail_product),
"quantity": sc_retail_product.{
"available": {
"count": stock_quantity ? stock_quantity : 0,
"measure":{
"value": $string(stock_quantity ? stock_quantity : 0),
"unit": quantity_unit
}
},
"selected": {
"count": $itemQuantity($itemBody, %.id)
}
},
"category_ids": $map(
$filter(cat_attr_tag_relations, function($v) { $v.taxanomy = 'CATEGORY'}),
function($v) {
$string($v.taxanomy_id.id)
}
)[],
"fulfillment_ids": $count(item_fulfillment_ids) > 0 ?
$map(item_fulfillment_ids, function($v){
$string($v.fulfilment_id.id)
})[] :
[],
"location_ids": $count(item_fulfillment_ids) > 0 ?
$map(item_fulfillment_ids, function($v){
$string($v.location_id.id)
})[] :
[],
"tags": $tags(cat_attr_tag_relations),
"xinput": {
"form": {
"url": $xInput(%.%.context),
"mime_type": "text/html"
}
},
"time": {
"duration": service.time_slot_per_client_in_min ? $string(service.time_slot_per_client_in_min) : ""
}
},
"category_ids": $map(
$filter(cat_attr_tag_relations, function($v) { $v.taxanomy = 'CATEGORY'}),
function($v) {
$string($v.taxanomy_id.id)
}
)[],
"fulfillment_ids": $count(item_fulfillment_ids) > 0 ?
$map(item_fulfillment_ids, function($v){
$string($v.fulfilment_id.id)
})[] :
[],
"location_ids": $count(item_fulfillment_ids) > 0 ?
$map(item_fulfillment_ids, function($v){
$string($v.location_id.id)
})[] :
[],
"tags": $tags(cat_attr_tag_relations),
"xinput": {
"form": {
"url": $xInput(%.%.context),
"mime_type": "text/html"
}[],
"quote": $quotePrice(message[0].items, message[0].itemsBody, context),
"billing": message.billing,
"categories": $map(message.category_ids, function($v) {
{
"id": $string($v.id),
"value": $v.value,
"createdAt": $v.createdAt,
"updatedAt": $v.updatedAt,
"publishedAt": $v.publishedAt,
"category_code": $v.category_code
}
},
"time": {
"duration": service.time_slot_per_client_in_min ? $string(service.time_slot_per_client_in_min) : ""
}
}[],
"quote": $quote(message.items),
"billing": message.billing,
"categories": $map(message.category_ids, function($v) {
{
"id": $string($v.id),
"value": $v.value,
"createdAt": $v.createdAt,
"updatedAt": $v.updatedAt,
"publishedAt": $v.publishedAt,
"category_code": $v.category_code
}
})[],
"fulfillments": $fulfillments(message.fulfillments, message.items),
"payments": $payments(message[0]),
"cancellation_terms": $cancellationTerms(message[0].items)
})[],
"fulfillments": $fulfillments(message.fulfillments, message.items),
"payments": $payments(message[0]),
"cancellation_terms": $cancellationTerms(message[0].items)
}
}
}
}
)
9 changes: 6 additions & 3 deletions plugins/beckn-bpp-adapter/server/mappings/on_select.jsonata
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
(
$itemBody := message[0].itemsBody;
{
"context": $context(context, $action),
"message": {
"order": {
Expand Down Expand Up @@ -78,7 +80,7 @@
"duration": service.time_slot_per_client_in_min ? $string(service.time_slot_per_client_in_min) : ""
}
}[],
"quote": $quote(message.items),
"quote": $quotePrice(message[0].items, message[0].itemsBody, context),
"categories": $map(message.category_ids, function($v) {
{
"id": $string($v.id),
Expand All @@ -92,4 +94,5 @@
"fulfillments": $fulfillments(message.fulfillments, message.items)
}
}
}
}
)
15 changes: 10 additions & 5 deletions plugins/beckn-bpp-adapter/server/mappings/on_status.jsonata
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

(
$tags := message.order_id.tags;
{
"context": $context(context, $action),
"message": {
"order":{
"id": $string(message.order_id.id),
"created_at": message.order_id.createdAt,
"provider": message.order_id.items.provider.{
"provider": message.order_id.items[0].provider.{
"id": $string(id),
"descriptor": {
"name": provider_name,
Expand Down Expand Up @@ -58,9 +61,10 @@
"unit": quantity_unit
}
},
"selected":{
"count":1
"selected": {
"count": $itemQuantity($tags, %.id)
}

},
"category_ids": $map(
$filter(cat_attr_tag_relations, function($v) { $v.taxanomy = 'CATEGORY'}),
Expand Down Expand Up @@ -181,9 +185,10 @@
"type": "PRE-ORDER",
"transaction_id": transaction_id
}[],
"quote": $quote(message.order_id.items),
"quote": $quotePrice(message[0].order_id.items, message[0].order_id.tags, context),
"cancellation_terms": $cancellationTerms(message.order_id.items),
"status": message.order_id.status
}
}
}
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ export default ({ strapi }: { strapi: Strapi }) => ({
}
},
order_id: orderId,
order_details: createOrder
order_details: createOrder,
// Attach itemsBody to get quantity of each items selected for order which will be used for dynamic price calculation
itemsBody: items.filter((i) => item.items.some((it) => String(it.id) === String(i.id)))

}));
if (isEnergy(context)) {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ export default ({ strapi }: { strapi: Strapi }) => ({
});
}
initDetails = initDetails.map((provider) => {
provider.items = provider.items.map((responseItem) => {
const providerItemIds = provider?.items.map((item) => String(item.id));
// Filter items that exist in provider.items
const itemsBody = items.filter((item) => providerItemIds.includes(String(item.id)));
provider.items = provider?.items.map((responseItem) => {
const bodyItem = items.find(
(item) => Number(item.id) === responseItem.id
);
Expand All @@ -182,7 +185,7 @@ export default ({ strapi }: { strapi: Strapi }) => ({
}
return responseItem;
});

provider.itemsBody = itemsBody;
return provider;
});
return initDetails;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ export default ({ strapi }: { strapi: Strapi }) => ({
itemDetails[0] = { ...itemDetails[0], ...quantitySelected };

itemDetails = itemDetails.map((provider) => {
const providerItemIds = provider?.items.map((item) => String(item.id));
// Filter items that exist in provider.items
const itemsBody = items.filter((item) =>
providerItemIds.includes(String(item.id))
);
provider.items = provider.items.map((responseItem) => {
// Find the matching item in request body by id
const bodyItem = items.find(
Expand All @@ -156,7 +161,7 @@ export default ({ strapi }: { strapi: Strapi }) => ({
}
return responseItem;
});

provider.itemsBody = itemsBody;
return provider;
});
return itemDetails;
Expand Down
Loading