Skip to content

Wrong type for field 'callback_duration' in class 'Operation' #22

Description

@immeo-rru

Problem: the data returned from Quickpay containing data from aquirer cannot always be serialized. This results in an error that cannot be handled in my own code.

Solution: change type for field callback_duration from "string" to "int?".

Details:
Looking at the part of the JSON returned for an operaion looks like this:

{
            "id": 2,
            "type": "authorize",
            "amount": 148,
            "pending": false,
            "qp_status_code": "20000",
            "qp_status_msg": "Approved",
            "aq_status_code": "0",
            "aq_status_msg": "Accepted, The agreement has been accepted.",
            "data": {},
            "callback_url": "https://13f5-147-78-28-145.ngrok-free.app/subscriptions/callback",
            "callback_success": false,
            "callback_response_code": null,
            "callback_duration": 30002,
            "acquirer": "mobilepaysubscriptions",
            "3d_secure_status": null,
            "callback_at": "2023-09-06T11:54:00Z",
            "created_at": "2023-09-06T11:50:58Z"
 }

Test:

private string JsonOperation = @"{
		""id"": 2,
		""type"": ""authorize"",
		""amount"": 148,
		""pending"": false,
		""qp_status_code"": ""20000"",
		""qp_status_msg"": ""Approved"",
		""aq_status_code"": ""0"",
		""aq_status_msg"": ""Accepted, The agreement has been accepted."",
		""data"": { },
		""callback_url"": ""https://13f5-147-78-28-145.ngrok-free.app/subscriptions/callback"",
		""callback_success"": false,
		""callback_response_code"": null,
		""callback_duration"": 30002,
		""acquirer"": ""mobilepaysubscriptions"",
		""3d_secure_status"": null,
		""callback_at"": ""2023-09-06T11:54:00Z"",
		""created_at"": ""2023-09-06T11:50:58Z""
	}";

[TestMethod]
public void ParseOperation_OneOperation_Fail()
{
	try
	{
		var operation = System.Text.Json.JsonSerializer.Deserialize<Quickpay.Models.Payments.Operation>(JsonOperation);
	}
	catch (Exception e)
	{
		Assert.Fail(e.Message);
	}
}

public class OperationFixed : Quickpay.Models.Payments.Operation
{
	public new int? callback_duration { get; set; }
}

[TestMethod]
public void ParseOperation_OneOperation_Success()
{
	try
	{
		var operation = System.Text.Json.JsonSerializer.Deserialize<OperationFixed>(JsonOperation);
	}
	catch (Exception e)
	{
		Assert.Fail(e.Message);
	}
	Assert.IsTrue(true);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions