Adding Bitcoin Payment Processing to Your Webstek

Adding Bitcoin Payment Processing to Your Website

Bitcoin has certainly commenced to become more mainstream, and with its global reach and minimal fees, it is a payment method worth considering.

Ter this article, wij will take a look at what Bitcoin is, spil well spil how to embark accepting them te your applications.

What Is Bitcoin?

Very first things very first, what is Bitcoin? For the un-familiar, Bitcoin is a peer-to-peer currency, developed to eliminate the need for a third party trusted authority, and instead rely on intrinsic security by means of cryptographic hashes.

By removing a central authority (A government, canap, etc..) you reduce fees and lower requirements. There is no need to pack out forms or pay people’s salaries, so te a sense, the money secures itself.

I’m not going to get into the specifics, but essentially each time a transfer of currency takes place, the money is signed with the two parties keys and then hashed, and thesis transactions are appended to the global loom. This permits coins to be publicly traced back, and to see if the money indeed belongs to someone or not.

Advantages & Disadvantages

Now let’s take a look at some of the advantages and disadvantages associated with using Bitcoin:

  • Anyone can use it globally.
  • Somewhat anonymous.
  • Minimal fees.
  • No setup required.
  • The worth of the coins fluctuates.
  • Not spil mainstream spil other options (CC, Paypal).

The advantages all go after a similar pattern, te that because there is no central authority, anyone can use it at any time without needing any confirmations or acceptance, plus the fees are pretty low.

Now the disadvantages are varied. Since it is not spil mainstream spil other payment options, I don’t think it is fairly where it needs to be, te order to make it your only payment option. But by all means, if you are a meaty supporter and want this to grow, you can be a Bitcoin-only service, but I would suggest, for now, using it alongside another service, which accepts credit card.

The other disadvantage is the stability of Bitcoin’s value, at the beginning of this year, the worth of one bitcoin wasgoed around 12-14$ each, ter just a duo of months the coins went up to almost 240$ ter April and are presently worth around 110-115$ each. This is ter fat tegenstelling to traditional currencies, for your money to have a 2000% increase ter worth and then a 50% decrease, all within a few months seems like it should be a crimson flag.

It’s hard to say for sure, if this is just a bi-product of having a decentralized currency, or if it is due to the infancy of the program, but it is undoubtedly a concern.

Fortunately most Bitcoin processors, like the one I will be using te this article, permits you to instantly convert the Bitcoins or a portion of them into regular currency, like dollars, right away. You can for example setup that 80% of the Bitcoins that come te should be instantly converted and transferred to your canap account, removing this risk factor.

Ultimately, you can both build up and lose from thesis fluctuations, so it’s up to you to determine whether you want to gamble and leave more of it te Bitcoins, or eliminate all the risk and convert all of it.

Their are a duo popular services around that work like Coinbase, BitPay, etc. but the one I will be using ter this article is Kont.

The Premise

Te this article wij will be building a plain landing pagina, where you can come in te your email and click ‘purchase’ which will take you to the payment pagina. On the payment pagina, you will be given a Bitcoin wallet address which you can send the money to, and once you pay, you will receive the voorwerp you purchased via email.

Thesis three stages are entirely separate, spil te all payment options, but it stands out more here, since you can’t pay directly from the purchase form and need to pay from your own private Bitcoin wallet.

For this app, I will be using Snugger to provide a little structure, Mandrill for sending the product and, like I mentioned, Kont spil the payment processor to implement the Bitcoin side of things.

The Setup

So to install Slender, create a composer.json opstopping with the following:

Then run composer install (assuming you have composer installed) to install the dependencies.

Next, create a public folder with an index.php verkeersopstopping inwards of it, and a views folder.

Your structure should look something like this:

Now open the index.php opstopping and let’s setup the Snugger app:

Wij are requiring the autoloader, and then instantiating the Snugger library, so far just boilerplate. Next, let’s add the huis route which will be a standard HTML pagina with the form to begin a purchase:

And then wij need to add the huis.php view verkeersopstopping itself to the views folder:

Nothing too fancy, basically just a form to submit the user’s email.

The last chunk of setup wij need to finish is to sign up for both Kont and Mandrill (if you are using it) and generate API keys for both. Ter Kont, you go to the Merchant tabulator and generate an invoice API key, and for Mandrill you go to the SMTP & API Credentials pagina to generate a fresh API key.

Creating an Invoice

So far wij have a basic form which will submit a user’s email via a Postbode request, the next step is to take that email and generate an invoice for it.

Let’s add a postbode route to the index.php verkeersopstopping, which will generate an API call to create a fresh invoice and redirect the user to it:

There are a duo of things to notice here, for one, the API token you generated for creating invoices, is the ‘username’ te the HTTP authentication. The Postbode fields wij are sending are spil goes after:

  • price – the price of the object (an int or float value).
  • currency – a currency abbreviation like USD, GBP, EUR or BTC for prices ter Bitcoin itself.
  • voorwerp – the voorwerp’s name, this is optional but it will voorstelling up on the invoice.
  • custom-built – a JSON encoded string containing any custom-built gegevens you want affixed to the invoice. Whatever gets specified here will be passed back once the user pays, so you can waterput internal reference numbers or keys to a database, te our example I just waterput the email te since wij aren’t storing any other gegevens.

The API call will terugwedstrijd just the URL to the invoice itself, so wij can just get the response and redirect straight to it.

Now unlike other payment options, like a credit card or PayPal, there is no third party who treats the charge, so you can’t just come in your number or login to pay. Instead, it creates a custom-made wallet vanaf transaction, and gives you 15 minutes to transfer the amount specified into that account. This is what I wasgoed talking about earlier, that with Bitcoin, you notice the different steps during the payment process more, then you would with something like the one-click purchase on Amazon.

On the other palm, the advantage to a system like this is the congenital security that comes without you needing to do anything. You don’t overeenkomst with credit card numbers or processing payments, so the webpagina doesn’t need to be spil secure, you just create a fresh ‘identity’ or wallet, and if the money is transfered there, then the payment is ended successfully.

Completing the Purchase

The last step is to treat the actual purchase, once the payment has bot finished. To do this you need to add a callback URL and a secret key on the merchant tabulator of the Kont panel. I am just going to onmiddellijk it to the /ipn route, with a secret key of SECRETKEY .

The callback is a Postbode request which contains all the informatie from the purchase along with the custom-made gegevens you passed ter and a hash to verify that it is authentic. You verify the purchase by SHA-512 hashing the transaction key along with the secret you setup te the admin panel, and verify that it matches the computed ‘hash’ ter the callback’s request:

The transaction key and secret are just appended to one another and then wij hash them together. The last bit just checks if the status is 1 (which means the payment came ter) and checking the authenticity of the notification.

Wij now have the user’s address and wij have a payment confirmation, so the last step is to send the user some sort of voorwerp. If you are building a subscription service, or some kleintje of physical voorwerp, you can just loom the user’s payment into a database, but to wrap up this article, let’s take a geschreven look at sending an voorwerp with Mandrill.

Ter the above code, all wij’re doing is preparing all of the gegevens and building the JSON message request to be sent to the Mandrill API, you need to send the API key, the email’s subject and message, the from email/name and who the email is for.

For the message, wij are using Slender’s built te template instructions, and then wij Postbode the request using curl and json_encode to compile the gegevens into JSON.

Next, let’s create the template opstopping email.php (inwards the views folder). You can waterput just about anything you want te here, spil it is parsed spil a normal Slender template, and wij just terugwedstrijd the rendered HTML:

I just added a heading with a verbinding to the verkeersopstopping. If all went well, your webpagina should be fully working.

Conclusion

Ter this article wij went through the process of both creating an invoice spil well spil treating payments. Bitcoin can seem a bit daunting to get embarked with, but spil you can see, it is much simpler then one would think, even simpler then other payment options ter most cases.

I know this may be one of the most expensive demos to attempt out, so I have gotten an special photo by the talented web designer Melissa Keizer which you can purchase te the demo if you so wish.

I hope you loved this article, and thank you for reading. Like always, if you have any questions feel free to leave mij a comment below, on twitter, or te the Nettuts+ IRC channel on freenode.

Related movie: Effortless CPU Monero & Crypto Coin Miner For Mac OSX


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *