Eam: Extend order payload (#816)
* Extend the order payload for translated names, attributes and price details * Add changeset
This commit is contained in:
parent
a725720920
commit
54901f8d08
4 changed files with 260 additions and 22 deletions
5
.changeset/stale-pigs-type.md
Normal file
5
.changeset/stale-pigs-type.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"saleor-app-emails-and-messages": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Added new fields to the order related payload: attributes, price details, translated names
|
|
@ -1,7 +1,11 @@
|
||||||
fragment OrderDetails on Order {
|
fragment OrderDetails on Order {
|
||||||
id
|
id
|
||||||
number
|
number
|
||||||
|
status
|
||||||
|
languageCodeEnum
|
||||||
userEmail
|
userEmail
|
||||||
|
created
|
||||||
|
redirectUrl
|
||||||
channel {
|
channel {
|
||||||
slug
|
slug
|
||||||
}
|
}
|
||||||
|
@ -17,28 +21,103 @@ fragment OrderDetails on Order {
|
||||||
email
|
email
|
||||||
firstName
|
firstName
|
||||||
lastName
|
lastName
|
||||||
|
languageCode
|
||||||
}
|
}
|
||||||
billingAddress {
|
billingAddress {
|
||||||
|
firstName
|
||||||
|
lastName
|
||||||
|
companyName
|
||||||
streetAddress1
|
streetAddress1
|
||||||
|
streetAddress2
|
||||||
city
|
city
|
||||||
|
cityArea
|
||||||
postalCode
|
postalCode
|
||||||
country {
|
country {
|
||||||
country
|
country
|
||||||
}
|
}
|
||||||
|
phone
|
||||||
}
|
}
|
||||||
shippingAddress {
|
shippingAddress {
|
||||||
|
firstName
|
||||||
|
lastName
|
||||||
|
companyName
|
||||||
streetAddress1
|
streetAddress1
|
||||||
|
streetAddress2
|
||||||
city
|
city
|
||||||
|
cityArea
|
||||||
postalCode
|
postalCode
|
||||||
country {
|
country {
|
||||||
country
|
country
|
||||||
}
|
}
|
||||||
|
phone
|
||||||
}
|
}
|
||||||
lines {
|
lines {
|
||||||
id
|
id
|
||||||
|
digitalContentUrl {
|
||||||
|
id
|
||||||
|
url
|
||||||
|
}
|
||||||
|
isShippingRequired
|
||||||
|
metadata {
|
||||||
|
key
|
||||||
|
value
|
||||||
|
}
|
||||||
|
privateMetadata {
|
||||||
|
key
|
||||||
|
value
|
||||||
|
}
|
||||||
productName
|
productName
|
||||||
|
translatedProductName
|
||||||
variantName
|
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
|
quantity
|
||||||
|
quantityFulfilled
|
||||||
|
taxRate
|
||||||
thumbnail {
|
thumbnail {
|
||||||
url
|
url
|
||||||
alt
|
alt
|
||||||
|
@ -48,12 +127,49 @@ fragment OrderDetails on Order {
|
||||||
currency
|
currency
|
||||||
amount
|
amount
|
||||||
}
|
}
|
||||||
|
net {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
tax {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
totalPrice {
|
totalPrice {
|
||||||
gross {
|
gross {
|
||||||
currency
|
currency
|
||||||
amount
|
amount
|
||||||
}
|
}
|
||||||
|
net {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
tax {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unitDiscount {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
unitDiscountReason
|
||||||
|
unitDiscountType
|
||||||
|
unitDiscountValue
|
||||||
|
undiscountedUnitPrice{
|
||||||
|
gross {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
net {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
tax {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
subtotal {
|
subtotal {
|
||||||
|
@ -61,17 +177,58 @@ fragment OrderDetails on Order {
|
||||||
amount
|
amount
|
||||||
currency
|
currency
|
||||||
}
|
}
|
||||||
|
net {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
tax {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
shippingPrice {
|
shippingPrice {
|
||||||
gross {
|
gross {
|
||||||
amount
|
amount
|
||||||
currency
|
currency
|
||||||
}
|
}
|
||||||
|
net {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
tax {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
total {
|
total {
|
||||||
gross {
|
gross {
|
||||||
amount
|
amount
|
||||||
currency
|
currency
|
||||||
}
|
}
|
||||||
|
net {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
tax {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
undiscountedTotal {
|
||||||
|
gross {
|
||||||
|
amount
|
||||||
|
currency
|
||||||
|
}
|
||||||
|
net {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
tax {
|
||||||
|
currency
|
||||||
|
amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
displayGrossPrices
|
||||||
|
isShippingRequired
|
||||||
|
shippingMethodName
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ import {
|
||||||
InvoiceSentWebhookPayloadFragment,
|
InvoiceSentWebhookPayloadFragment,
|
||||||
GiftCardSentWebhookPayloadFragment,
|
GiftCardSentWebhookPayloadFragment,
|
||||||
OrderRefundedWebhookPayloadFragment,
|
OrderRefundedWebhookPayloadFragment,
|
||||||
|
LanguageCodeEnum,
|
||||||
|
OrderStatus,
|
||||||
} from "../../../generated/graphql";
|
} from "../../../generated/graphql";
|
||||||
import {
|
import {
|
||||||
NotifyPayloadAccountChangeEmailRequest,
|
NotifyPayloadAccountChangeEmailRequest,
|
||||||
|
@ -21,6 +23,11 @@ import {
|
||||||
const exampleOrderPayload: OrderDetailsFragment = {
|
const exampleOrderPayload: OrderDetailsFragment = {
|
||||||
id: "T3JkZXI6NTdiNTBhNDAtYzRmYi00YjQzLWIxODgtM2JhZmRlMTc3MGQ5",
|
id: "T3JkZXI6NTdiNTBhNDAtYzRmYi00YjQzLWIxODgtM2JhZmRlMTc3MGQ5",
|
||||||
number: "198",
|
number: "198",
|
||||||
|
status: OrderStatus.Unfulfilled,
|
||||||
|
languageCodeEnum: LanguageCodeEnum.En,
|
||||||
|
created: "",
|
||||||
|
displayGrossPrices: true,
|
||||||
|
isShippingRequired: true,
|
||||||
userEmail: "adrian.king@example.com",
|
userEmail: "adrian.king@example.com",
|
||||||
metadata: [
|
metadata: [
|
||||||
{
|
{
|
||||||
|
@ -41,9 +48,15 @@ const exampleOrderPayload: OrderDetailsFragment = {
|
||||||
email: "adrian.king@example.com",
|
email: "adrian.king@example.com",
|
||||||
firstName: "Adrian",
|
firstName: "Adrian",
|
||||||
lastName: "King",
|
lastName: "King",
|
||||||
|
languageCode: LanguageCodeEnum.En,
|
||||||
},
|
},
|
||||||
billingAddress: {
|
billingAddress: {
|
||||||
|
firstName: "Adrian",
|
||||||
|
lastName: "King",
|
||||||
streetAddress1: "59314 Mary Well Suite 281",
|
streetAddress1: "59314 Mary Well Suite 281",
|
||||||
|
streetAddress2: "",
|
||||||
|
companyName: "",
|
||||||
|
cityArea: "",
|
||||||
city: "METROPOLIS",
|
city: "METROPOLIS",
|
||||||
postalCode: "71653",
|
postalCode: "71653",
|
||||||
country: {
|
country: {
|
||||||
|
@ -51,7 +64,12 @@ const exampleOrderPayload: OrderDetailsFragment = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
shippingAddress: {
|
shippingAddress: {
|
||||||
|
firstName: "Adrian",
|
||||||
|
lastName: "King",
|
||||||
streetAddress1: "59314 Mary Well Suite 281",
|
streetAddress1: "59314 Mary Well Suite 281",
|
||||||
|
streetAddress2: "",
|
||||||
|
companyName: "",
|
||||||
|
cityArea: "",
|
||||||
city: "METROPOLIS",
|
city: "METROPOLIS",
|
||||||
postalCode: "71653",
|
postalCode: "71653",
|
||||||
country: {
|
country: {
|
||||||
|
@ -73,27 +91,13 @@ const exampleOrderPayload: OrderDetailsFragment = {
|
||||||
currency: "USD",
|
currency: "USD",
|
||||||
amount: 5,
|
amount: 5,
|
||||||
},
|
},
|
||||||
},
|
net: {
|
||||||
totalPrice: {
|
|
||||||
gross: {
|
|
||||||
currency: "USD",
|
currency: "USD",
|
||||||
amount: 5,
|
amount: 4,
|
||||||
},
|
},
|
||||||
},
|
tax: {
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "T3JkZXJMaW5lOjVhYmEzMTBkLTZkMzEtNDNlNy1hZjAyLTdlNGUwM2UzYmI4ZA==",
|
|
||||||
productName: "Code Division T-shirt",
|
|
||||||
variantName: "L",
|
|
||||||
quantity: 1,
|
|
||||||
thumbnail: {
|
|
||||||
url: "https://placehold.jp/150x150.png",
|
|
||||||
alt: "",
|
|
||||||
},
|
|
||||||
unitPrice: {
|
|
||||||
gross: {
|
|
||||||
currency: "USD",
|
currency: "USD",
|
||||||
amount: 5,
|
amount: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
totalPrice: {
|
totalPrice: {
|
||||||
|
@ -101,24 +105,96 @@ const exampleOrderPayload: OrderDetailsFragment = {
|
||||||
currency: "USD",
|
currency: "USD",
|
||||||
amount: 5,
|
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: {
|
subtotal: {
|
||||||
gross: {
|
gross: {
|
||||||
amount: 10,
|
amount: 5,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
net: {
|
||||||
|
amount: 4,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
tax: {
|
||||||
|
amount: 1,
|
||||||
currency: "USD",
|
currency: "USD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
shippingPrice: {
|
shippingPrice: {
|
||||||
gross: {
|
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",
|
currency: "USD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
total: {
|
total: {
|
||||||
gross: {
|
gross: {
|
||||||
amount: 71.62,
|
amount: 15,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
net: {
|
||||||
|
amount: 12,
|
||||||
|
currency: "USD",
|
||||||
|
},
|
||||||
|
tax: {
|
||||||
|
amount: 3,
|
||||||
currency: "USD",
|
currency: "USD",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -114,7 +114,7 @@ describe("WebhookManagementService", function () {
|
||||||
name: invoiceSentWebhook.name,
|
name: invoiceSentWebhook.name,
|
||||||
targetUrl: "https://example.com/api/webhooks/invoice-sent",
|
targetUrl: "https://example.com/api/webhooks/invoice-sent",
|
||||||
query:
|
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}",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue