Refund in Admin-app change the Status
Problem
Regardless of the current status of an order in the admin app, it is possible to issue refunds for purchases made online, such as with a credit card.
We have the option to process either full or partial refunds.
It is important to note that when a refund is issued, the status of the order in the loyalty system changes to "VOID," which cancels any points previously earned.
In the Loyalty Transaction screen, this order will appear with the status "VOID" and without the points bonus. However, in the Recent Orders screen and Order Details, it is still displayed as a normal order, as if the points were earned.
We need to align the app's behavior so that the status is consistent in both the loyalty screen and the orders screen.
Example:
Description | Screen |
---|---|
Current point of user in Loyalty | |
An order with a refund shows discrepancies in the initial and final points, as the correct value should be 21.514. When the refund is processed after the order has been delivered, the value becomes outdated. | |
In the Order Screen, the transaction values are retained, but the status "Refund Successful" is treated the same as "Canceled," which prevents us from displaying the transaction points. | |
In the Order Detail screen, we encounter the same issue: we display the transaction, but the earned points are not shown correctly. |
Solution
Create and Adjust the validation for Delivery and Order Status
The current code only checks the delivery status in the order screens, but we also need to validate the order status.
In services/graphql/src/generated/graphql.ts
export enum RbiOrderStatus {
...
REFUND_SUCCESSFUL = "REFUND_SUCCESSFUL",
UPDATE_ERROR = "UPDATE_ERROR",
...
}
We need to verify these statuses to determine whether the order status is correct or not.
We can create a new validation in /src/utils/loyalty-balance-point/index.ts
We need to adjust the isVoidOrderStatus
and create the isVoidDeliveryStatus
as follows:
export const isVoidOrderStatus = (status?: string): boolean =>
status === INTLLoyaltyTransactionStatus.VOID ||
status === RbiOrderStatus.UPDATE_ERROR ||
status === RbiOrderStatus.REFUND_SUCCESSFUL;
export const isVoidDeliveryStatus = (status?: string): boolean =>
status === DeliveryStatus.ORDER_ERROR || status === DeliveryStatus.ORDER_CANCELLED;
And when we validate only the isVoidOrderStatus
, we also need to validate the isVoidDeliveryStatus
.
For example, in the LoyaltyBalancePoints
screen, we already validate the delivery status, so now we need to validate both, as follows:
//old code
const isOrderStatusVoid = isVoidOrderStatus(orderStatus);
//new code
const isOrderOrDeliveryStatusVoid =
isVoidOrderStatus(orderStatus) || isVoidDeliveryStatus(deliveryStatus);
We need to change this in all places where it is used
Recent Orders
Create a new attribute in LoyaltyBalancePoints
.src/components/loyalty-balance-points/loyalty-balance-points.tsx
We need to pass the order status to this component, so we will update its interface.
And we will pass this new value in OrderTimelineItem
src/components/customer-orders/order-timeline-item.tsx
Order Detail Screen
we need to adjust the PointsDetailsProps
in src/components/points-details-card/types.ts
Add deliveryStatus?: string;
After this, adjust the PointsDetailsCard
in src/components/points-details-card/index.tsx
And to pass the order and delivery status in OrderDetails
src/components/order-details/index.tsx
In PointsDetailsCard
we need to adjust the validation to void status like this:
Limitation
We can process a refund in certain situations, such as when the transaction status is marked as Confirmed or Voided. These statuses do not affect the user's final score.
When the transaction is in the Claim status, points are awarded to the user. However, if we issue a refund, the user's final score will change, but the points for that specific transaction will remain unchanged. This means that the initial score displayed for the order will be incorrect, and this control is managed on the layout side. We do not have a solution for this in the admin app.
Here’s an example:
Transaction in Confirmed status:
Step | Evidence |
---|---|
We placed the order, and now the status is Confirmed, but not delivered.
|
|
We processed a refund |
|
After the refund the status is Voided, and the initial and final points values remain the same, corresponding to the user's total points. |
|
In the database, we also have the same value |
|
Transaction in status de Claimed:
Step | Evidence |
---|---|
We placed the order, and now the status is Confirmed, but not delivered. | |
After the product was delivered the status is Claimed. | |
We processed a refund. | |
After the refund, the status is Voided, the initial and final points values remain unchanged, but now they differ from the user's total points. Here we have an issue, as the values are different from the user's total points, whereas the correct points should reflect the user's total points. | |
In the database, we also have the incorrect value. This value is managed by the loyalty service, and we do not have control over it. |