Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback parameters #1

Closed
ZKRYLN opened this issue Apr 19, 2018 · 11 comments
Closed

Callback parameters #1

ZKRYLN opened this issue Apr 19, 2018 · 11 comments

Comments

@ZKRYLN
Copy link

ZKRYLN commented Apr 19, 2018

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(????);
..............

@bchavez
Copy link
Owner

bchavez commented Apr 19, 2018

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

👨 🏁 "Louie Louie, oh no... Me gotta go... Aye-yi-yi-yi, I said"

@bchavez bchavez closed this as completed Apr 19, 2018
@bchavez
Copy link
Owner

bchavez commented Apr 19, 2018

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

@ZKRYLN
Copy link
Author

ZKRYLN commented Apr 20, 2018

Hi @bchavez,
good job thanks :)

@ZKRYLN
Copy link
Author

ZKRYLN commented Apr 21, 2018

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);

<script> function CoinBaseLoad(result) { $("#coinbase").empty().append("<iframe src='" + result.iframe + "' style=\"border: 0; width: 100%; height: 500px; overflow:hidden;\"></iframe>"); } </script>

the server did not allow.

regards.

@bchavez
Copy link
Owner

bchavez commented Apr 21, 2018

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

🚶‍♂️ 🚶‍♀️ Missing Persons - Walking in L.A.

@ZKRYLN
Copy link
Author

ZKRYLN commented Apr 24, 2018

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)

@bchavez
Copy link
Owner

bchavez commented Apr 24, 2018

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 [email protected] 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.

💫 💥 Chaos Chaos - Do You Feel It?

@chuksgpfr
Copy link

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
Copy link

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

@bchavez
Copy link
Owner

bchavez commented May 28, 2019

@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

@smilehun
Copy link

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....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants