bchavez / Coinbase.Commerce

:moneybag: A .NET/C# implementation of the Coinbase Commerce API.
https://commerce.coinbase.com/docs/
Other
48 stars 9 forks source link

Error converting value {null} to type 'System.Int64'. Path 'payments[0].block.height' #12

Closed KirillKaverin closed 4 years ago

KirillKaverin commented 4 years ago

Version Information

Software Version(s)
NuGet Package 1.10.0

What is the expected behavior?

No error while convert webhook body to the object.

What is the actual behavior?

Error converting value {null} to type 'System.Int64'. Path 'payments[0].block.height'

Please provide a unit test that demonstrates the bug.

Webhook example to reproduce:

{
  "attempt_number": 1,
  "event": {
    "api_version": "2018-03-22",
    "created_at": "2019-12-19T16:18:40Z",
    "data": {
      "id": "foo",
      "code": "foo",
      "name": "foo",
      "pricing": {
        "usdc": {
          "amount": "1275.000000",
          "currency": "USDC"
        },
        "local": {
          "amount": "1275.00",
          "currency": "USD"
        },
        "bitcoin": {
          "amount": "0.17824340",
          "currency": "BTC"
        },
        "ethereum": {
          "amount": "9.982384000",
          "currency": "ETH"
        },
        "litecoin": {
          "amount": "31.90291505",
          "currency": "LTC"
        },
        "bitcoincash": {
          "amount": "6.76410515",
          "currency": "BCH"
        }
      },
      "logo_url": "foo",
      "metadata": {
        "DepositId": "111"
      },
      "payments": [
        {
          "block": {
            "hash": null,
            "height": null,
            "confirmations": 0,
            "confirmations_required": 1
          },
          "value": {
            "local": {
              "amount": "1274.67",
              "currency": "USD"
            },
            "crypto": {
              "amount": "0.17819718",
              "currency": "BTC"
            }
          },
          "status": "PENDING",
          "network": "bitcoin",
          "detected_at": "2019-12-19T16:18:40Z",
          "transaction_id": "foo"
        }
      ],
      "resource": "charge",
      "timeline": [
        {
          "time": "2019-12-19T16:18:11Z",
          "status": "NEW"
        },
        {
          "time": "2019-12-19T16:18:40Z",
          "status": "PENDING",
          "payment": {
            "network": "bitcoin",
            "transaction_id": "foo"
          }
        }
      ],
      "addresses": {
        "usdc": "foo",
        "bitcoin": "foo",
        "ethereum": "foo",
        "litecoin": "foo",
        "bitcoincash": "foo"
      },
      "created_at": "2019-12-19T16:18:11Z",
      "expires_at": "2019-12-19T17:18:11Z",
      "hosted_url": "https:\/\/commerce.coinbase.com\/charges\/foo",
      "description": "foo",
      "pricing_type": "fixed_price"
    },
    "id": "foo",
    "resource": "event",
    "type": "charge:pending"
  },
  "id": "foo",
  "scheduled_for": "2019-12-19T16:18:40Z"
}

Other notes on how to reproduce the issue?

Coinbase sends the 'height' null value only when webhook type is 'charge:pending'

Any possible solutions?

Change in Block class from public long Height { get; set; } to public long? Height { get; set; }

bchavez commented 4 years ago

Hi @KirillKaverin,

Your issue should be fixed in v1.1.1 released today:

https://www.nuget.org/packages/Coinbase.Commerce/1.1.1

Thanks, Brian