avadev / AvaTax-Calc-REST-PHP

PHP sample for the AvaTax Calc REST API
Apache License 2.0
9 stars 28 forks source link

GetTaxResult properties json encode #28

Closed estevejm closed 8 years ago

estevejm commented 8 years ago

When you execute json_encode(GetTaxResult)you get a json similar to:

{
    "DocCode": "DOCCODE01",
    "DocDate": "2016-02-11",
    "Timestamp": "2016-02-11T15:52:58.2634494Z",
    "TotalAmount": "143.5",
    "TotalDiscount": "0",
    "TotalExemption": "0",
    "TotalTaxable": "143.5",
    "TotalTax": "30.14",
    "TotalTaxCalculated": "30.14",
    "TaxDate": "2016-02-11",
    "TaxLines": [
        [],
        []
    ],
    "TaxSummary": [],
    "TaxAddresses": {
        "AddressCode": null,
        "Line1": null,
        "Line2": null,
        "Line3": null,
        "City": null,
        "Region": null,
        "PostalCode": null,
        "Country": null,
        "TaxRegionId": null,
        "Latitude": null,
        "Longitude": null
    },
    "ResultCode": "Success",
    "Messages": []
}

As you can notice, neither TaxLines (with their TaxDetails) nor Messages are correctly serialized.

Applying this change we could get a more complete serialization, something similar to:

{
    "DocCode": "DOCCODE01",
    "DocDate": "2016-02-11",
    "Timestamp": "2016-02-15T09:55:45.5684464Z",
    "TotalAmount": "143.5",
    "TotalDiscount": "0",
    "TotalExemption": "0",
    "TotalTaxable": "143.5",
    "TotalTax": "30.14",
    "TotalTaxCalculated": "30.14",
    "TaxDate": "2016-02-11",
    "TaxLines": [
        {
            "TaxDetails": [
                {
                    "JurisType": "Country",
                    "Taxable": 127.52380952381,
                    "Rate": "0.210000",
                    "Tax": "26.78",
                    "JurisName": "SPAIN",
                    "TaxName": "Standard Rate",
                    "Country": "ES",
                    "Region": "ES"
                }
            ],
            "LineNo": "1",
            "TaxCode": "P0000000",
            "Taxability": "true",
            "BoundaryLevel": "Zip5",
            "Exemption": "0",
            "Discount": "0",
            "Taxable": "127.5",
            "Rate": "0.210000",
            "Tax": "26.78",
            "TaxCalculated": "26.78"
        },
        {
            "TaxDetails": [
                {
                    "JurisType": "Country",
                    "Taxable": 16,
                    "Rate": "0.210000",
                    "Tax": "3.36",
                    "JurisName": "SPAIN",
                    "TaxName": "Standard Rate",
                    "Country": "ES",
                    "Region": "ES"
                }
            ],
            "LineNo": "2",
            "TaxCode": "P0000000",
            "Taxability": "true",
            "BoundaryLevel": "Zip5",
            "Exemption": "0",
            "Discount": "0",
            "Taxable": "16",
            "Rate": "0.210000",
            "Tax": "3.36",
            "TaxCalculated": "3.36"
        }
    ],
    "TaxSummary": [],
    "TaxAddresses": {
        "AddressCode": null,
        "Line1": null,
        "Line2": null,
        "Line3": null,
        "City": null,
        "Region": null,
        "PostalCode": null,
        "Country": null,
        "TaxRegionId": null,
        "Latitude": null,
        "Longitude": null
    },
    "ResultCode": "Success",
    "Messages": []
}
nejo commented 8 years ago

:+1:

lukestokes commented 8 years ago

@estevejm Minor fix:

'TaxSummary' =>  $this->jsonSerializeArray($this->getTaxSummary()),

We pulled this in to our fork and are using the Summary document type and noticed it was otherwise empty. Thanks!

estevejm commented 8 years ago

@lukestokes you're right, I included the fix in this PR. Thanks!