<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ayush Jain</title>
    <description>The latest articles on DEV Community by Ayush Jain (@aj54).</description>
    <link>https://dev.to/aj54</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F186031%2F607bd72e-761f-4cbd-8ea2-f70098fcf07d.jpg</url>
      <title>DEV Community: Ayush Jain</title>
      <link>https://dev.to/aj54</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aj54"/>
    <language>en</language>
    <item>
      <title>Add Messaging, File sharing, Activity Feeds in your website easily</title>
      <dc:creator>Ayush Jain</dc:creator>
      <pubDate>Tue, 27 Jul 2021 10:29:10 +0000</pubDate>
      <link>https://dev.to/aj54/add-messaging-file-sharing-activity-feeds-in-your-website-easily-2jlf</link>
      <guid>https://dev.to/aj54/add-messaging-file-sharing-activity-feeds-in-your-website-easily-2jlf</guid>
      <description>&lt;h1&gt;
  
  
  What is Weavy?
&lt;/h1&gt;

&lt;p&gt;Weavy is an in-app collaboration API and SDK, meaning that it provides you easy way to add features like in-app messaging, in-app activity feeds, in-app file sharing and in-app tasks management. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--acEaEejm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6yuauk7p3tuvek65ikcr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--acEaEejm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6yuauk7p3tuvek65ikcr.jpg" alt="Weavy" width="400" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What does in-app mean?
&lt;/h2&gt;

&lt;p&gt;In-app means that users will remain on your website/application and thus, you can add these features WITHOUT losing your user. Weavy has been designed with simplicity, easy usability, quick integration and complete feature set in mind. &lt;/p&gt;

&lt;h2&gt;
  
  
  Can I try it without doing anything?
&lt;/h2&gt;

&lt;p&gt;Sure, you can play around with all the features by going to &lt;a href="https://www.weavy.com/try/app"&gt;https://www.weavy.com/try/app&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How is my data secured?
&lt;/h2&gt;

&lt;p&gt;Your data is stored inside your cloud. Weavy provides you complete SDK (Client, Server, Tenant and Mobile) and you will be hosting everything on your cloud. Thus, your data never leaves your system. &lt;/p&gt;

&lt;h2&gt;
  
  
  How to get started?
&lt;/h2&gt;

&lt;p&gt;You can get started on your local machine by following &lt;a href="https://www.weavy.com/developer/getting-started/introduction-to-weavy"&gt;this&lt;/a&gt; article. &lt;/p&gt;

&lt;h2&gt;
  
  
  Is it Free?
&lt;/h2&gt;

&lt;p&gt;Weavy provide 30 days of FREE trial to all features (no questions asked, no limits placed). After that, the sales team will help you to get onboard or provide more extension. &lt;/p&gt;

&lt;h2&gt;
  
  
  Need Help?
&lt;/h2&gt;

&lt;p&gt;You can use &lt;a href="https://www.weavy.com/developer/contact"&gt;Get Help&lt;/a&gt; form to reach out and get assistance immediately.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>sdk</category>
      <category>collaboration</category>
    </item>
    <item>
      <title>Using Blockonomics Payment Button API</title>
      <dc:creator>Ayush Jain</dc:creator>
      <pubDate>Tue, 09 Feb 2021 16:22:19 +0000</pubDate>
      <link>https://dev.to/aj54/using-blockonomics-payment-button-api-3n68</link>
      <guid>https://dev.to/aj54/using-blockonomics-payment-button-api-3n68</guid>
      <description>&lt;p&gt;The Links to relevant resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create your Blockonomics Account- &lt;a href="https://www.blockonomics.co/merchants?ref=hPga3rGcrDj45w1C2jzkDMUPGBkCRYxNE6"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The Blog Post - &lt;a href="https://dev.to/aj54/blockonomics-payment-button-api-k3p"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The Github Repository - &lt;a href="https://github.com/blockonomics/Blockonomics_Payment_Button_Demo"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Creating Your Payment Button - &lt;a href="https://www.youtube.com/watch?v=1sE2r5tDkNY"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Setup local server for testing - &lt;a href="https://dev.to/aj54/testing-blockonomics-api-locally-9gi"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Blockonomics Payments API Documentation - &lt;a href="https://www.blockonomics.co/views/api.html#payments"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>php</category>
      <category>laravel</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Using Blockonomics Bitcoin Payments API</title>
      <dc:creator>Ayush Jain</dc:creator>
      <pubDate>Tue, 09 Feb 2021 16:17:06 +0000</pubDate>
      <link>https://dev.to/aj54/using-blockonomics-bitcoin-payments-api-1ldc</link>
      <guid>https://dev.to/aj54/using-blockonomics-bitcoin-payments-api-1ldc</guid>
      <description>&lt;p&gt;The Link to relevant resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create your Blockonomics Account- &lt;a href="https://www.blockonomics.co/merchants?ref=hPga3rGcrDj45w1C2jzkDMUPGBkCRYxNE6"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github Repository - &lt;a href="https://github.com/blockonomics/Django-Image-Store"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Blockonomics Account Create - &lt;a href="http://blockonomics.co/"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Blockonomics API Documentation - &lt;a href="https://www.blockonomics.co/views/api.html#payments"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Setting Up HTTP Callback URL - &lt;a href="https://www.blockonomics.co/merchants#/page3"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The Blog Post  - &lt;a href="https://dev.to/aj54/using-blockonomics-bitcoin-payments-api-5021"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>django</category>
      <category>python</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Testing Blockonomics Payments API Locally</title>
      <dc:creator>Ayush Jain</dc:creator>
      <pubDate>Tue, 09 Feb 2021 16:11:58 +0000</pubDate>
      <link>https://dev.to/aj54/testing-blockonomics-api-locally-9gi</link>
      <guid>https://dev.to/aj54/testing-blockonomics-api-locally-9gi</guid>
      <description>&lt;p&gt;The Link to Resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create your Blockonomics Account- &lt;a href="https://www.blockonomics.co/merchants?ref=hPga3rGcrDj45w1C2jzkDMUPGBkCRYxNE6"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Ngrok Download - &lt;a href="https://ngrok.com/download"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;localtunnel - &lt;a href="https://github.com/localtunnel/localtunnel"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Create Blockonomics Account - &lt;a href="http://blockonomics.co"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The Blog - &lt;a href="https://dev.to/aj54/testing-blockonomics-payment-api-s-locally-h11"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>testing</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Using Blockonomics Payment Button API</title>
      <dc:creator>Ayush Jain</dc:creator>
      <pubDate>Mon, 01 Feb 2021 10:30:30 +0000</pubDate>
      <link>https://dev.to/aj54/blockonomics-payment-button-api-k3p</link>
      <guid>https://dev.to/aj54/blockonomics-payment-button-api-k3p</guid>
      <description>&lt;p&gt;In this tutorial, we are going to look at a super-easy way to accept Bitcoin payments on your website. This method requires just a few lines of code and the majority of work is done by Blockonomics.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Blockonomics?
&lt;/h1&gt;

&lt;p&gt;Blockonomics is a decentralized Bitcoin payment solution that provides you with specialized transactional tools to enhance your BTC use. With Blockonomics, you can generate Bitcoins by accepting it on your online stores, as well as utilitarian features such as creating P2P invoices, sending emails via Bitcoin, and tracking your wallet addresses.&lt;/p&gt;

&lt;h1&gt;
  
  
  What we’re building
&lt;/h1&gt;

&lt;p&gt;We are building an online art shop. The purpose of this Demo shop is to showcase the use of Payment Button API. In order to gain premium content from the shop, you need to purchase the premium pass. This transaction will be done using the Blockonomics Payment Button API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up
&lt;/h2&gt;

&lt;p&gt;The entire code for this demo is available on Github and you can fork it &lt;a href="https://github.com/AJ-54/Blockonomics_Payment_Button_Demo" rel="noopener noreferrer"&gt;here&lt;/a&gt;. The step by step instructions on how to set up the demo is provided in the &lt;code&gt;README&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Once you have completed the setup, you can now navigate to &lt;code&gt;http://127.0.0.1:8000/&lt;/code&gt; to see the demo live. &lt;/p&gt;

&lt;h2&gt;
  
  
  Native Payment API vs Payment Button API
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Features&lt;/th&gt;
&lt;th&gt;Native Payments API&lt;/th&gt;
&lt;th&gt;Payment Button API&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Order/Bitcoin Address Management&lt;/td&gt;
&lt;td&gt;You&lt;/td&gt;
&lt;td&gt;Blockonomics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Checkout Interface&lt;/td&gt;
&lt;td&gt;You&lt;/td&gt;
&lt;td&gt;Blockonomics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Automated email for order confirmations&lt;/td&gt;
&lt;td&gt;You&lt;/td&gt;
&lt;td&gt;Blockonomics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Customer Field Input&lt;/td&gt;
&lt;td&gt;You&lt;/td&gt;
&lt;td&gt;Blockonomics&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The above table summarises that if you do not want to worry much about how the bitcoin address is being managed, how the checkout interface of my website looks like, and other utilities like order confirmation mail, etc., then Blockonomics Payment Button API is the right choice for you. But, if you care about the checkout interface or the way email messages are being sent to your customers, you can choose to go with native Payments API and create your own stuff from scratch. The blog for native Payments API can be found &lt;a href="https://dev.to/aj54/using-blockonomics-bitcoin-payments-api-5021"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Logic
&lt;/h2&gt;

&lt;p&gt;You might have placed your own Payment Button in the code when doing the setup. It is important to configure the Database and understand the logic for the Order Hook URL endpoint. &lt;/p&gt;

&lt;h3&gt;
  
  
  Database Configuration
&lt;/h3&gt;

&lt;p&gt;Since we are using the Payment Buttons API, all the concerned stuff is taken care by Blockonomics, so we just need to know which user is a premium user and which is a standard (non-premium) user. Thus, I have simply added &lt;code&gt;status&lt;/code&gt; field in &lt;code&gt;User&lt;/code&gt; table to attach the &lt;a href="https://www.blockonomics.co/views/api.html#paymentbuttons" rel="noopener noreferrer"&gt;status code&lt;/a&gt; of the transaction made by that user.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmd8x9xe37z2mhbt62oyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmd8x9xe37z2mhbt62oyo.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Order Hook URL and Redirection URL
&lt;/h3&gt;

&lt;p&gt;It is really important to understand the meaning of the above terms before you code your logic. &lt;br&gt;
&lt;code&gt;Order Hook URL&lt;/code&gt; is the endpoint that is used by Blockonomics to provide you status update notifications of the transactions done using Payment Buttons/Links you created.&lt;br&gt;
&lt;code&gt;Redirection URL&lt;/code&gt; is the endpoint on which the user is redirected once the transaction is carried out. This does not mean the transaction was successful, and thus your redirection URL should &lt;strong&gt;NOT&lt;/strong&gt;  point towards the paid content. &lt;br&gt;
You should unlock the premium content only upon the confirmation received on the &lt;code&gt;Order Hook URL&lt;/code&gt; from Blockonomics.&lt;/p&gt;
&lt;h3&gt;
  
  
  Order Hook URL Endpoint Logic
&lt;/h3&gt;

&lt;p&gt;Blockonomics hits the endpoint with a &lt;code&gt;GET&lt;/code&gt; request, passing the Bitcoin &lt;code&gt;address&lt;/code&gt; and the &lt;code&gt;status&lt;/code&gt; of the transaction carried using the given address. &lt;br&gt;
We can use the &lt;a href="https://www.blockonomics.co/views/api.html#paymentbuttons" rel="noopener noreferrer"&gt;&lt;em&gt;Get Order API&lt;/em&gt;&lt;/a&gt; to know the details about the user who used the given bitcoin address to perform the transaction. &lt;code&gt;Email&lt;/code&gt; can be used as a source of identification but you can pass any logic as you like. Here, we identify the user using the email and update the status of that user with the one that Blockonomics provided.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function handle(Request $request)
    {
        $address = $request-&amp;gt;addr;
        $status = $request-&amp;gt;status;

        try{
            $client =  new Client();
            $response = $client-&amp;gt;get('https://www.blockonomics.co/api/merchant_order/'.$address,[
                'headers'=&amp;gt;['Authorization'=&amp;gt; 'Bearer '.env('Blockonomics_API','')],
            ]);
            $data = json_decode($response-&amp;gt;getBody());
            $data_string =json_encode($data);

            $mail = $data-&amp;gt;data-&amp;gt;emailid;
            $user = User::where('email','=',$mail)-&amp;gt;first();
            $user-&amp;gt;status = (string)$status;
            $user-&amp;gt;save();   
        }
        catch (\Exception $e){
            error_log($e);
        }
    } 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thus, we successfully configured the Order Hook URL Endpoint. We can easily use the status information anywhere in our code to know if we can grant access to some information for this user. &lt;/p&gt;

&lt;h2&gt;
  
  
  The End
&lt;/h2&gt;

&lt;p&gt;Before we end, the video tutorial for this entire demo is linked below. For any queries, feel free to use the comments section!&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/IFjfkD3nRNE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>php</category>
      <category>tutorial</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Testing Blockonomics Payment API's Locally</title>
      <dc:creator>Ayush Jain</dc:creator>
      <pubDate>Fri, 29 Jan 2021 08:08:23 +0000</pubDate>
      <link>https://dev.to/aj54/testing-blockonomics-payment-api-s-locally-h11</link>
      <guid>https://dev.to/aj54/testing-blockonomics-payment-api-s-locally-h11</guid>
      <description>&lt;p&gt;In this tutorial, we are going to understand how to test our Blockonomics Payment APIs locally without deploying them to the production/testing environment. &lt;/p&gt;

&lt;h1&gt;
  
  
  What is Blockonomics?
&lt;/h1&gt;

&lt;p&gt;Blockonomics is a decentralized Bitcoin payment solution that provides you with specialized transactional tools to enhance your BTC use. With Blockonomics, you can generate Bitcoins by accepting it on your online stores, as well as utilitarian features such as creating P2P invoices, sending emails via Bitcoin, and tracking your wallet addresses. Create your Blockonomics Account- &lt;a href="https://www.blockonomics.co/merchants?ref=hPga3rGcrDj45w1C2jzkDMUPGBkCRYxNE6" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What we’re building
&lt;/h1&gt;

&lt;p&gt;We are going to understand the use of reverse proxy, allowing us to create a public URL for the code which is local to our system. Using the public URL, we can place it as an endpoint to the HTTP Callback URL required by Blockonomics.  &lt;/p&gt;

&lt;h1&gt;
  
  
  Setting Up
&lt;/h1&gt;

&lt;p&gt;In order to expose our code to the public URL's, we shall use the Ngrok. Later, we will generate the public URL which actively listens to a specific port on our local system. This allows us to communicate from that port with the rest of the world!&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Ngrok
&lt;/h2&gt;

&lt;p&gt;To install Ngrok on your machine, refer to the &lt;a href="https://ngrok.com/download" rel="noopener noreferrer"&gt;official page&lt;/a&gt;. After you download, navigate to the directory and type &lt;code&gt;ngrok.exe http 8000&lt;/code&gt;. This will start listening to the &lt;code&gt;8000&lt;/code&gt; port and you can see a terminal page like this: &lt;br&gt;
 &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fos3jlyiz2yeoy3mxyd9o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fos3jlyiz2yeoy3mxyd9o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my case, the public URL is &lt;code&gt;http://7db20c5efe6d.ngrok.io&lt;/code&gt; and I can make requests on this URL and it will redirect those requests to my localhost at the specified port, in our case port &lt;code&gt;8000&lt;/code&gt;. &lt;/p&gt;
&lt;h2&gt;
  
  
  Configuring HTTP CallBack URL
&lt;/h2&gt;

&lt;p&gt;Once you have a public URL listening to your localhost, you can use it as a webhook to test the Blockonomic Payment APIs. For example, you have configured a &lt;code&gt;/receive/&lt;/code&gt; route that is responsible for processing the requests coming from Blockonomics about the status update of the transactions, then you should set up the HTTP Callback URL as &lt;code&gt;&amp;lt;your_ngrok_domain&amp;gt;/receive&lt;/code&gt; on &lt;a href="https://www.blockonomics.co/merchants#/page3" rel="noopener noreferrer"&gt;this page&lt;/a&gt; and this will redirect the Blockonomics requests to your localhost at the specified route. &lt;br&gt;
Thus, you can test your logic and the Blockonomics Payment APIs without deploying them to any cloud platform.   &lt;/p&gt;
&lt;h1&gt;
  
  
  The END
&lt;/h1&gt;

&lt;p&gt;Here is the youtube video, explaining the entire tutorial on testing the Blockonomics Payment API's locally. If you have any queries, feel free to use the comments section!&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/6Ydk32avIgo"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>beginners</category>
      <category>testing</category>
      <category>programming</category>
    </item>
    <item>
      <title>Using Blockonomics Bitcoin Payments API</title>
      <dc:creator>Ayush Jain</dc:creator>
      <pubDate>Sat, 23 Jan 2021 16:24:58 +0000</pubDate>
      <link>https://dev.to/aj54/using-blockonomics-bitcoin-payments-api-5021</link>
      <guid>https://dev.to/aj54/using-blockonomics-bitcoin-payments-api-5021</guid>
      <description>&lt;p&gt;In this tutorial, we are going to use Blockonomics Payment API to receive Bitcoin payments on our website.&lt;/p&gt;

&lt;h1&gt;
  
  
  What is Blockonomics?
&lt;/h1&gt;

&lt;p&gt;Blockonomics is a decentralized Bitcoin payment solution that provides you with specialized transactional tools to enhance your BTC use. With Blockonomics, you can generate Bitcoins by accepting it on your online stores, as well as utilitarian features such as creating P2P invoices, sending emails via Bitcoin, and tracking your wallet addresses. &lt;/p&gt;

&lt;h1&gt;
  
  
  What we’re building
&lt;/h1&gt;

&lt;p&gt;We will create an online shop that will accept Bitcoin payments using &lt;a href="https://www.blockonomics.co/views/api.html#payments"&gt;Blockonomics Payment API&lt;/a&gt;. Let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Tech Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Django&lt;/li&gt;
&lt;li&gt;HTML/CSS&lt;/li&gt;
&lt;li&gt;Javascript&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting Up
&lt;/h2&gt;

&lt;p&gt;Before getting started, you can set up the local version of this tutorial using &lt;a href="https://github.com/AJ-54/Blockonomics"&gt;github repository&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/AJ-54/Blockonomics.git
pip install -r requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure you have your Blockonomics API Key handy. To get one for free, &lt;a href="https://www.blockonomics.co/register#"&gt;create your account&lt;/a&gt; and get to &lt;a href="https://www.blockonomics.co/merchants"&gt;this&lt;/a&gt; page.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Inside Blockonomics folder, go to  &lt;code&gt;settings.py&lt;/code&gt; file and place your &lt;strong&gt;API KEY&lt;/strong&gt; to the &lt;code&gt;API_KEY&lt;/code&gt; variable&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python manage.py migrate
python manage.py runserver
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you go to &lt;a href="http://127.0.0.1:8000"&gt;http://127.0.0.1:8000&lt;/a&gt;, you will be able to see the same screen like that of &lt;a href="https://blockonomics.herokuapp.com"&gt;https://blockonomics.herokuapp.com&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The HTTP Callback URL
&lt;/h3&gt;

&lt;p&gt;To use the Bitcoin payments API, you need to set up the order hook URL at your &lt;a href="https://www.blockonomics.co/merchants#/page3"&gt;merchant page&lt;/a&gt; on the Blockonomics website. Every time a transaction carried on the address associated with your API key changes its status, Blockonomics will use the HTTP Callback URL provided by you to notify you about the status update. Also, new transaction notifications are also provided using the same HTTP Callback URL.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Logic
&lt;/h2&gt;

&lt;p&gt;In order to integrate Blockonomics payment API, you should know how the process works. Firstly, you need the Blockonomics account and your API Key. Next, you should use a unique Bitcoin address every time you do a transaction. You can request a new address using the &lt;a href="https://www.blockonomics.co/views/api.html#newaddress"&gt;New Address API&lt;/a&gt;. Once the buyer uses that Bitcoin address to transfer the amount, you will get the status update from Blockonomics on the &lt;code&gt;HTTP Callback URL&lt;/code&gt; provided by you. Thus, your backend logic must process the requests received at that endpoint to classify the transactions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Payments App
&lt;/h2&gt;

&lt;p&gt;I have created a core Django application called &lt;code&gt;payments&lt;/code&gt; which is responsible for everything. &lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding Models
&lt;/h3&gt;

&lt;p&gt;To store the information about the transactions, I created an &lt;code&gt;Invoice&lt;/code&gt; table. The table looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Invoice(models.Model):
    STATUS_CHOICES = ((-1,"Not Started"),(0,'Unconfirmed'),
   (1,"Partially Confirmed"), (2,"Confirmed"))

    product = models.ForeignKey("Product", on_delete=models.CASCADE)
    status = models.IntegerField(choices=STATUS_CHOICES, default=-1)
    order_id = models.CharField(max_length=250)
    address = models.CharField(max_length=250, blank=True, null=True)
    btcvalue = models.IntegerField(blank=True, null=True)
    received = models.IntegerField(blank=True, null=True)
    txid = models.CharField(max_length=250, blank=True, null=True)
    rbf = models.IntegerField(blank=True, null=True)
    created_at = models.DateField(auto_now=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Invoice&lt;/code&gt; table stores the &lt;code&gt;product&lt;/code&gt; for which the invoice is created, the &lt;code&gt;address&lt;/code&gt; is the Bitcoin address used for this transaction. The &lt;code&gt;btcvalue&lt;/code&gt; is the amount that you have charged from the buyer and &lt;code&gt;received&lt;/code&gt; is the amount you receive from the buyer. Both these values will be in satoshi. The most important field is &lt;code&gt;status&lt;/code&gt; which describes the current status of this transaction. &lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Payment Invoice
&lt;/h3&gt;

&lt;p&gt;Once the user clicks on the price button, we process the request inside &lt;code&gt;create_payment&lt;/code&gt; view. The job here is to create a new object in the &lt;code&gt;Invoice&lt;/code&gt; table and then redirect the request to the &lt;code&gt;track_invoice&lt;/code&gt; view.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def exchanged_rate(amount):
    url = "https://www.blockonomics.co/api/price?currency=USD"
    r = requests.get(url)
    response = r.json()
    return amount/response['price']

def create_payment(request, pk):

    product_id = pk
    product = Product.objects.get(id=product_id)
    url = 'https://www.blockonomics.co/api/new_address'
    headers = {'Authorization': "Bearer " + settings.API_KEY}
    r = requests.post(url, headers=headers)
    print(r.json())
    if r.status_code == 200:
        address = r.json()['address']
        bits = exchanged_rate(product.price)
        order_id = uuid.uuid1()
        invoice = Invoice.objects.create(order_id=order_id,
                                address=address,btcvalue=bits*1e8, product=product)
        return HttpResponseRedirect(reverse('payments:track_payment', kwargs={'pk':invoice.id}))
    else:
        print(r.status_code, r.text)
        return HttpResponse("Some Error, Try Again!")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  HTTP Callback URL Endpoint
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;receive_payment&lt;/code&gt; view is the endpoint for receiving status updates from Blockonomics. It is used to sync our &lt;code&gt;Invoice&lt;/code&gt; table in the database with recent transactions and their status updates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def receive_payment(request):

    if (request.method != 'GET'):
        return 

    txid  = request.GET.get('txid')
    value = request.GET.get('value')
    status = request.GET.get('status')
    addr = request.GET.get('addr')

    invoice = Invoice.objects.get(address = addr)

    invoice.status = int(status)
    if (int(status) == 2):
        invoice.received = value
    invoice.txid = txid
    invoice.save()
    return HttpResponse(200)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Tracking Payment Invoice
&lt;/h3&gt;

&lt;p&gt;You can track any invoice if you know the invoice ID. The &lt;code&gt;track_invoice&lt;/code&gt; view fetches the latest data of that invoice ID from our database and passes it to the frontend. It also passes whether the user has paid the required amount, if yes then the &lt;code&gt;paid&lt;/code&gt; variable is also passed to the frontend. At this point, you can add your business logic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def track_invoice(request, pk):
    invoice_id = pk
    invoice = Invoice.objects.get(id=invoice_id)
    data = {
            'order_id':invoice.order_id,
            'bits':invoice.btcvalue/1e8,
            'value':invoice.product.price,
            'addr': invoice.address,
            'status':Invoice.STATUS_CHOICES[invoice.status+1][1],
            'invoice_status': invoice.status,
        }
    if (invoice.received):
        data['paid'] =  invoice.received/1e8
        if (int(invoice.btcvalue) &amp;lt;= int(invoice.received)):
            data['path'] = invoice.product.product_image.url
    else:
        data['paid'] = 0  

    return render(request,'invoice.html',context=data)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Invoice Page Front End
&lt;/h3&gt;

&lt;p&gt;In the frontend, we have displayed all the data we get from &lt;code&gt;track_invoice&lt;/code&gt; view. But, when the transaction status gets updated, how will the buyer know about it? &lt;br&gt;
To address this issue, we can either continuously pool our database to get the recent status of this invoice or we can use the WebSocket provided by Blockonomics. It is &lt;strong&gt;HIGHLY&lt;/strong&gt; recommended to use WebSocket as continuous polling may have serious effects on system performance. Blockonomics pushes the status update through websocket as well, so your frontend will instantaneously know the changes, so you know that your page is now outdated. At this point, you can either reload the page to get recent data from &lt;code&gt;track_invoice&lt;/code&gt; view or use AJAX calls to do the same. It is recommended to use a time out of 1 second, because &lt;code&gt;receive_payment&lt;/code&gt; view will take some time to update the database with details and once you wait for a while, you are assured that your database is updated and thus you can perform the action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var socket = new WebSocket("wss://www.blockonomics.co/payment/"+ address);
socket.onmessage = function(event){
  response = JSON.parse(event.data);
  //This condition ensures that we reload only when we get a 
  //new payment status and don't go into a loop
    if (parseInt(response.status) &amp;gt; parseInt(status))
    setTimeout(function(){window.location.reload() }, 1000); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The End
&lt;/h2&gt;

&lt;p&gt;The video tutorial explaining the entire demo is attached below. In case you have queries, feel free to use the comment section!&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/xGeD1UUXpMk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>django</category>
      <category>javascript</category>
      <category>python</category>
    </item>
  </channel>
</rss>
