bchavez / coinbase.commerce Goto Github PK
View Code? Open in Web Editor NEW:moneybag: A .NET/C# implementation of the Coinbase Commerce API.
Home Page: https://commerce.coinbase.com/docs/
License: Other
:moneybag: A .NET/C# implementation of the Coinbase Commerce API.
Home Page: https://commerce.coinbase.com/docs/
License: Other
Hello,
I keep getting the
FlurlHttpException: Call failed with status code 400 (Bad Request): POST https://api.commerce.coinbase.com/charges
on this line of code
var response = await commerceApi.CreateChargeAsync(charge);
please help!!
Software | Version(s) |
---|---|
NuGet Package | this one |
.NET Core? | 2.1.802 |
.NET Full Framework? | 4.6 |
Windows OS? | windows 10 |
Linux OS? | N/A |
Visual Studio? | 19 |
Just get successfully get the charge from api request
Request works until the charge status is set to pending
thats why im here
Just make a charge send the money and try and request the api when its pending and you get a
null error json failed to deserialize
No
responsee = await commerceApi.GetChargeAsync(response.Data.Code);
Hi @bchavez I hope you are OK with using your issues board to page you. I am not sure of any other way to contact you. I wanted to let you know that Coinbase is actively engaging users on their new forum board and I brought up the issue in which we were both participants here:
The new issue is here:
https://forums.coinbasecloud.dev/t/any-web2-support/745
I thought you would find that interesting and/or might want to participate in the discussion there.
Hope all is well for you out there! 👍
(Oh yeah, please close this thread upon receipt!)
var requestSignature = Request.Headers[HeaderNames.WebhookSignature]; Request.InputStream.Seek(0, SeekOrigin.Begin); var json = new StreamReader(Request.InputStream).ReadToEnd();
HttpContext does not contain a definition of InputStream.
How to solve this
Request.Body.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(Request.Body)) { var json =await reader.ReadToEndAsync(); }
when testing my webhook, it throws 500 internal server error. and then in my server i see this error "The application completed without reading the entire request body."
Software | Version(s) |
---|---|
NuGet Package | 1.10.0 |
No error while convert webhook body to the object.
Error converting value {null} to type 'System.Int64'. Path 'payments[0].block.height'
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"
}
Coinbase sends the 'height' null value only when webhook type is 'charge:pending'
Change in Block class from
public long Height { get; set; }
to
public long? Height { get; set; }
Hi there
We prepared everything, but we need to have the IP ranges used by coinbase to configure our security settings on the server.
Can you provide a specific IP range or connection IP which is used by this service?
Coinbase Commerce Support couldnt send any so far.
Thanks
Michael
First off, thank you so much for putting this library together! Especially the Webhook integration. It's going to save me a lot of work. 👍
I did have a question that perhaps you can help answer for me. In my Coinbase Commerce account, I have created a Checkout. Now, in the API, it says Checkouts can have many charges and each charge is automatically generated on a per customer basis
.
However, when creating a charge, I do not see where to assign the checkout, neither in this API nor on Coinbase Commerce itself. So, I'm now officially confused. 😅
My understanding is you create a checkout and when you visit that checkout it creates a charge. You can also create a charge directly. However, it doesn't seem you can create a charge from a checkout (even though it seems this happens when you visit a created checkout from the Commerce settings).
I hope this makes sense. It would be really helpful to get this figured out.
Otherwise, great work out there. The documentation, too!
The front end seems to work just fine but the back end hooks don't seem to be working.
Issue 1) the test posts from coinbase seem to now include pricing: nil which blows up. I managed to fix this by writing in some logic to remove it from the json if it shows up.
The create seems to be working on but the confirm seems to always come back with invalid shared secret.
possible side note, I'm working outside of MVC and despite it posting the test posts to my end point seem always seem to come back with a message that says "Failed to establish a connection to the remote server". I am returning 200 but it's not caring.
Appreciate any insight you can offer.
public HttpResponseMessage CallbackFunction ()
{
try
{
string SHARED_SECRET = "<Secret>";
var requestSignature = Request.Headers[HeaderNames.WebhookSignature];
//owner_functions.CreateGeneralLog("CoinBase", requestSignature);
Request.InputStream.Seek(0, SeekOrigin.Begin);
var json = new StreamReader(Request.InputStream).ReadToEnd();
//clear up bad information if it's passed in
if (json.Contains("\"pricing\":\"nil\",")) { json = json.Replace("\"pricing\":\"nil\",", ""); }
owner_functions.CreateGeneralLog("CoinBase", json);
if (!WebhookHelper.IsValid(SHARED_SECRET, requestSignature, json))
{
//fail
owner_functions.CreateGeneralLog("CoinBase", "INVALID SHARED SECRET");
return new HttpResponseMessage(HttpStatusCode.Unauthorized);
}
var webhook = JsonConvert.DeserializeObject<Webhook>(json);
var chargeInfo = webhook.Event.DataAs<Charge>();
try
{
var customerId = chargeInfo.Metadata["customerId"].ToObject<string>();
}
catch { owner_functions.CreateGeneralLog("CoinBase Error", "No Customer ID Found"); }
var charge = webhook.Event.DataAs<Charge>();
if (webhook.Event.IsChargeCreated)
{
// The charge was created just now.
// Do something with the newly created
// event.
owner_functions.CreateGeneralLog("CoinBase", "Charge Created");
return new HttpResponseMessage(HttpStatusCode.OK);
}
else if (webhook.Event.IsChargeConfirmed)
{
// The payment was confirmed
owner_functions.CreateGeneralLog("CoinBase", "Charge Confirmed");
return new HttpResponseMessage(HttpStatusCode.OK);
}
else if (webhook.Event.IsChargeFailed)
{
// The payment failed. Log something.
owner_functions.CreateGeneralLog("CoinBase", "Charge Failed");
return new HttpResponseMessage(HttpStatusCode.OK);
}
return new HttpResponseMessage(HttpStatusCode.OK);
}
catch (Exception ex) {
owner_functions.CreateGeneralLog("CoinBase Error", ex.ToString());
return new HttpResponseMessage(HttpStatusCode.BadRequest);
}
}
Software | Version(s) |
---|---|
.NET Core? | 2.1.801, 3.1.100 |
.NET Full Framework? | 4.8 |
Windows OS? | Yes. Win 10 Pro 1903 (10.0.18362) |
Build succeeded
Build failed
Error:
System.Exception: Test failed on "test" --configuration Release --test-adapter-path:. --logger:"nunit;LogFilePath=Y:\work\Coinbase.Commerce\__test\results.xml"
в [email protected](String message) в D:\code\fake\src\app\FakeLib\DotNetCLIHelper.fs:line 298
в Fake.DotNetCli.Test(FSharpFunc`2 setTestParams) в D:\code\fake\src\app\FakeLib\DotNetCLIHelper.fs:line 298
в [email protected](Unit _arg4) в Y:\work\Coinbase.Commerce\Source\Builder\build.fsx:line 134
в Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) в D:\code\fake\src\app\FakeLib\TargetHelper.fs:line 626
---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target Duration
------ --------
Clean 00:00:00.0314926
restore 00:00:02.2319258
BuildInfo 00:00:00.0085929
dnx 00:00:04.6698891
test Failure
Total: 00:00:11.7333330
---------------------------------------------------------------------
Status: Failure
---------------------------------------------------------------------
---------------------------------------------------------------------
1) System.Exception: Test failed on "test" --configuration Release --test-adapter-path:. --logger:"nunit;LogFilePath=Y:\work\Coinbase.Commerce\__test\results.xml"
в [email protected](String message) в D:\code\fake\src\app\FakeLib\DotNetCLIHelper.fs:line 298
в Fake.DotNetCli.Test(FSharpFunc`2 setTestParams) в D:\code\fake\src\app\FakeLib\DotNetCLIHelper.fs:line 298
в [email protected](Unit _arg4) в Y:\work\Coinbase.Commerce\Source\Builder\build.fsx:line 134
в Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) в D:\code\fake\src\app\FakeLib\TargetHelper.fs:line 626
---------------------------------------------------------------------
Update NUnit3TestAdapter package to the latest version (3.15.1)
Hello thanks for the awesome library!
Is there any reason
CreateInvoiceAsync returns a URI in data.HostedUrl
and
CreateChargeAsync returns a string in the same field?
also, just to confirm is this the right way of passing multiple metadata:
Metadata =
{
{"userID", userID},
{"product", product},
{"extraID", extraID}
}
?
also, should
var commerceApi = new CommerceApi(APIKey);
.. be created for every transaction or is it safe to just create it once in the application?
and for bonus points, how do i attach metadata to an invoice? I couldn't see how to marry up the charge that is generated by the invoice with any meta data about the order.
sorry for the multiple questions!
Hi,
it would be great if we could extend the library to support the invoice api: https://commerce.coinbase.com/docs/api/#invoices
What do you think?
Hello, I'm doing the payment successfully, but I have not found which parameter to return in the callback address.
regards respects.
Webhook subscriptions : https://mysite.com/home/callback
public ActionResult callback(string ????)
{
// or Request.Form.Get("????");
try
{
var webhook = JsonConvert.DeserializeObject(????);
..............
Hi @bchavez
Thanks for putting this up on GitHub.
I was trying to use your package in my WebAPI project but I am unable to get pass these errors. For some reason, the only namespace I see under using Coinbase is Coinbase.Models. I see your package under my References section. Not sure what I am missing here.. See image below.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.