Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add integration with: Ebay (ecommerce) #709

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions packages/api/scripts/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ CREATE TABLE connector_sets
fs_sharepoint boolean NULL,
fs_onedrive boolean NULL,
crm_salesforce boolean NULL,
ecom_ebay boolean NULL,
CONSTRAINT PK_project_connector PRIMARY KEY ( id_connector_set )
);

Expand Down
8 changes: 4 additions & 4 deletions packages/api/scripts/seed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ INSERT INTO users (id_user, identification_strategy, email, password_hash, first
('0ce39030-2901-4c56-8db0-5e326182ec6b', 'b2c','local@panora.dev', '$2b$10$Y7Q8TWGyGuc5ecdIASbBsuXMo3q/Rs3/cnY.mLZP4tUgfGUOCUBlG', 'local', 'Panora');


INSERT INTO connector_sets (id_connector_set, crm_hubspot, crm_zoho, crm_pipedrive, crm_attio, crm_zendesk, crm_close, tcg_zendesk, tcg_gorgias, tcg_front, tcg_jira, tcg_gitlab, fs_box, tcg_github, hris_deel, hris_sage, ats_ashby, crm_microsoftdynamicssales, ecom_webflow, tcg_linear, ecom_shopify, ecom_woocommerce, ecom_amazon, ecom_squarespace, hris_gusto, fs_googledrive, fs_dropbox, fs_sharepoint, fs_onedrive, crm_salesforce) VALUES
('1709da40-17f7-4d3a-93a0-96dc5da6ddd7', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('852dfff8-ab63-4530-ae49-e4b2924407f8', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('aed0f856-f802-4a79-8640-66d441581a99', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);
INSERT INTO connector_sets (id_connector_set, crm_hubspot, crm_zoho, crm_pipedrive, crm_attio, crm_zendesk, crm_close, tcg_zendesk, tcg_gorgias, tcg_front, tcg_jira, tcg_gitlab, fs_box, tcg_github, hris_deel, hris_sage, ats_ashby, crm_microsoftdynamicssales, ecom_webflow, tcg_linear, ecom_shopify, ecom_woocommerce, ecom_amazon, ecom_squarespace, hris_gusto, fs_googledrive, fs_dropbox, fs_sharepoint, fs_onedrive, crm_salesforce, ecom_ebay) VALUES
('1709da40-17f7-4d3a-93a0-96dc5da6ddd7', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('852dfff8-ab63-4530-ae49-e4b2924407f8', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('aed0f856-f802-4a79-8640-66d441581a99', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

INSERT INTO projects (id_project, name, sync_mode, id_user, id_connector_set) VALUES
('1e468c15-aa57-4448-aa2b-7fed640d1e3d', 'Project 1', 'pull', '0ce39030-2901-4c56-8db0-5e326182ec6b', '1709da40-17f7-4d3a-93a0-96dc5da6ddd7'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { EbayOrderInput, EbayOrderOutput } from '@ecommerce/order/services/ebay/types';

import { EbayProductInput, EbayProductOutput } from '@ecommerce/product/services/ebay/types';

/* INPUT */

import { AmazonCustomerOutput } from '@ecommerce/customer/services/amazon/types';
Expand Down Expand Up @@ -67,15 +71,15 @@ export type OriginalProductInput =
| ShopifyProductInput
| WoocommerceProductInput
| SquarespaceProductInput
| WebflowProductInput;
| WebflowProductInput | EbayProductInput;

/* order */
export type OriginalOrderInput =
| ShopifyOrderInput
| WoocommerceOrderInput
| SquarespaceOrderInput
| AmazonOrderInput
| WebflowOrderInput;
| WebflowOrderInput | EbayOrderInput;

/* fulfillmentorders */
export type OriginalFulfillmentOrdersInput = ShopifyFulfillmentOrdersInput;
Expand Down Expand Up @@ -104,15 +108,15 @@ export type OriginalProductOutput =
| ShopifyProductOutput
| WoocommerceProductOutput
| SquarespaceProductOutput
| WebflowProductOutput;
| WebflowProductOutput | EbayProductOutput;

/* order */
export type OriginalOrderOutput =
| ShopifyOrderOutput
| WoocommerceOrderOutput
| SquarespaceOrderOutput
| AmazonOrderOutput
| WebflowOrderOutput;
| WebflowOrderOutput | EbayOrderOutput;

/* fulfillmentorders */
export type OriginalFulfillmentOrdersOutput = ShopifyFulfillmentOrdersOutput;
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/ecommerce/order/order.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EbayOrderMapper } from './services/ebay/mappers';
import { EbayService } from './services/ebay';
import { CoreUnification } from '@@core/@core-services/unification/core-unification.service';
import { IngestDataService } from '@@core/@core-services/unification/ingest-data.service';
import { WebhookService } from '@@core/@core-services/webhooks/panora-webhooks/webhook.service';
Expand Down Expand Up @@ -39,6 +41,8 @@ import { AmazonService } from './services/amazon';
AmazonService,
WebflowService,
WebflowOrderMapper,
EbayService,
EbayOrderMapper,
],
exports: [SyncService],
})
Expand Down
61 changes: 61 additions & 0 deletions packages/api/src/ecommerce/order/services/ebay/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { ApiResponse } from '@@core/utils/types';
import { SyncParam } from '@@core/utils/types/interface';
import { IOrderService } from '@ecommerce/order/types';
import { Injectable } from '@nestjs/common';
import { EcommerceObject } from '@panora/shared';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import { EbayOrderInput, EbayOrderOutput } from './types';

@Injectable()
export class EbayService implements IOrderService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
`${EcommerceObject.order.toUpperCase()}:${EbayService.name}`,
);
this.registry.registerService('ebay', this);
}

async sync(data: SyncParam): Promise<ApiResponse<EbayOrderOutput[]>> {
try {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: data.linkedUserId,
provider_slug: 'ebay',
vertical: 'ecommerce',
},
});

// ref: https://developer.ebay.com/api-docs/sell/fulfillment/resources/order/methods/getOrders
const resp = await axios.get(
`${connection.account_url}/sell/fulfillment/v1/order?offset=0&limit=200`,
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
},
);
const orders: EbayOrderOutput[] = resp.data.orders;
this.logger.log(`Synced ebay orders !`);

return {
data: orders,
message: 'Ebay orders retrieved',
statusCode: 200,
};
} catch (error) {
throw error;
}
}
}
119 changes: 119 additions & 0 deletions packages/api/src/ecommerce/order/services/ebay/mappers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import {
UnifiedEcommerceOrderInput,
UnifiedEcommerceOrderOutput,
} from '@ecommerce/order/types/model.unified';
import { IOrderMapper } from '@ecommerce/order/types';
import { MappersRegistry } from '@@core/@core-services/registries/mappers.registry';
import { Injectable } from '@nestjs/common';
import { CoreUnification } from '@@core/@core-services/unification/core-unification.service';
import { Utils } from '@ecommerce/@lib/@utils';
import {
EbayOrderInput,
EbayOrderOutput,
LineItemFulfillmentStatusEnum,
OrderFulfillmentStatus,
OrderPaymentStatusEnum,
} from './types';

@Injectable()
export class EbayOrderMapper implements IOrderMapper {
constructor(
private mappersRegistry: MappersRegistry,
private utils: Utils,
private coreUnificationService: CoreUnification,
) {
this.mappersRegistry.registerService('ecommerce', 'order', 'ebay', this);
}

async desunify(
source: UnifiedEcommerceOrderInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): Promise<EbayOrderInput> {
const result: Partial<EbayOrderInput> = {
orderFulfillmentStatus:
source.fulfillment_status as OrderFulfillmentStatus,
orderPaymentStatus: source.payment_status as OrderPaymentStatusEnum,
pricingSummary: {
priceSubtotal: {
currency: source.currency,
value: source.total_price.toString(),
},
priceDiscount: {
currency: source.currency,
value: source.total_discount.toString(),
},
deliveryCost: {
currency: source.currency,
value: source.total_shipping.toString(),
},
tax: {
currency: source.currency,
value: source.total_tax.toString(),
},
total: {
currency: source.currency,
value: source.total_price.toString(),
},
},
lineItems: source.items.map((item) => ({
lineItemId: item.remote_id.toString(),
quantity: item.quantity,
title: item.title,
lineItemCost: {
currency: source.currency,
value: item.price.toString(),
},
total: {
currency: source.currency,
value: item.total.toString(),
},
lineItemFulfillmentStatus:
item.fulfillment_status as LineItemFulfillmentStatusEnum,
sku: item.sku,
})),
};
return result;
}

async unify(
source: EbayOrderInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): Promise<UnifiedEcommerceOrderOutput> {
const result: UnifiedEcommerceOrderOutput = {
remote_id: source.orderId.toString(),
remote_data: source,
order_status: source.orderFulfillmentStatus,
payment_status: source.orderPaymentStatus,
currency: source.pricingSummary.total.currency,
total_price: Number(source.pricingSummary.total.value),
total_discount: Number(source.pricingSummary.priceDiscount.value),
total_shipping: Number(source.pricingSummary.deliveryCost.value),
total_tax: Number(source.pricingSummary.tax.value),
fulfillment_status: source.orderFulfillmentStatus,
items: source.lineItems.map((item) => ({
remote_id: item.lineItemId,
sku: item.sku,
quantity: item.quantity,
title: item.title,
price: item.lineItemCost.value,
total: item.total.value,
fulfillment_status: item.lineItemFulfillmentStatus,
})),
field_mappings: {},
};

if (customFieldMappings) {
for (const mapping of customFieldMappings) {
result.field_mappings[mapping.slug] = source[mapping.remote_id];
}
}

return result;
}
}
Loading
Loading