bchavez / Coinbase

:moneybag: A .NET/C# implementation of the Coinbase API.

Home Page:https://developers.coinbase.com/api/v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mispaid fields

aleles opened this issue · comments

Hi Brian, could you please add a couple of fields to the Order object?

  • mispaid_btc
  • mispaid_native

Optionally, someone may benefit from the mispayments array too.

Thanks a lot!
Alex

Hi @aleles , I think they are already added?

https://github.com/bchavez/Coinbase/blob/master/Source/Coinbase/ObjectModel/RefundResponse.cs#L37

What endpoint are you using that you're not getting the mis-payments fields?

Oh, cool, my bad. So if the order status is Mispaid, then I can cast the CoinbaseCallback.Order to the RefundOrder class?

  • At what exact point do you check the order status?

If you have access to the HTTP traffic:

  • What API call contained the mispaid JSON?

I do it in the callback handler that Coinbase sends after the customer completes the order on a Coinbase payment page.

Ah, i see. Thanks, yea, the v1 API is a complete a mess. I'm looking at the v2 API, the object model is a bit better in v2 and might be able to do this.

Cool, thanks!

I just tried and the object I get in the callback is just Order, not RefundOrder, so I can't cast it.

Yes, that's correct. With V1 object model, the information isn't kept around. Will try to fix this in V2 API calls.

Could you post the HTTP contents (removing sensitive info)?

Sure, here's one for a mispaid order

{
  "order": {
    "id": "FEZ0U...",
    "uuid": "85f8f8fa-167d-5752-921d-...",
    "resource_path": "\/v2\/orders\/85f8f8fa-167d-5752-921d-...",
    "metadata": null,
    "created_at": "2015-12-07T14:20:58-08:00",
    "status": "mispaid",
    "event": {
      "type": "mispayment",
      "mispayment_id": "CK95MCVI"
    },
    "total_btc": {
      "cents": 12700,
      "currency_iso": "BTC"
    },
    "total_native": {
      "cents": 5,
      "currency_iso": "USD"
    },
    "total_payout": {
      "cents": 5,
      "currency_iso": "USD"
    },
    "receive_address": "1LAbvB5VFP...",
    "button": {
      "type": "buy_now",
      "subscription": false,
      "repeat": null,
      "name": "Test Order #17790",
      "description": null,
      "id": "64ccf4cd...",
      "uuid": "fb553bb5-54bc-52ce-b3cf-...",
      "resource_path": "\/v2\/checkouts\/fb553bb5-54bc-52ce-b3cf-..."
    },
    "refund_address": "1Yt9Gho...",
    "mispaid_btc": {
      "cents": 10000,
      "currency_iso": "BTC"
    },
    "mispaid_native": {
      "cents": 3,
      "currency_iso": "USD"
    },
    "mispayments": [
      {
        "id": "CK95MCVI",
        "created_at": "2015-12-07T14:26:00-08:00",
        "total_btc": {
          "cents": 10000,
          "currency_iso": "BTC"
        },
        "total_native": {
          "cents": 4,
          "currency_iso": "USD"
        }
      }
    ],
    "transaction": {
      "id": "56660777...",
      "hash": null,
      "confirmations": 0
    }
  }
}

Ah, thanks :)

Brian, how soon do you think you can implement V2?

Not sure yet ... Implementing the callback crypto verification. Maybe a few days.

Sounds good, thanks.
I use an additional key I pass in the callback url to Coinbase and verify after it comes back.

Yea, might have to keep it that way... the coinbase signature isn't playing well with .net's crypto APIs.

@aleles

Give 2.0.1-beta-1 a try.

BREAKING CHANGES

  • Compatibility with Coinbase API v2.
  • Deprecated Coinbase.Mvc project. Please replace uses of CoinbaseCallback with the Notification class (in Coinbase.ObjectModel).
  • [JsonNetBinder] (or any other binder) is no longer needed when processing callbacks.
  • Checkout redirect URLs are generated by api.GetCheckoutUrl(response), where response is the return value from api.CreateCheckout() and api is CoinbaseApi.
  • You can now send raw requests to any endpoint: /order, /time, /wallet by using api.SendRequest(body, endpoint, httpMethod)

The CoinbaseResponse class now has a .Data field, that returns JObject that you can use to probe for values in the response.

Additionally, please replace CoinbaseCallback with Notification and use the .UnverifiedOrder property (of type JObject) to probe order properties like mispayments.

[Route( "bitcoin/callback" ), HttpPost]
public ActionResult Bitcoin_Execute( Notification callback )
{
    var order = callback.UnverifiedOrder;
    if( IsValid(order) ) //my app's custom verification
    {
        var purchaseId = order["custom"];
        if( order["status"] == "completed"){
            //The bitcoin payment has completed, use the purchaseId
            //to fulfill the order.
        }

        return new HttpStatusCodeResult( HttpStatusCode.OK );
    }
    return new HttpStatusCodeResult( HttpStatusCode.BadRequest );
}

Also, the Coinbase.Mvc project has been deprecated now that we're using JObject in processing responses. Please remove it from your MVC project.

I'll probably leave beta1 up for a few weeks before moving it to production to give everyone enough time to update and check things out.

-Brian