feat: Add Shopify refund to return mapping logic#250
feat: Add Shopify refund to return mapping logic#250puru-khedre wants to merge 25 commits intorefunds-mega-queryfrom
Conversation
Summary of ChangesHello @puru-khedre, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the integration with Shopify by implementing a robust and detailed mechanism for processing refunds and returns. The core objective is to accurately translate complex Shopify refund data, including item-level details, financial adjustments, and payment information, into the internal system's return payload. This ensures consistent data representation, supports various refund and exchange scenarios, and provides comprehensive tracking and auditing capabilities, ultimately improving the system's ability to manage post-purchase operations from Shopify. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new Groovy script for mapping Shopify refund data to an internal return payload and refactors the create#ShopifyRefunds service to utilize this script. This is a good move towards modularity. My review has identified a critical bug in the updated service that would cause it to fail, a potential critical runtime error in the new script, and some areas for code improvement and cleanup. Please see the detailed comments for suggestions on how to address these issues.
| grandTotal: refund.totalRefundedSet.shopMoney.amount, | ||
| items: refund.refundLineItems.collect { rli -> | ||
| def lineItem = rli.lineItem | ||
| def qtyRatio = rli.quantity / lineItem.quantity |
| <parameter name="shopifyOrderId" required="true"/> | ||
| </in-parameters> | ||
| <actions> | ||
| <service-call name="co.hotwax.shopify.return.ShopifyReturnServices.get#CompleteOrderRefundDetails" in-map="[systemMessageRemoteId:systemMessageRemoteId? systemMessageRemoteId:systemMessageRemote.systemMessageRemoteId , shopifyOrderId:shopifyOrderId]" out-map="orderRefundDetails"/> |
There was a problem hiding this comment.
This service call will fail because the systemMessageRemote variable is used in the in-map attribute but is not defined within the service's actions. The logic to fetch the SystemMessageRemote entity using the shopId (which was present in the old version of the service) is missing. You need to re-introduce this logic before the service call to prevent a runtime error.
| refund.refundShippingLines.collect { | ||
| [type: "RET_SHIPPING_ADJ", amount: it.subtotalAmountSet?.shopMoney?.amount, description: "Shipping Refund"] | ||
| } + | ||
| refund.refundShippingLines.collect { | ||
| [type: "RET_SALES_TAX_ADJ", amount: it.taxAmountSet?.shopMoney?.amount, description: "Shipping Tax Refund"] | ||
| } + | ||
| refund.orderAdjustments.collect { | ||
| [type: "RET_ORDER_ADJ", amount: it.amountSet?.shopMoney?.amount, description: "Order Adjustment"] | ||
| } | ||
| ).findAll { it.amount > 0 }, |
There was a problem hiding this comment.
The current implementation iterates over refund.refundShippingLines twice, which is inefficient. You can refactor this to use flatMap for a cleaner and more performant single-pass operation. Additionally, it's safer to explicitly check for null on the amount field in the findAll clause, as the safe-navigation operator (?.) can result in null values.
refund.refundShippingLines.flatMap { rsl ->
[
[type: "RET_SHIPPING_ADJ", amount: rsl.subtotalAmountSet?.shopMoney?.amount, description: "Shipping Refund"],
[type: "RET_SALES_TAX_ADJ", amount: rsl.taxAmountSet?.shopMoney?.amount, description: "Shipping Tax Refund"]
]
} +
refund.orderAdjustments.collect {
[type: "RET_ORDER_ADJ", amount: it.amountSet?.shopMoney?.amount, description: "Order Adjustment"]
}
).findAll { it.amount != null && it.amount > 0 },
| <iterate list="order.refunds" entry="refund"> | ||
| <service-call name="co.hotwax.shopify.return.ShopifyReturnServices.map#ShopifyRefundToReturn" in-map="[order:order, refund:refund]" out-map="result"/> | ||
|
|
||
| <log message="======= \n ${groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(result))} \n ======"/> |
| ) | ||
| ] | ||
| }, | ||
| returnAdjustment: ( |
There was a problem hiding this comment.
is flatMap a method on collection ?
There was a problem hiding this comment.
Updated with the correct method
script/co/hotwax/shopify/return/MapShopifyRefundToReturn.groovy
Outdated
Show resolved
Hide resolved
script/co/hotwax/shopify/return/MapShopifyRefundToReturn.groovy
Outdated
Show resolved
Hide resolved
| def prorate = { val -> (val as BigDecimal * qtyRatio).setScale(2, RoundingMode.HALF_UP) } | ||
|
|
||
| [ | ||
| id: ShopifyHelper.resolveShopifyGid(lineItem.variant?.id), // TODO: Requires internal productId resolution |
There was a problem hiding this comment.
we must have fallback condition based on sku and isGiftCard.
There was a problem hiding this comment.
Added the fallback, but the custom gift card is not handled.
script/co/hotwax/shopify/return/MapShopifyRefundToReturn.groovy
Outdated
Show resolved
Hide resolved
script/co/hotwax/shopify/return/MapShopifyRefundToReturn.groovy
Outdated
Show resolved
Hide resolved
…ange credit logic, and simplify payload construction
77e1f04 to
5c60d45
Compare
5c60d45 to
9acc9ed
Compare
Changes:
MapShopifyRefundToReturn.groovyto map Shopify refund JSON to internal Return payload.