fix(order): summary raw totals (#11712)
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/order": patch
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(order): summary raw totals
|
||||||
@@ -33,14 +33,14 @@ export type ValidateRefundStepInput = {
|
|||||||
/**
|
/**
|
||||||
* This step validates that the refund is valid for the order.
|
* This step validates that the refund is valid for the order.
|
||||||
* If the order does not have an outstanding balance to refund, the step throws an error.
|
* If the order does not have an outstanding balance to refund, the step throws an error.
|
||||||
*
|
*
|
||||||
* :::note
|
* :::note
|
||||||
*
|
*
|
||||||
* You can retrieve an order or payment's details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),
|
* You can retrieve an order or payment's details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),
|
||||||
* or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).
|
* or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).
|
||||||
*
|
*
|
||||||
* :::
|
* :::
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const data = validateRefundStep({
|
* const data = validateRefundStep({
|
||||||
* order: {
|
* order: {
|
||||||
@@ -56,12 +56,11 @@ export type ValidateRefundStepInput = {
|
|||||||
*/
|
*/
|
||||||
export const validateRefundStep = createStep(
|
export const validateRefundStep = createStep(
|
||||||
"validate-refund-step",
|
"validate-refund-step",
|
||||||
async function ({
|
async function ({ order, payment, amount }: ValidateRefundStepInput) {
|
||||||
order,
|
const pendingDifference =
|
||||||
payment,
|
order.summary?.raw_pending_difference! ??
|
||||||
amount,
|
order.summary?.pending_difference! ??
|
||||||
}: ValidateRefundStepInput) {
|
0
|
||||||
const pendingDifference = order.summary?.raw_pending_difference!
|
|
||||||
|
|
||||||
if (MathBN.gte(pendingDifference, 0)) {
|
if (MathBN.gte(pendingDifference, 0)) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
@@ -102,12 +101,12 @@ export type RefundPaymentWorkflowInput = {
|
|||||||
|
|
||||||
export const refundPaymentWorkflowId = "refund-payment-workflow"
|
export const refundPaymentWorkflowId = "refund-payment-workflow"
|
||||||
/**
|
/**
|
||||||
* This workflow refunds a payment. It's used by the
|
* This workflow refunds a payment. It's used by the
|
||||||
* [Refund Payment Admin API Route](https://docs.medusajs.com/api/admin#payments_postpaymentsidrefund).
|
* [Refund Payment Admin API Route](https://docs.medusajs.com/api/admin#payments_postpaymentsidrefund).
|
||||||
*
|
*
|
||||||
* You can use this workflow within your own customizations or custom workflows, allowing you
|
* You can use this workflow within your own customizations or custom workflows, allowing you
|
||||||
* to refund a payment in your custom flows.
|
* to refund a payment in your custom flows.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const { result } = await refundPaymentWorkflow(container)
|
* const { result } = await refundPaymentWorkflow(container)
|
||||||
* .run({
|
* .run({
|
||||||
@@ -115,16 +114,14 @@ export const refundPaymentWorkflowId = "refund-payment-workflow"
|
|||||||
* payment_id: "payment_123",
|
* payment_id: "payment_123",
|
||||||
* }
|
* }
|
||||||
* })
|
* })
|
||||||
*
|
*
|
||||||
* @summary
|
* @summary
|
||||||
*
|
*
|
||||||
* Refund a payment.
|
* Refund a payment.
|
||||||
*/
|
*/
|
||||||
export const refundPaymentWorkflow = createWorkflow(
|
export const refundPaymentWorkflow = createWorkflow(
|
||||||
refundPaymentWorkflowId,
|
refundPaymentWorkflowId,
|
||||||
(
|
(input: WorkflowData<RefundPaymentWorkflowInput>) => {
|
||||||
input: WorkflowData<RefundPaymentWorkflowInput>
|
|
||||||
) => {
|
|
||||||
const payment = useRemoteQueryStep({
|
const payment = useRemoteQueryStep({
|
||||||
entry_point: "payment",
|
entry_point: "payment",
|
||||||
fields: [
|
fields: [
|
||||||
|
|||||||
@@ -144,14 +144,17 @@ export async function applyChangesToOrder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const orderSummary = order.summary
|
const orderSummary = order.summary
|
||||||
summariesToUpsert.push({
|
const upsertSummary = {
|
||||||
id: orderSummary?.version === version ? orderSummary.id : undefined,
|
id: orderSummary?.version === version ? orderSummary.id : undefined,
|
||||||
order_id: order.id,
|
order_id: order.id,
|
||||||
version,
|
version,
|
||||||
totals: calculated.getSummaryFromOrder(
|
totals: calculated.getSummaryFromOrder(
|
||||||
calculated.order as unknown as OrderDTO
|
calculated.order as unknown as OrderDTO
|
||||||
),
|
),
|
||||||
})
|
}
|
||||||
|
|
||||||
|
createRawPropertiesFromBigNumber(upsertSummary)
|
||||||
|
summariesToUpsert.push(upsertSummary)
|
||||||
|
|
||||||
if (Object.keys(orderAttributes).length > 0) {
|
if (Object.keys(orderAttributes).length > 0) {
|
||||||
orderToUpdate.push({
|
orderToUpdate.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user