diff --git a/.changeset/stale-pigs-type.md b/.changeset/stale-pigs-type.md new file mode 100644 index 0000000..6c042f0 --- /dev/null +++ b/.changeset/stale-pigs-type.md @@ -0,0 +1,5 @@ +--- +"saleor-app-emails-and-messages": patch +--- + +Added new fields to the order related payload: attributes, price details, translated names diff --git a/apps/emails-and-messages/graphql/fragments/OrderDetails.graphql b/apps/emails-and-messages/graphql/fragments/OrderDetails.graphql index e4b58ac..455ac3f 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 6c54398..5fe5521 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,27 +91,13 @@ const exampleOrderPayload: OrderDetailsFragment = { currency: "USD", amount: 5, }, - }, - totalPrice: { - gross: { + net: { currency: "USD", - amount: 5, + amount: 4, }, - }, - }, - { - id: "T3JkZXJMaW5lOjVhYmEzMTBkLTZkMzEtNDNlNy1hZjAyLTdlNGUwM2UzYmI4ZA==", - productName: "Code Division T-shirt", - variantName: "L", - quantity: 1, - thumbnail: { - url: "https://placehold.jp/150x150.png", - alt: "", - }, - unitPrice: { - gross: { + tax: { currency: "USD", - amount: 5, + amount: 1, }, }, totalPrice: { @@ -101,24 +105,96 @@ const exampleOrderPayload: OrderDetailsFragment = { currency: "USD", amount: 5, }, + net: { + currency: "USD", + amount: 4, + }, + tax: { + currency: "USD", + amount: 1, + }, }, + isShippingRequired: true, + translatedProductName: "Black Hoodie", + translatedVariantName: "XL", + quantityFulfilled: 0, + taxRate: 10, + unitDiscountValue: 0, + unitDiscount: { + amount: 0, + currency: "USD", + }, + undiscountedUnitPrice: { + gross: { + currency: "USD", + amount: 5, + }, + net: { + currency: "USD", + 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", }, }, 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 9c2f643..e3edc90 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}", }, }); });