-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shopify return location on refunds #6
base: main
Are you sure you want to change the base?
Changes from 4 commits
bb5cfe6
7de6252
db117b1
e67269e
adac8cb
0ba11c1
1b4152d
e94a985
acb191e
47261f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Microsoft.Integration.Shopify; | ||
|
||
enum 30156 "Shpfy Return Location Priority" | ||
{ | ||
Extensible = true; | ||
|
||
value(0; "Default Return Location") | ||
{ | ||
Caption = 'Default Return Location'; | ||
} | ||
value(1; "Original -> Default Location") | ||
{ | ||
Caption = 'Original -> Default Location'; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Microsoft.Integration.Shopify; | ||
|
||
/// <summary> | ||
/// Codeunit Shpfy GQL NextRevFulfillOrdLns (ID 30213) implements Interface Shpfy IGraphQL. | ||
/// </summary> | ||
codeunit 30213 "Shpfy GQL NextRevFulfillOrdLns" implements "Shpfy IGraphQL" | ||
{ | ||
Access = Internal; | ||
|
||
/// <summary> | ||
/// GetGraphQL. | ||
/// </summary> | ||
/// <returns>Return value of type Text.</returns> | ||
internal procedure GetGraphQL(): Text | ||
begin | ||
exit('{"query":"{ reverseFulfillmentOrder(id: \"{{FulfillOrderId}}\") { lineItems(first: 10, after:\"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { id fulfillmentLineItem { id lineItem { id name } } dispositions { id quantity type location { id legacyResourceId } } } } } }"}'); | ||
end; | ||
|
||
/// <summary> | ||
/// GetExpectedCost. | ||
/// </summary> | ||
/// <returns>Return value of type Integer.</returns> | ||
internal procedure GetExpectedCost(): Integer | ||
begin | ||
exit(15); | ||
end; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Microsoft.Integration.Shopify; | ||
|
||
/// <summary> | ||
/// Codeunit Shpfy GQL NextRevFulfillOrders (ID 30159) implements Interface Shpfy IGraphQL. | ||
/// </summary> | ||
codeunit 30159 "Shpfy GQL NextRevFulfillOrders" implements "Shpfy IGraphQL" | ||
{ | ||
Access = Internal; | ||
|
||
/// <summary> | ||
/// GetGraphQL. | ||
/// </summary> | ||
/// <returns>Return value of type Text.</returns> | ||
internal procedure GetGraphQL(): Text | ||
begin | ||
exit('{"query":"{ return(id: \"gid://shopify/Return/{{ReturnId}}\") { reverseFulfillmentOrders(first: 10, after:\"{{After}}\") { pageInfo { endCursor hasNextPage } nodes { id } } } }"}'); | ||
|
||
end; | ||
|
||
/// <summary> | ||
/// GetExpectedCost. | ||
/// </summary> | ||
/// <returns>Return value of type Integer.</returns> | ||
internal procedure GetExpectedCost(): Integer | ||
begin | ||
exit(7); | ||
end; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace Microsoft.Integration.Shopify; | ||
|
||
/// <summary> | ||
/// Codeunit Shpfy GQL RevFulfillOrders (ID 30105) implements Interface Shpfy IGraphQL. | ||
/// </summary> | ||
codeunit 30168 "Shpfy GQL RevFulfillOrderLines" implements "Shpfy IGraphQL" | ||
{ | ||
Access = Internal; | ||
|
||
/// <summary> | ||
/// GetGraphQL. | ||
/// </summary> | ||
/// <returns>Return value of type Text.</returns> | ||
internal procedure GetGraphQL(): Text | ||
begin | ||
exit('{"query":"{ reverseFulfillmentOrder(id: \"{{FulfillOrderId}}\") { id lineItems(first: 10) { nodes { id fulfillmentLineItem { id lineItem { id name } } dispositions { id quantity type location { id legacyResourceId } } } } } }"}'); | ||
end; | ||
|
||
/// <summary> | ||
/// GetExpectedCost. | ||
/// </summary> | ||
/// <returns>Return value of type Integer.</returns> | ||
internal procedure GetExpectedCost(): Integer | ||
begin | ||
exit(15); | ||
end; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Microsoft.Integration.Shopify; | ||
|
||
/// <summary> | ||
/// Codeunit Shpfy GQL RevFulfillOrders (ID 30105) implements Interface Shpfy IGraphQL. | ||
/// </summary> | ||
codeunit 30105 "Shpfy GQL RevFulfillOrders" implements "Shpfy IGraphQL" | ||
{ | ||
Access = Internal; | ||
|
||
/// <summary> | ||
/// GetGraphQL. | ||
/// </summary> | ||
/// <returns>Return value of type Text.</returns> | ||
internal procedure GetGraphQL(): Text | ||
begin | ||
exit('{"query":"{ return(id: \"gid://shopify/Return/{{ReturnId}}\") { reverseFulfillmentOrders(first: 10) { pageInfo { endCursor hasNextPage } nodes { id } } } }"}'); | ||
|
||
end; | ||
|
||
/// <summary> | ||
/// GetExpectedCost. | ||
/// </summary> | ||
/// <returns>Return value of type Integer.</returns> | ||
internal procedure GetExpectedCost(): Integer | ||
begin | ||
exit(7); | ||
end; | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -31,11 +31,14 @@ codeunit 30228 "Shpfy Refunds API" | |||||||||||||||||||||||||||||||||
RefundHeader: Record "Shpfy Refund Header"; | ||||||||||||||||||||||||||||||||||
GraphQLType: Enum "Shpfy GraphQL Type"; | ||||||||||||||||||||||||||||||||||
Parameters: Dictionary of [text, Text]; | ||||||||||||||||||||||||||||||||||
ReturnLocations: Dictionary of [BigInteger, BigInteger]; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure proper error handling for The + if ReturnId = 0 then
+ Error('Invalid Return ID provided.'); Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||
JResponse: JsonToken; | ||||||||||||||||||||||||||||||||||
JLines: JsonArray; | ||||||||||||||||||||||||||||||||||
JLine: JsonToken; | ||||||||||||||||||||||||||||||||||
begin | ||||||||||||||||||||||||||||||||||
GetRefundHeader(RefundId, UpdatedAt, RefundHeader); | ||||||||||||||||||||||||||||||||||
ReturnLocations := CollectReturnLocations(RefundHeader."Return Id"); | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor suggestion for repeated code in The + private procedure GetCursor(JResponse: JsonToken): Text
+ begin
+ exit(JsonHelper.GetValueAsText(JResponse, 'data.refund.refundLineItems.pageInfo.endCursor'));
+ end;
...
- Parameters.Set('After', JsonHelper.GetValueAsText(JResponse, 'data.refund.refundLineItems.pageInfo.endCursor'));
+ Parameters.Set('After', GetCursor(JResponse)); Also applies to: 54-54 |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Parameters.Add('RefundId', Format(RefundId)); | ||||||||||||||||||||||||||||||||||
GraphQLType := "Shpfy GraphQL Type"::GetRefundLines; | ||||||||||||||||||||||||||||||||||
repeat | ||||||||||||||||||||||||||||||||||
|
@@ -46,8 +49,9 @@ codeunit 30228 "Shpfy Refunds API" | |||||||||||||||||||||||||||||||||
Parameters.Set('After', JsonHelper.GetValueAsText(JResponse, 'data.refund.refundLineItems.pageInfo.endCursor')) | ||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||
Parameters.Add('After', JsonHelper.GetValueAsText(JResponse, 'data.refund.refundLineItems.pageInfo.endCursor')); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
foreach JLine in JLines do | ||||||||||||||||||||||||||||||||||
FillInRefundLine(RefundId, JLine.AsObject(), RefundHeader."Total Refunded Amount" > 0); | ||||||||||||||||||||||||||||||||||
FillInRefundLine(RefundId, JLine.AsObject(), RefundHeader."Total Refunded Amount" > 0, ReturnLocations); | ||||||||||||||||||||||||||||||||||
until not JsonHelper.GetValueAsBoolean(JResponse, 'data.refund.refundLineItems.pageInfo.hasNextPage'); | ||||||||||||||||||||||||||||||||||
end; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
|
@@ -88,21 +92,34 @@ codeunit 30228 "Shpfy Refunds API" | |||||||||||||||||||||||||||||||||
DataCapture.Add(Database::"Shpfy Refund Header", RefundHeader.SystemId, JResponse); | ||||||||||||||||||||||||||||||||||
end; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
local procedure FillInRefundLine(RefundId: BigInteger; JLine: JsonObject; NonZeroRefund: Boolean) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
local procedure CollectReturnLocations(ReturnId: BigInteger): Dictionary of [BigInteger, BigInteger] | ||||||||||||||||||||||||||||||||||
var | ||||||||||||||||||||||||||||||||||
ReturnsAPI: Codeunit "Shpfy Returns API"; | ||||||||||||||||||||||||||||||||||
begin | ||||||||||||||||||||||||||||||||||
if ReturnId <> 0 then | ||||||||||||||||||||||||||||||||||
exit(ReturnsAPI.GetReturnLocations(ReturnId)); | ||||||||||||||||||||||||||||||||||
end; | ||||||||||||||||||||||||||||||||||
Comment on lines
+96
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for invalid The + if ReturnId = 0 then
+ Error('Invalid Return ID provided.'); Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
local procedure FillInRefundLine(RefundId: BigInteger; JLine: JsonObject; NonZeroRefund: Boolean; ReturnLocations: Dictionary of [BigInteger, BigInteger]) | ||||||||||||||||||||||||||||||||||
var | ||||||||||||||||||||||||||||||||||
DataCapture: Record "Shpfy Data Capture"; | ||||||||||||||||||||||||||||||||||
RefundLine: Record "Shpfy Refund Line"; | ||||||||||||||||||||||||||||||||||
RefundLineRecordRef: RecordRef; | ||||||||||||||||||||||||||||||||||
Id: BigInteger; | ||||||||||||||||||||||||||||||||||
ReturnLocation: BigInteger; | ||||||||||||||||||||||||||||||||||
begin | ||||||||||||||||||||||||||||||||||
Id := CommunicationMgt.GetIdOfGId(JsonHelper.GetValueAsText(JLine, 'lineItem.id')); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if not RefundLine.Get(RefundId, Id) then begin | ||||||||||||||||||||||||||||||||||
RefundLine."Refund Line Id" := Id; | ||||||||||||||||||||||||||||||||||
RefundLine."Refund Id" := RefundId; | ||||||||||||||||||||||||||||||||||
RefundLine."Order Line Id" := Id; | ||||||||||||||||||||||||||||||||||
RefundLine.Insert(); | ||||||||||||||||||||||||||||||||||
end; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
RefundLine."Restock Type" := RefundEnumConvertor.ConvertToReStockType(JsonHelper.GetValueAsText(JLine, 'restockType')); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
RefundLineRecordRef.GetTable(RefundLine); | ||||||||||||||||||||||||||||||||||
JsonHelper.GetValueIntoField(JLine, 'quantity', RefundLineRecordRef, RefundLine.FieldNo(Quantity)); | ||||||||||||||||||||||||||||||||||
JsonHelper.GetValueIntoField(JLine, 'restocked', RefundLineRecordRef, RefundLine.FieldNo(Restocked)); | ||||||||||||||||||||||||||||||||||
|
@@ -113,8 +130,17 @@ codeunit 30228 "Shpfy Refunds API" | |||||||||||||||||||||||||||||||||
JsonHelper.GetValueIntoField(JLine, 'totalTaxSet.shopMoney.amount', RefundLineRecordRef, RefundLine.FieldNo("Total Tax Amount")); | ||||||||||||||||||||||||||||||||||
JsonHelper.GetValueIntoField(JLine, 'totalTaxSet.presentmentMoney.amount', RefundLineRecordRef, RefundLine.FieldNo("Presentment Total Tax Amount")); | ||||||||||||||||||||||||||||||||||
RefundLineRecordRef.SetTable(RefundLine); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
RefundLine."Can Create Credit Memo" := NonZeroRefund; | ||||||||||||||||||||||||||||||||||
RefundLine."Location Id" := JsonHelper.GetValueAsBigInteger(JLine, 'location.legacyResourceId'); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// If refund was created from a return, the location needs to come from the return | ||||||||||||||||||||||||||||||||||
// If Item was restocked to multiple locations, the return location is not known | ||||||||||||||||||||||||||||||||||
if (RefundLine."Location Id" = 0) and (ReturnLocations.Get(RefundLine."Order Line Id", ReturnLocation)) then | ||||||||||||||||||||||||||||||||||
RefundLine."Location Id" := ReturnLocation; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
RefundLine.Modify(); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
RefundLineRecordRef.Close(); | ||||||||||||||||||||||||||||||||||
DataCapture.Add(Database::"Shpfy Refund Line", RefundLine.SystemId, JLine); | ||||||||||||||||||||||||||||||||||
end; | ||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! But consider improving readability of the query string.
The method correctly returns a GraphQL query string. For better readability and maintainability, consider formatting the query string.
Committable suggestion