'How to Track Successful Payment on Coinbase Commerce Webhook Directly on my Website

Please I need help on how to to go about this.

I am currently building a website to enable bitcoin payment directly on my website. After creating a checkout on Coinbase Commerce, I got an embedded code which I added to my website.

Here is the embedded html code from Coinbase Commerce checkout:

<div>
  <a class="buy-with-crypto"
     href="https://commerce.coinbase.com/checkout/xxxxxxxxxxxxxxxxx">
    Buy with Crypto
  </a>
  <script src="https://commerce.coinbase.com/v1/checkout.js?version=201807">
  </script>
</div>

And here is an image showing the result of the code above.

Payment via Conbase Commerce

Everything works fine. But my problem is how to track a successful payment, since they are paying for an item that needs to be delivered immediately after they have paid. I have downloaded the coinbase-commerce-php api from Github, but the truth is I don't know how to use it. I'm not too familiar with composer, vendor, autoload... and how to use the Json responds. However, I'm quite good with a lot of PHP codes.

My question is:

  1. Does the embedded code above supply any unique ID that can be used to track each transaction?

  2. If yes; how can I get, and use this ID to track a transaction?

Please I'd appreciate it if anyone can help me out on this. I'm also familiar with JavaScript. So either PHP or JavaScript response is accepted. Thanks.



Solution 1:[1]

You can use the Coinbase Commerce webhooks to notify you when a payment is successful.

The relevant documentation is here.

Solution 2:[2]

Using webhooks is a bit advance. I would prefer using javascript. For getting reply with javascript it is in their documentation but i'll paste it here.

<script>

BuyWithCrypto.registerCallback('onSuccess', function(e){
    // Charge was successfully completed
});

BuyWithCrypto.registerCallback('onFailure', function(e){
    // Charge failed
});

BuyWithCrypto.registerCallback('onPaymentDetected', function(e){
    // Payment has been detected but not yet confirmed
});

</script>

I hope this solves your problem ?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 C. Gluck
Solution 2 Victor Pianwi