From b19789215a55b23b003d4d31b349845dd0f31012 Mon Sep 17 00:00:00 2001 From: Krzysztof Wolski Date: Wed, 26 Jul 2023 15:05:13 +0200 Subject: [PATCH] Extend the order payload for translated names, attributes and price details --- .../graphql/fragments/OrderDetails.graphql | 157 ++++++++++++++++++ .../event-handlers/default-payloads.ts | 111 +++++++++++-- .../webhook-management-service.test.ts | 2 +- 3 files changed, 251 insertions(+), 19 deletions(-) diff --git a/apps/emails-and-messages/graphql/fragments/OrderDetails.graphql b/apps/emails-and-messages/graphql/fragments/OrderDetails.graphql index e4b58acff5..455ac3ffba 100644 --- a/apps/emails-and-messages/graphql/fragments/OrderDetails.graphql +++ b/apps/emails-and-messages/graphql/fragments/OrderDetails.graphql @@ -1,7 +1,11 @@ fragment OrderDetails on Order { id number + status + languageCodeEnum userEmail + created + redirectUrl channel { slug } @@ -17,28 +21,103 @@ fragment OrderDetails on Order { email firstName lastName + languageCode } billingAddress { + firstName + lastName + companyName streetAddress1 + streetAddress2 city + cityArea postalCode country { country } + phone } shippingAddress { + firstName + lastName + companyName streetAddress1 + streetAddress2 city + cityArea postalCode country { country } + phone } lines { id + digitalContentUrl { + id + url + } + isShippingRequired + metadata { + key + value + } + privateMetadata { + key + value + } productName + translatedProductName variantName + translatedVariantName + productSku + variant { + preorder{ + endDate + } + weight{ + unit + value + } + attributes { + attribute { + id + name + slug + } + values { + id + name + slug + file { + url + contentType + } + } + } + product { + attributes { + attribute { + id + name + slug + } + values { + id + name + slug + file{ + url + contentType + } + + } + } + } + } quantity + quantityFulfilled + taxRate thumbnail { url alt @@ -48,12 +127,49 @@ fragment OrderDetails on Order { currency amount } + net { + currency + amount + } + tax { + currency + amount + } } totalPrice { gross { currency amount } + net { + currency + amount + } + tax { + currency + amount + } + } + unitDiscount { + currency + amount + } + unitDiscountReason + unitDiscountType + unitDiscountValue + undiscountedUnitPrice{ + gross { + currency + amount + } + net { + currency + amount + } + tax { + currency + amount + } } } subtotal { @@ -61,17 +177,58 @@ fragment OrderDetails on Order { amount currency } + net { + currency + amount + } + tax { + currency + amount + } } shippingPrice { gross { amount currency } + net { + currency + amount + } + tax { + currency + amount + } } total { gross { amount currency } + net { + currency + amount + } + tax { + currency + amount + } + } + undiscountedTotal { + gross { + amount + currency + } + net { + currency + amount + } + tax { + currency + amount + } } + displayGrossPrices + isShippingRequired + shippingMethodName } diff --git a/apps/emails-and-messages/src/modules/event-handlers/default-payloads.ts b/apps/emails-and-messages/src/modules/event-handlers/default-payloads.ts index bb49792d6f..5fe5521fc4 100644 --- a/apps/emails-and-messages/src/modules/event-handlers/default-payloads.ts +++ b/apps/emails-and-messages/src/modules/event-handlers/default-payloads.ts @@ -9,6 +9,8 @@ import { InvoiceSentWebhookPayloadFragment, GiftCardSentWebhookPayloadFragment, OrderRefundedWebhookPayloadFragment, + LanguageCodeEnum, + OrderStatus, } from "../../../generated/graphql"; import { NotifyPayloadAccountChangeEmailRequest, @@ -21,6 +23,11 @@ import { const exampleOrderPayload: OrderDetailsFragment = { id: "T3JkZXI6NTdiNTBhNDAtYzRmYi00YjQzLWIxODgtM2JhZmRlMTc3MGQ5", number: "198", + status: OrderStatus.Unfulfilled, + languageCodeEnum: LanguageCodeEnum.En, + created: "", + displayGrossPrices: true, + isShippingRequired: true, userEmail: "adrian.king@example.com", metadata: [ { @@ -41,9 +48,15 @@ const exampleOrderPayload: OrderDetailsFragment = { email: "adrian.king@example.com", firstName: "Adrian", lastName: "King", + languageCode: LanguageCodeEnum.En, }, billingAddress: { + firstName: "Adrian", + lastName: "King", streetAddress1: "59314 Mary Well Suite 281", + streetAddress2: "", + companyName: "", + cityArea: "", city: "METROPOLIS", postalCode: "71653", country: { @@ -51,7 +64,12 @@ const exampleOrderPayload: OrderDetailsFragment = { }, }, shippingAddress: { + firstName: "Adrian", + lastName: "King", streetAddress1: "59314 Mary Well Suite 281", + streetAddress2: "", + companyName: "", + cityArea: "", city: "METROPOLIS", postalCode: "71653", country: { @@ -73,52 +91,110 @@ const exampleOrderPayload: OrderDetailsFragment = { currency: "USD", amount: 5, }, + net: { + currency: "USD", + amount: 4, + }, + tax: { + currency: "USD", + amount: 1, + }, }, totalPrice: { gross: { currency: "USD", amount: 5, }, + net: { + currency: "USD", + amount: 4, + }, + tax: { + currency: "USD", + amount: 1, + }, }, - }, - { - id: "T3JkZXJMaW5lOjVhYmEzMTBkLTZkMzEtNDNlNy1hZjAyLTdlNGUwM2UzYmI4ZA==", - productName: "Code Division T-shirt", - variantName: "L", - quantity: 1, - thumbnail: { - url: "https://placehold.jp/150x150.png", - alt: "", + isShippingRequired: true, + translatedProductName: "Black Hoodie", + translatedVariantName: "XL", + quantityFulfilled: 0, + taxRate: 10, + unitDiscountValue: 0, + unitDiscount: { + amount: 0, + currency: "USD", }, - unitPrice: { + undiscountedUnitPrice: { gross: { currency: "USD", amount: 5, }, - }, - totalPrice: { - gross: { + net: { currency: "USD", - amount: 5, + amount: 4, + }, + tax: { + currency: "USD", + amount: 1, }, }, + metadata: [], + privateMetadata: [], }, ], subtotal: { gross: { - amount: 10, + amount: 5, + currency: "USD", + }, + net: { + amount: 4, + currency: "USD", + }, + tax: { + amount: 1, currency: "USD", }, }, shippingPrice: { gross: { - amount: 61.62, + amount: 10, + currency: "USD", + }, + net: { + amount: 8, + currency: "USD", + }, + tax: { + amount: 2, + currency: "USD", + }, + }, + undiscountedTotal: { + gross: { + amount: 15, + currency: "USD", + }, + net: { + amount: 12, + currency: "USD", + }, + tax: { + amount: 3, currency: "USD", }, }, total: { gross: { - amount: 71.62, + amount: 15, + currency: "USD", + }, + net: { + amount: 12, + currency: "USD", + }, + tax: { + amount: 3, currency: "USD", }, }, @@ -344,7 +420,6 @@ const orderLineMonospaceTeePayloadFragment: NotifyPayloadFulfillmentUpdate["orde id: "UHJvZHVjdFZhcmlhbnQ6MzQ4", weight: "", is_preorder: false, - preorder_global_threshold: null, preorder_end_date: null, first_image: { original: { diff --git a/apps/emails-and-messages/src/modules/webhook-management/webhook-management-service.test.ts b/apps/emails-and-messages/src/modules/webhook-management/webhook-management-service.test.ts index 9c2f6431d2..e3edc9005c 100644 --- a/apps/emails-and-messages/src/modules/webhook-management/webhook-management-service.test.ts +++ b/apps/emails-and-messages/src/modules/webhook-management/webhook-management-service.test.ts @@ -114,7 +114,7 @@ describe("WebhookManagementService", function () { name: invoiceSentWebhook.name, targetUrl: "https://example.com/api/webhooks/invoice-sent", query: - "subscription InvoiceSent { event { ...InvoiceSentWebhookPayload }}fragment InvoiceSentWebhookPayload on InvoiceSent { invoice { id metadata { key value } privateMetadata { key value } message externalUrl url order { id } } order { ...OrderDetails }}fragment OrderDetails on Order { id number userEmail channel { slug } metadata { key value } privateMetadata { key value } user { email firstName lastName } billingAddress { streetAddress1 city postalCode country { country } } shippingAddress { streetAddress1 city postalCode country { country } } lines { id productName variantName quantity thumbnail { url alt } unitPrice { gross { currency amount } } totalPrice { gross { currency amount } } } subtotal { gross { amount currency } } shippingPrice { gross { amount currency } } total { gross { amount currency } }}", + "subscription InvoiceSent { event { ...InvoiceSentWebhookPayload }}fragment InvoiceSentWebhookPayload on InvoiceSent { invoice { id metadata { key value } privateMetadata { key value } message externalUrl url order { id } } order { ...OrderDetails }}fragment OrderDetails on Order { id number status languageCodeEnum userEmail created redirectUrl channel { slug } metadata { key value } privateMetadata { key value } user { email firstName lastName languageCode } billingAddress { firstName lastName companyName streetAddress1 streetAddress2 city cityArea postalCode country { country } phone } shippingAddress { firstName lastName companyName streetAddress1 streetAddress2 city cityArea postalCode country { country } phone } lines { id digitalContentUrl { id url } isShippingRequired metadata { key value } privateMetadata { key value } productName translatedProductName variantName translatedVariantName productSku variant { preorder { endDate } weight { unit value } attributes { attribute { id name slug } values { id name slug file { url contentType } } } product { attributes { attribute { id name slug } values { id name slug file { url contentType } } } } } quantity quantityFulfilled taxRate thumbnail { url alt } unitPrice { gross { currency amount } net { currency amount } tax { currency amount } } totalPrice { gross { currency amount } net { currency amount } tax { currency amount } } unitDiscount { currency amount } unitDiscountReason unitDiscountType unitDiscountValue undiscountedUnitPrice { gross { currency amount } net { currency amount } tax { currency amount } } } subtotal { gross { amount currency } net { currency amount } tax { currency amount } } shippingPrice { gross { amount currency } net { currency amount } tax { currency amount } } total { gross { amount currency } net { currency amount } tax { currency amount } } undiscountedTotal { gross { amount currency } net { currency amount } tax { currency amount } } displayGrossPrices isShippingRequired shippingMethodName}", }, }); });