Skip to content
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] Dispute processing in Shopify (Payments module) #25753

Merged
merged 29 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9ee36ca
Add Dispute Status and "Dispute Finalized On" DateTime
daniloziva Jan 19, 2024
2a6db49
Fix object name
daniloziva Jan 19, 2024
c6d40b2
Change protection level of Shfy Payment Transaction type
daniloziva Jan 19, 2024
12c822c
Add function DisputesSync() to BackgroundSyncs.Codeunit.al
daniloziva Jan 22, 2024
5159e23
removed from Sync All Action
daniloziva Jan 22, 2024
5cdc133
Tests + CU updates to cater for test implementation
daniloziva Jan 22, 2024
6271f59
Fixes asked for by reviewer
daniloziva Jan 22, 2024
194d366
Updates
daniloziva Jan 26, 2024
d155514
remove variable
daniloziva Jan 26, 2024
106d295
Merge branch 'main' into main
daniloziva Jan 26, 2024
0564ed7
revert versions
daniloziva Jan 26, 2024
e658856
Merge branch 'main' of https://github.com/danilovetatek/ALAppExtensions
daniloziva Jan 26, 2024
17de3d9
Remove Unused var
daniloziva Jan 26, 2024
a66c64f
Add table for Disputes
daniloziva Jan 26, 2024
9717da9
Fix tests
daniloziva Jan 26, 2024
aa14d4c
CodeCopFix
daniloziva Jan 26, 2024
9e9fd0e
fix error
daniloziva Jan 26, 2024
7a2b221
Remove stray code
daniloziva Jan 28, 2024
87cc722
Merge branch 'microsoft:main' into main
daniloziva Feb 1, 2024
a5f0999
Updated enums
daniloziva Feb 5, 2024
6887705
Merge branch 'main' of https://github.com/danilovetatek/ALAppExtensions
daniloziva Feb 5, 2024
476fba8
Merge branch 'main' into main
JesperSchulz Apr 8, 2024
087928e
Apply suggestions from code review
JesperSchulz Apr 8, 2024
a32097d
Update Apps/W1/Shopify/app/src/Payments/Codeunits/ShpfyPayments.Codeu…
JesperSchulz Apr 8, 2024
d461c0c
Update Apps/W1/Shopify/app/src/Payments/Codeunits/ShpfyPayments.Codeu…
JesperSchulz Apr 9, 2024
225d716
Update Apps/W1/Shopify/test/Payments/ShpfyPaymentsTest.Codeunit.al
JesperSchulz Apr 9, 2024
c6770b1
Update test as checked in in NAV repo.
JesperSchulz Apr 10, 2024
39c5d7a
Update Apps/W1/Shopify/app/src/Payments/Codeunits/ShpfyPayments.Codeu…
JesperSchulz Apr 10, 2024
19aaf1d
Apply suggestions from internal check-in.
JesperSchulz Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,48 @@ codeunit 30169 "Shpfy Payments"
end;
end;
end;

internal procedure UpdateDisputeStatus()
var
PaymentTransaction: Record "Shpfy Payment Transaction";
OrderId: BigInteger;
JDisputes: JsonArray;
JItem: JsonToken;
JResponse: JsonToken;
Url: Text;
UrlTxt: Label 'shopify_payments/disputes.json?limit=250', Locked = true;
DisputeStatus: Enum "Shpfy Pay. Trans. Disp. Status";
begin
Url := CommunicationMgt.CreateWebRequestURL(UrlTxt);

repeat
JResponse := CommunicationMgt.ExecuteWebRequest(Url, 'GET', JResponse, Url);

if JsonHelper.GetJsonArray(JResponse, JDisputes, 'disputes') then
foreach JItem in JDisputes do begin
OrderId := JsonHelper.GetValueAsBigInteger(JItem, 'order_id');
DisputeStatus := ConvertToDisputeStatus(JsonHelper.GetValueAsText(JItem, 'status'));

PaymentTransaction.SetRange("Source Order Id", OrderId);
PaymentTransaction.SetRange(Type, PaymentTransaction.Type::Dispute);
if PaymentTransaction.Findset() then
repeat
if PaymentTransaction."Dispute Status" <> DisputeStatus then begin
PaymentTransaction."Dispute Status" := DisputeStatus;
PaymentTransaction."Dispute Finalized On" := JsonHelper.GetValueAsDateTime(JItem, 'finalized_on');
PaymentTransaction.Modify();
end;
until PaymentTransaction.Next() = 0;
end;
until Url = '';
end;

local procedure ConvertToDisputeStatus(Value: Text): Enum "Shpfy Pay. Trans. Disp. Status"
begin
Value := CommunicationMgt.ConvertToCleanOptionValue(Value);
if Enum::"Shpfy Pay. Trans. Disp. Status".Names().Contains(Value) then
exit(Enum::"Shpfy Pay. Trans. Disp. Status".FromInteger(Enum::"Shpfy Pay. Trans. Disp. Status".Ordinals().Get(Enum::"Shpfy Pay. Trans. Disp. Status".Names().IndexOf(Value))))
else
exit(Enum::"Shpfy Pay. Trans. Disp. Status"::Unknown);
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
enum 30150 "Shpfy Pay. Trans. Disp. Status"
{
Caption = 'Shopify Payment Transaction Dispute status';
Extensible = true;

value(0; Unknown)
{
Caption = ' ';
}
value(1; "Needs Response")
{
Caption = 'Needs Response';
}
value(2; "Under Review")
{
Caption = 'Under Review';
}
value(3; "Charge Refunded")
{
Caption = 'Charge Refunded';
}
value(4; "Accepted")
{
Caption = 'Accepted';
}
value(5; "Won")
{
Caption = 'Chargeback Won';
}
value(6; "Lost")
{
Caption = 'Lost';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace Microsoft.Integration.Shopify;
/// </summary>
enum 30127 "Shpfy Payment Trans. Type"
{
Access = Internal;
Caption = 'Shopify Payment Transcation Type';
Extensible = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ page 30124 "Shpfy Payment Transactions"
ApplicationArea = All;
ToolTip = 'Specifies the id the order transaction that resulted in this balance transaction.';
}
field("Dispute Status"; Rec."Dispute Status")
{
ApplicationArea = All;
ToolTip = 'Specifies the Dispute Status of the payment transaction.';
}
field("Dispute Finalized On"; Rec."Dispute Finalized On")
{
ApplicationArea = All;
ToolTip = 'Specifies the Dispute Finalized On of the payment transaction.';

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
report 30120 "Shpfy Sync Disputes"
{
ApplicationArea = All;
Caption = 'Shopify Sync Disputes';
ProcessingOnly = true;
UsageCategory = Tasks;

dataset
{
dataitem(Shop; "Shpfy Shop")
{
DataItemTableView = where(Enabled = const(true));
trigger OnAfterGetRecord()
var
Sync: codeunit "Shpfy Payments";
begin
Sync.SetShop(Shop);
Sync.UpdateDisputeStatus();
end;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ table 30124 "Shpfy Payment Transaction"
Caption = 'Invoice No.';
FieldClass = FlowField;
}
field(200; "Dispute Status"; Enum "Shpfy Pay. Trans. Disp. Status")
{
Caption = 'Dispute Status';
DataClassification = CustomerContent;
}
field(201; "Dispute Finalized On"; DateTime)
{
Caption = 'Dispute Finalized On';
DataClassification = CustomerContent;
}
}
keys
{
Expand Down