diff --git a/plugins/beckn-bpp-adapter/server/mappings/context.jsonata b/plugins/beckn-bpp-adapter/server/mappings/context.jsonata index fa9a4237..c2852716 100644 --- a/plugins/beckn-bpp-adapter/server/mappings/context.jsonata +++ b/plugins/beckn-bpp-adapter/server/mappings/context.jsonata @@ -15,8 +15,8 @@ "action": $action, "timestamp": $moment().toISOString(), "version": "1.1.0", - "bap_uri": bap_uri, - "bap_id": bap_id, + "bap_uri": bap_uri ? bap_uri : "http://34.93.45.226:8081/bap/receiver", + "bap_id": bap_id ? bap_id : "sandbox-retail-np1.com", "bpp_id": $env.BPP_ID, "bpp_uri": $env.BPP_URI } diff --git a/plugins/beckn-bpp-adapter/server/mappings/on_search.jsonata b/plugins/beckn-bpp-adapter/server/mappings/on_search.jsonata index bcca63f0..c1db3b5f 100644 --- a/plugins/beckn-bpp-adapter/server/mappings/on_search.jsonata +++ b/plugins/beckn-bpp-adapter/server/mappings/on_search.jsonata @@ -70,6 +70,12 @@ $string($v.location_id.id) })[] : [], + "xinput": { + "form": { + "url": $xInput(%.%.context), + "mime_type": "text/html" + } + }, "tags": $tags(cat_attr_tag_relations), "time": { "duration": service.time_slot_per_client_in_min ? $string(service.time_slot_per_client_in_min) : "" diff --git a/plugins/beckn-bpp-adapter/server/services/confirm/commerce-workflow-service.ts b/plugins/beckn-bpp-adapter/server/services/confirm/commerce-workflow-service.ts index e8f106db..133d5327 100644 --- a/plugins/beckn-bpp-adapter/server/services/confirm/commerce-workflow-service.ts +++ b/plugins/beckn-bpp-adapter/server/services/confirm/commerce-workflow-service.ts @@ -112,16 +112,18 @@ export default ({ strapi }: { strapi: Strapi }) => ({ order_transaction_id: transaction_id, publishedAt: isoString, domain, - bap_id, - bap_uri, + bap_id: bap_id ? bap_id : "sandbox-retail-np1.com", + bap_uri: bap_uri ? bap_uri : "http://34.93.45.226:8081/bap/receiver", currency: payments?.[0]?.params?.amount || "INR", total_amount: payments?.[0]?.params?.amount || 100, transaction_id: payments?.[0]?.id }; + console.log("orderData ==>>>>>>", orderData); // Create order createOrder = await strapi.entityService.create("api::order.order", { data: orderData }); + console.log("createOrder ==>>>>>>", createOrder); orderId = createOrder.id; // Create order address @@ -207,12 +209,14 @@ export default ({ strapi }: { strapi: Strapi }) => ({ // Update the order with the modified tags console.log("Orderis", orderId); - await strapi.entityService.update("api::order.order", orderId, { + const updateOrder = await strapi.entityService.update("api::order.order", orderId, { data: { tags: items // Assuming 'items' is a writable field; adjust based on your Strapi schema } }); + console.log("updateOrder ==>>>>>>", updateOrder); + strapi.log.info( `Order ${orderId} has been successfully updated with tag IDs.` ); @@ -230,11 +234,11 @@ export default ({ strapi }: { strapi: Strapi }) => ({ ...billingInfo, publishedAt: isoString }; - await strapi.entityService.create( + const createOrderAddress = await strapi.entityService.create( "api::order-address.order-address", { data: orderAddressData } ); - + console.log("createOrderAddress ==>>>>>>", createOrderAddress); // Find or create customer const [existingCustomer] = await strapi.entityService.findMany( "api::customer.customer", @@ -254,6 +258,7 @@ export default ({ strapi }: { strapi: Strapi }) => ({ "api::order-fulfillment-location.order-fulfillment-location", { data: shippingDetail } ); + console.log("createShipping ==>>>>>>", createShipping); const stopsIds = [createShipping.id]; if (endLocationDetail) { @@ -301,11 +306,13 @@ export default ({ strapi }: { strapi: Strapi }) => ({ "api::order-fulfillment.order-fulfillment", { data: orderFulfillmentDetail } ); + console.log("orderFulfillmentRes ==>>>>>>", orderFulfillmentRes); orderFulFillmentId = orderFulfillmentRes.id; await onConfirm(message); trx.commit(); } catch (err) { + console.log("err ==>>>>>>", JSON.stringify(err.details, null, 2)); trx.rollback(); } }); @@ -397,6 +404,7 @@ export default ({ strapi }: { strapi: Strapi }) => ({ populate } ); + console.log("itemDetails ==>>>>>>", itemDetails); const commonService = strapi.plugin(PLUGIN).service("commonService"); await Promise.all( itemDetails.map(async (itemDetail) => { @@ -432,6 +440,7 @@ export default ({ strapi }: { strapi: Strapi }) => ({ fulfilment_id: {} } ); + console.log("orderFulfillment ==>>>>>>", orderFulfillment); const billingDetails = billing; const fulfillmentDetails = fulfillments; diff --git a/plugins/beckn-bpp-adapter/server/services/webhook/webhook-service.ts b/plugins/beckn-bpp-adapter/server/services/webhook/webhook-service.ts index 0d87b1b0..80624b5e 100644 --- a/plugins/beckn-bpp-adapter/server/services/webhook/webhook-service.ts +++ b/plugins/beckn-bpp-adapter/server/services/webhook/webhook-service.ts @@ -11,7 +11,7 @@ export default ({ strapi: any }: { strapi: Strapi }) => ({ async index(body, domain) { try { const dummyProvider = { - DOMAIN: "Retail", + DOMAIN: "Retail:dev", provider_name: "Sample Provider", provider_short_desc: "Your one-stop shop for daily essentials.", provider_long_desc: diff --git a/plugins/beckn-bpp-adapter/server/tl/tl.helper.ts b/plugins/beckn-bpp-adapter/server/tl/tl.helper.ts index 0cc56aed..66feb1d5 100644 --- a/plugins/beckn-bpp-adapter/server/tl/tl.helper.ts +++ b/plugins/beckn-bpp-adapter/server/tl/tl.helper.ts @@ -23,25 +23,32 @@ export const context = async (data: any, action: string) => { }; export const xInput = async (context: KeyValuePair) => { + console.log("context====>", context, "\n\n\n"); const { action, domain } = context; let formId; - if (action === "init" && domain === "dsep:scholarships") { + if ( + action === "init" && + domain === `dsep:scholarships:${process.env.BECKN_ENV}` + ) { formId = "dsepScholarshipDetailsForm"; - } else if (action === "init" && domain === "dsep:jobs") { + } else if ( + action === "init" && + domain === `dsep:jobs:${process.env.BECKN_ENV}` + ) { formId = "dsepJobsApplyForm"; } else if ( - action === "select" && - domain === "online-dispute-resolution:0.1.0" + (action === "select" || action === "search") && + domain === `online-dispute-resolution:0.1.0:${process.env.BECKN_ENV}` ) { formId = "odrDisputeDetailsForm"; } else if ( action === "init" && - domain === "online-dispute-resolution:0.1.0" + domain === `online-dispute-resolution:0.1.0:${process.env.BECKN_ENV}` ) { formId = "odrConsentForm"; } else if ( action === "select" && - domain === "supply-chain-services:assembly" + domain === `supply-chain-services:assembly:${process.env.BECKN_ENV}` ) { formId = "industryAssemblyDetailsForm"; } else if (action === "rating" && isMobility(context)) { @@ -90,16 +97,17 @@ export const quote = async (items: KeyValuePair[]) => { // Domain-specific base price name mappings const domainBasePriceNames = { - "Retail": "Item Price", - "dhp:pharmacy:0.1.0": "Item Price", - "supply-chain-services:assembly": "Base Price", - "mobility:1.1.0": "Base Fare", - "tourism": "Sub Total", - "dsep:courses": "Course Fee", - "hospitality": "Room Tariff", - "retail:1.1.0": "Item Price", - "uei:p2p_trading": "P2P Energy Cost", - "uei:charging": "Cost of Charge" + "Retail:dev": "Base Price", + "dhp:pharmacy:0.1.0:dev": "Base Price", + "supply-chain-services:assembly:dev": "Base Price", + "mobility:1.1.0:dev": "Base Fare", + "tourism:dev": "Sub Total", + "dsep:courses:dev": "Course Fee", + "hospitality:dev": "Room Tariff", + "retail:1.1.0:dev": "Base Price", + "uei:p2p_trading:dev": "P2P Energy Cost", + "uei:charging:dev": "Cost of Charge", + "retail:1.1.0": "Base Price" }; export const quotePrice = async ( @@ -141,9 +149,9 @@ export const quotePrice = async ( title: price_bareakup_id.title, price: { currency: price_bareakup_id.currency, - value: adjustedValue.toString(), + value: adjustedValue.toString() }, - item: { id: `${item.id || ""}` }, + item: { id: `${item.id || ""}` } }); }); @@ -153,9 +161,9 @@ export const quotePrice = async ( title: basePriceName, price: { currency: scProduct.currency, - value: (Number(scProduct.base_fee) * selectedQuantity).toString(), + value: (Number(scProduct.base_fee) * selectedQuantity).toString() }, - item: { id: `${item.id || ""}` }, + item: { id: `${item.id || ""}` } }); } } else { @@ -166,6 +174,8 @@ export const quotePrice = async ( } }); + console.log("Items Final====>", JSON.stringify(items, null, 2)); + // Calculate total priceValue as sum of all breakup.price.value plus any base_fee values const breakupPriceValue = breakup.reduce( (accumulator, currentValue) => @@ -176,9 +186,9 @@ export const quotePrice = async ( return { price: { value: (breakupPriceValue + totalPriceValue).toString(), - currency: items?.[0]?.sc_retail_product?.currency, + currency: items?.[0]?.sc_retail_product?.currency }, - breakup, + breakup }; }; diff --git a/plugins/beckn-bpp-adapter/server/tl/tl.service.ts b/plugins/beckn-bpp-adapter/server/tl/tl.service.ts index 7155b09c..ad6cad16 100644 --- a/plugins/beckn-bpp-adapter/server/tl/tl.service.ts +++ b/plugins/beckn-bpp-adapter/server/tl/tl.service.ts @@ -1,21 +1,36 @@ import jsonata from "jsonata"; -import path from 'path'; +import path from "path"; import appRootPath from "app-root-path"; -import fs from 'fs'; +import fs from "fs"; import { ObjectUtil } from "../util/object.util"; -import * as tlHelpers from './tl.helper' +import * as tlHelpers from "./tl.helper"; export class TLService { - static async transform(data: any, action: string) { - - if (action) { - const expression = jsonata(fs.readFileSync(path.join(appRootPath.toString(), `/server/mappings/${action}.jsonata`), "utf8")); - console.log("Transforming %s data: \n%o", action, JSON.stringify(data)); - let transformed = await expression.evaluate(data, { action, ...tlHelpers }); - transformed = ObjectUtil.removeEmptyObjectKeys(transformed) - console.log("Transformed %s data: \n%o", action, JSON.stringify(transformed)); - return transformed; - } - return {}; + static async transform(data: any, action: string) { + if (action) { + const expression = jsonata( + fs.readFileSync( + path.join( + appRootPath.toString(), + `/server/mappings/${action}.jsonata` + ), + "utf8" + ) + ); + // console.log("Transforming %s data: \n%o", action, JSON.stringify(data)); + console.log(`Transforming ${action} data: \n${JSON.stringify(data)}`); + let transformed = await expression.evaluate(data, { + action, + ...tlHelpers + }); + transformed = ObjectUtil.removeEmptyObjectKeys(transformed); + console.log( + "Transformed %s data: \n%o", + action, + JSON.stringify(transformed) + ); + return transformed; } + return {}; + } } diff --git a/plugins/beckn-bpp-adapter/server/util/search.util.ts b/plugins/beckn-bpp-adapter/server/util/search.util.ts index 4be428e8..26f345e5 100644 --- a/plugins/beckn-bpp-adapter/server/util/search.util.ts +++ b/plugins/beckn-bpp-adapter/server/util/search.util.ts @@ -103,56 +103,57 @@ export class SearchUtil { filteredProviders = []; } } else if (isTourism(context)) { - let checkInReq: KeyValuePair | null = null; - fulfillment?.stops.map((fulfillmentStop: KeyValuePair) => { - if (fulfillmentStop?.type?.toLowerCase() === CHECK_IN) { - checkInReq = fulfillmentStop; - } - }); - if (checkInReq) { - filteredProviders = providers.filter((providerItem: KeyValuePair) => { - providerItem.items = providerItem.items.filter( - (item: KeyValuePair) => { - let checkInItem: any = null; - item?.item_fulfillment_ids?.forEach( - (fulfillment: KeyValuePair) => { - if ( - fulfillment?.fulfilment_id?.type?.toLowerCase() === CHECK_IN - ) { - checkInItem = fulfillment; - } - } - ); - const checkInGps = checkInReq?.location?.gps.split(",") || []; - const itemGps = checkInItem?.location_id?.gps.split(",") || []; - const checkInLat = checkInGps[0]; - const checkInLong = checkInGps[1]; - const itemLat = itemGps[0]; - const itemLong = itemGps[1]; - console.log( - moment(checkInReq?.time?.timestamp).format("YYYY-MM-DD"), - moment(checkInItem?.timestamp).format("YYYY-MM-DD"), - checkInGps.length && - itemGps.length && - !isInRange(checkInLat, checkInLong, itemLat, itemLong) - ); - if ( - moment(checkInReq?.time?.timestamp).format("YYYY-MM-DD") !== - moment(checkInItem?.timestamp).format("YYYY-MM-DD") || - (checkInGps.length && - itemGps.length && - !isInRange(checkInLat, checkInLong, itemLat, itemLong)) - ) { - return false; - } - return true; - } - ); - return providerItem.items.length > 0; - }); - } else { - filteredProviders = []; - } + // let checkInReq: KeyValuePair | null = null; + // fulfillment?.stops?.map((fulfillmentStop: KeyValuePair) => { + // if (fulfillmentStop?.type?.toLowerCase() === CHECK_IN) { + // checkInReq = fulfillmentStop; + // } + // }); + // if (checkInReq) { + // filteredProviders = providers.filter((providerItem: KeyValuePair) => { + // providerItem.items = providerItem.items.filter( + // (item: KeyValuePair) => { + // let checkInItem: any = null; + // item?.item_fulfillment_ids?.forEach( + // (fulfillment: KeyValuePair) => { + // if ( + // fulfillment?.fulfilment_id?.type?.toLowerCase() === CHECK_IN + // ) { + // checkInItem = fulfillment; + // } + // } + // ); + // const checkInGps = checkInReq?.location?.gps.split(",") || []; + // const itemGps = checkInItem?.location_id?.gps.split(",") || []; + // const checkInLat = checkInGps[0]; + // const checkInLong = checkInGps[1]; + // const itemLat = itemGps[0]; + // const itemLong = itemGps[1]; + // console.log( + // moment(checkInReq?.time?.timestamp).format("YYYY-MM-DD"), + // moment(checkInItem?.timestamp).format("YYYY-MM-DD"), + // checkInGps.length && + // itemGps.length && + // !isInRange(checkInLat, checkInLong, itemLat, itemLong) + // ); + // if ( + // moment(checkInReq?.time?.timestamp).format("YYYY-MM-DD") !== + // moment(checkInItem?.timestamp).format("YYYY-MM-DD") || + // (checkInGps.length && + // itemGps.length && + // !isInRange(checkInLat, checkInLong, itemLat, itemLong)) + // ) { + // return false; + // } + // return true; + // } + // ); + // return providerItem.items.length > 0; + // }); + // } else { + // filteredProviders = []; + // } + return providers; } else if (isMobility(context)) { let customerLocation: KeyValuePair | null = null; fulfillment?.stops.map((fulfillmentStop: KeyValuePair) => { diff --git a/plugins/driver-app/contstants.ts b/plugins/driver-app/contstants.ts index feceba4f..10900ff8 100644 --- a/plugins/driver-app/contstants.ts +++ b/plugins/driver-app/contstants.ts @@ -1,6 +1,10 @@ import pluginPkg from "./package.json"; +import dotenv from "dotenv"; export const PLUGIN: string = pluginPkg.strapi.name; -export const MOBILITY_DOMAIN = "mobility:1.1.0"; + +export const MOBILITY_DOMAIN = `mobility:1.1.0${ + process.env.BECKN_ENV ? `:${process.env.BECKN_ENV}` : "" +}`; export enum RIDE_STATUS_CODE { AWAITING_DRIVER_APPROVAL = "AWAITING_DRIVER_APPROVAL", RIDE_ACCEPTED = "RIDE_ACCEPTED",