Closed ZKRYLN closed 6 years ago
Hi @ZKRYLN ,
The Coinbase Commerce documentation isn't quite clear on what to return. Basically, what I've done is return an HTTP 200 status code and seems to work.
return new HttpStatusCodeResult(HttpStatusCode.OK);
Let me know if you have any other issues.
Thanks, Brian
:man: :checkered_flag: "Louie Louie, oh no... Me gotta go... Aye-yi-yi-yi, I said"
In more detail for completeness, here is the code I use:
[Route("some_route/webhook"), HttpPost]
public ActionResult Coinbase_Webhook()
{
var requestSignature = Request.Headers[HeaderNames.WebhookSignature];
Request.InputStream.Seek(0, SeekOrigin.Begin);
var json = new StreamReader(Request.InputStream).ReadToEnd();
if (!WebhookHelper.IsValid(SHARED_SECRET, requestSignature, json)){
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
var webhook = JsonConvert.DeserializeObject<Webhook>(json);
if (webhook.Event.IsChargeConfirmed)
{
var charge = webhook.Event.DataAs<Charge>();
if (charge.Name == "PRODUCT_NAME")
{
//THE PAYMENT IS SUCCESSFUL
//DO SOMETHING TO MARK THE PAYMENT IS COMPLETE
//IN YOUR DATABASE
}
}
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
:walking_woman: :ok_hand: Danelle & Salda - Nobody
Hi @bchavez, good job thanks :)
hi, I made a donation, now I can ask the question :)
Response.Data.HostedUrl, can I open this address in iframe or modal? I could not find it in the documents and my english is a little bad. sorry
var url = response.Data.HostedUrl; return Json(new { iframe = url }, JsonRequestBehavior.AllowGet);
the server did not allow.
regards.
Hi @ZKRYLN ,
Thanks a lot for your donation. I appreciate it :)
As for your question: No, you cannot embed using an IFRAME due to Coinbase Commerce CSP:
content-security-policy: frame-ancestors 'none'; frame-src 'none'; default-src 'none';...
As you saw, the server instructs the browser not to allow it.
The best you can do is send a full page redirect:
var order = new CreateCharge
{
Name = "PRODUCT_NAME",
Description = "PRODUCT_DESCRIPTION",
PricingType = PricingType.FixedPrice,
LocalPrice = new Money
{
Amount = 3.00,
Currency = "USD"
},
Metadata =
{
{"purchaseId", PURCHASE_ID}
},
RedirectUrl = "https://mysite.com/some_route/complete"
};
var response = await this.CommerceApi.CreateChargeAsync(order);
return Redirect(response.Data.HostedUrl);
Notice how the RedirectUrl
is set above to: https://mysite.com/some_route/complete
. When the customer completes the payment, the user should be redirected to your server. You can handle it below:
[Route( "some_route/complete" ), HttpGet]
public ActionResult Coinbase_Complete()
{
//DISPLAY THE CHECKOUT COMPLETED VIEW
return View( "Complete" );
}
Hope that helps! Brian
:walking_man: :walking_woman: Missing Persons - Walking in L.A.
hi @bchavez I have successfully completed my tests, but I have a problem :) logo_url I could not find a code to add a logo, it's not on the website, (commerce.coinbase.com)
Hi @ZKRYLN,
I have the same problem too. I wasn't able to find a way to add a logo_url
so I left it as is.
I suspect this is maybe by design or a problem with their API.
You'll probably have to talk to them directly to find out if logo_url
can be set.
Try sending email to api@coinbase.com for support, posting on stack overflow, or using their support site.
If you find the answer, please let me know too. I would like to know if the logo_url
can be changed.
:dizzy: :boom: Chaos Chaos - Do You Feel It?
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
In more detail for completeness, here is the code I use:
[Route("some_route/webhook"), HttpPost] public ActionResult Coinbase_Webhook() { var requestSignature = Request.Headers[HeaderNames.WebhookSignature]; Request.InputStream.Seek(0, SeekOrigin.Begin); var json = new StreamReader(Request.InputStream).ReadToEnd(); if (!WebhookHelper.IsValid(SHARED_SECRET, requestSignature, json)){ return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var webhook = JsonConvert.DeserializeObject<Webhook>(json); if (webhook.Event.IsChargeConfirmed) { var charge = webhook.Event.DataAs<Charge>(); if (charge.Name == "PRODUCT_NAME") { //THE PAYMENT IS SUCCESSFUL //DO SOMETHING TO MARK THE PAYMENT IS COMPLETE //IN YOUR DATABASE } } return new HttpStatusCodeResult(HttpStatusCode.OK); }
πΆββ π Danelle & Salda - Nobody
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
@chuksgpfr , you'll have to find where the input stream is for the request body in your version of ASP.NET. MVC5 or ASP.NET Core. The HttpContext
and input stream locations are slightly different between versions. You'll have to modify the code to fit your environment.
Hope that helps, Brian
In more detail for completeness, here is the code I use:
[Route("some_route/webhook"), HttpPost] public ActionResult Coinbase_Webhook() { var requestSignature = Request.Headers[HeaderNames.WebhookSignature]; Request.InputStream.Seek(0, SeekOrigin.Begin); var json = new StreamReader(Request.InputStream).ReadToEnd(); if (!WebhookHelper.IsValid(SHARED_SECRET, requestSignature, json)){ return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var webhook = JsonConvert.DeserializeObject<Webhook>(json); if (webhook.Event.IsChargeConfirmed) { var charge = webhook.Event.DataAs<Charge>(); if (charge.Name == "PRODUCT_NAME") { //THE PAYMENT IS SUCCESSFUL //DO SOMETHING TO MARK THE PAYMENT IS COMPLETE //IN YOUR DATABASE } } return new HttpStatusCodeResult(HttpStatusCode.OK); }
πΆββ π Danelle & Salda - Nobody
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 Pls using: HttpContext.Current.Request....
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(????);
..............