ads

Implement Coinbase API with Angular and PHP


Hello! developer (who is struggling to implement coinbase api with angular and php). this article is for you, the implementation of coinbase api is much more easier, they have already given a php example files which is in github (I will guide you, be patient), all you need to do is download it,edit it and upload to your hosting. that’s it :)

official documentation : https://commerce.coinbase.com/docs/api/

not clear yet? :p no worries I will guide you, here are the steps

important :

charge = “a request with the amount to be charge and the currency type eg :btc (bitcoin), this is a like a receipt in shop, although the charge is initialized still the payment from the client is not received), this charge function will initialize a payment and return some data with a charge id plus a code which can be used to redirect the user for the actual payment window

Step 1 : register for coinbase and get an API Key (if you don’t know how to do it, then just google or go to hell)

Step 2 : https://github.com/coinbase/coinbase-commerce-php here is the github repo to the coinbase php files, first download the given repo to your pc

Step 3 : next to get an payment from a client there is an example php file which we can use to charge the customer,so what you need to do is go to the examples/resources/ and open the chargeexample.php file in your favourite text editor (sublime recommended)

step 4 : when you open the file you will see the a place to add your api key, please do not hard code the api key, use a database to store the api key and retrieve it.

Step 5: now we are 20% done and all we need to do is remove the unnecessary code from the php file and keep only the code which we need to create a charge and return the charge details

due to the security reasons I can’t show you my whole code but make sure that the below shown code comes in the top of the php file, (change the charge object ($chargeobj = new charge() ) details as you needed

then after that, remove all other code that is useless but keep the below shown code only

save the php file, upload all the files to your hosting, then use postman and do a get request to the chargexample.php.

it will return a lot of data but what we are interested is is the timeline,transaction id and code

in the response there is a [code]=”12345", get that into a variable in your angular component ts file and then prepare a url like this

var code = data[‘code’];

this.url = “https://commerce.coinbase.com/checkout/”+code;

so your final url should look like this https://commerce.coinbase.com/checkout/yourcode

then use redirect the user to the above link which will show the checkout page where the user can do the payment. that’s all

need help in web development? no worries feel free to place an order on fiverr, I will help you. here is my profile link https://www.fiverr.com/chrissachin

#stay motivated, #be positive

1 comment:

  1. Wow... what a great article published by you. DO you know you can increase your cybersecurity by downloading this perfect Cybersecurity solution; Protegent Total Security Antivirus.
    www.protegent360.com/protegent-total-security.html

    ReplyDelete

Powered by Blogger.