@@ -3856,33 +3856,86 @@ fn get_dispute_stage(
3856
3856
3857
3857
pub fn get_dispute_status (
3858
3858
dispute_cycle : String ,
3859
- ) -> Result < api_models:: enums:: DisputeStatus , error_stack:: Report < errors:: ConnectorError > > {
3860
- match connector_utils:: normalize_string ( dispute_cycle. clone ( ) )
3861
- . change_context ( errors:: ConnectorError :: RequestEncodingFailed ) ?
3862
- . as_str ( )
3863
- {
3864
- "arbitration"
3865
- | "arbitrationmastercard"
3866
- | "arbitrationsplit"
3867
- | "representment"
3868
- | "issuerarbitration"
3869
- | "prearbitration"
3870
- | "responsetoissuerarbitration"
3871
- | "arbitrationchargeback" => Ok ( api_models:: enums:: DisputeStatus :: DisputeChallenged ) ,
3872
- "chargebackreversal" | "issueracceptedprearbitration" | "arbitrationwon" => {
3873
- Ok ( api_models:: enums:: DisputeStatus :: DisputeWon )
3874
- }
3875
- "arbitrationlost" | "issuerdeclinedprearbitration" => {
3876
- Ok ( api_models:: enums:: DisputeStatus :: DisputeLost )
3877
- }
3878
- "firstchargeback" | "retrievalrequest" | "rapiddisputeresolution" => {
3879
- Ok ( api_models:: enums:: DisputeStatus :: DisputeOpened )
3859
+ dispute_activities : Vec < Activity > ,
3860
+ ) -> Result < common_enums:: DisputeStatus , error_stack:: Report < errors:: ConnectorError > > {
3861
+ if let Some ( activity) = get_last_non_auxiliary_activity_type ( dispute_activities) {
3862
+ match activity. as_ref ( ) {
3863
+ "Merchant Accept"
3864
+ | "Issuer Accepted Pre-Arbitration"
3865
+ | "Vantiv Accept"
3866
+ | "Sent Credit" => Ok ( common_enums:: DisputeStatus :: DisputeAccepted ) ,
3867
+
3868
+ "Merchant Represent"
3869
+ | "Respond to Dispute"
3870
+ | "Respond to PreArb"
3871
+ | "Request Arbitration"
3872
+ | "Request Pre-Arbitration"
3873
+ | "Create Arbitration"
3874
+ | "Record Arbitration"
3875
+ | "Create Pre-Arbitration"
3876
+ | "File Arbitration"
3877
+ | "File Pre-Arbitration"
3878
+ | "File Visa Pre-Arbitration"
3879
+ | "Send Representment"
3880
+ | "Send Response"
3881
+ | "Arbitration"
3882
+ | "Arbitration (Mastercard)"
3883
+ | "Arbitration Chargeback"
3884
+ | "Issuer Declined Pre-Arbitration"
3885
+ | "Issuer Arbitration"
3886
+ | "Request Response to Pre-Arbitration"
3887
+ | "Vantiv Represent"
3888
+ | "Vantiv Respond"
3889
+ | "Auto Represent"
3890
+ | "Arbitration Ruling" => Ok ( common_enums:: DisputeStatus :: DisputeChallenged ) ,
3891
+
3892
+ "Arbitration Lost" | "Unsuccessful Arbitration" | "Unsuccessful Pre-Arbitration" => {
3893
+ Ok ( common_enums:: DisputeStatus :: DisputeLost )
3894
+ }
3895
+
3896
+ "Arbitration Won"
3897
+ | "Arbitration Split"
3898
+ | "Successful Arbitration"
3899
+ | "Successful Pre-Arbitration" => Ok ( common_enums:: DisputeStatus :: DisputeWon ) ,
3900
+
3901
+ "Chargeback Reversal" => Ok ( common_enums:: DisputeStatus :: DisputeCancelled ) ,
3902
+
3903
+ "Receive Network Transaction" => Ok ( common_enums:: DisputeStatus :: DisputeOpened ) ,
3904
+
3905
+ "Unaccept" | "Unrepresent" => Ok ( common_enums:: DisputeStatus :: DisputeOpened ) ,
3906
+
3907
+ unexpected_activity => Err ( errors:: ConnectorError :: UnexpectedResponseError (
3908
+ bytes:: Bytes :: from ( format ! ( "Dispute Activity: {unexpected_activity})" ) ) ,
3909
+ )
3910
+ . into ( ) ) ,
3880
3911
}
3881
- _ => Err ( errors:: ConnectorError :: NotSupported {
3882
- message : format ! ( "Dispute status {dispute_cycle}" ) ,
3883
- connector : "worldpayvantiv" ,
3912
+ } else {
3913
+ match connector_utils:: normalize_string ( dispute_cycle. clone ( ) )
3914
+ . change_context ( errors:: ConnectorError :: RequestEncodingFailed ) ?
3915
+ . as_str ( )
3916
+ {
3917
+ "arbitration"
3918
+ | "arbitrationmastercard"
3919
+ | "arbitrationsplit"
3920
+ | "representment"
3921
+ | "issuerarbitration"
3922
+ | "prearbitration"
3923
+ | "responsetoissuerarbitration"
3924
+ | "arbitrationchargeback" => Ok ( api_models:: enums:: DisputeStatus :: DisputeChallenged ) ,
3925
+ "chargebackreversal" | "issueracceptedprearbitration" | "arbitrationwon" => {
3926
+ Ok ( api_models:: enums:: DisputeStatus :: DisputeWon )
3927
+ }
3928
+ "arbitrationlost" | "issuerdeclinedprearbitration" => {
3929
+ Ok ( api_models:: enums:: DisputeStatus :: DisputeLost )
3930
+ }
3931
+ "firstchargeback" | "retrievalrequest" | "rapiddisputeresolution" => {
3932
+ Ok ( api_models:: enums:: DisputeStatus :: DisputeOpened )
3933
+ }
3934
+ dispute_cycle => Err ( errors:: ConnectorError :: UnexpectedResponseError (
3935
+ bytes:: Bytes :: from ( format ! ( "Dispute Stage: {dispute_cycle}" ) ) ,
3936
+ )
3937
+ . into ( ) ) ,
3884
3938
}
3885
- . into ( ) ) ,
3886
3939
}
3887
3940
}
3888
3941
@@ -3914,7 +3967,7 @@ impl TryFrom<ChargebackCase> for DisputeSyncResponse {
3914
3967
amount,
3915
3968
currency : item. chargeback_currency_type ,
3916
3969
dispute_stage : get_dispute_stage ( item. cycle . clone ( ) ) ?,
3917
- dispute_status : get_dispute_status ( item. cycle . clone ( ) ) ?,
3970
+ dispute_status : get_dispute_status ( item. cycle . clone ( ) , item . activity ) ?,
3918
3971
connector_status : item. cycle . clone ( ) ,
3919
3972
connector_dispute_id : item. case_id . clone ( ) ,
3920
3973
connector_reason : item. reason_code_description . clone ( ) ,
@@ -4148,3 +4201,40 @@ impl
4148
4201
} )
4149
4202
}
4150
4203
}
4204
+
4205
+ fn get_last_non_auxiliary_activity_type ( activities : Vec < Activity > ) -> Option < String > {
4206
+ let auxiliary_activities: std:: collections:: HashSet < & ' static str > = [
4207
+ "Add Note" ,
4208
+ "Attach Document" ,
4209
+ "Attempted Attach Document" ,
4210
+ "Delete Document" ,
4211
+ "Update Document" ,
4212
+ "Move To Error Queue" ,
4213
+ "Assign to Vantiv" ,
4214
+ "Assign To Merchant" ,
4215
+ "Merchant Auto Assign" ,
4216
+ "Issuer Recalled" ,
4217
+ "Network Decision" ,
4218
+ "Request Declined" ,
4219
+ "Sent Gift" ,
4220
+ "Successful PayPal" ,
4221
+ ]
4222
+ . iter ( )
4223
+ . copied ( )
4224
+ . collect ( ) ;
4225
+
4226
+ let mut last_non_auxiliary_activity = None ;
4227
+
4228
+ for activity in activities {
4229
+ let auxiliary_activity = activity
4230
+ . activity_type
4231
+ . as_deref ( )
4232
+ . map ( |activity_type| auxiliary_activities. contains ( activity_type) )
4233
+ . unwrap_or ( false ) ;
4234
+
4235
+ if !auxiliary_activity {
4236
+ last_non_auxiliary_activity = activity. activity_type . clone ( )
4237
+ }
4238
+ }
4239
+ last_non_auxiliary_activity
4240
+ }
0 commit comments