#!/usr/bin/perl -w use HTTP::Request::Common qw(POST); use LWP::UserAgent; use JSON::XS; use Net::SSL; use CGI; use URI; use DBI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); my $CGI = CGI->new(); my $ua = LWP::UserAgent->new( ssl_opts => { verify_hostname => 0 }, ); # DB CONNECTION my $host = "localhost"; my $usr = "root"; my $pwd = ""; my $dbname = "tbtest"; my $DBH = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, { AutoCommit => 0, RaiseError => 1, }) or die $DBI::errstr; # ORDER DETAILS $ORDER_ID = '2018'; $BUYER_ID = 'test@test.com'; # BUYER AMOUNT HE/SHE SUPPOSED TO SEND IN USD $USD = $CGI->param("usd_amount"); # CONVERT BUYER USD TO BTC if ($USD){ my $amount_req = HTTP::Request->new(GET => "https://blockchain.info/tobtc?currency=USD&value=$USD"); $amount_req->content_type('application/json'); my $amount_res = $ua->request($amount_req); $amount = $amount_res->content; # GENERATE RECEIVING ADDRESS FOR PAYMENT $LINK = 'https://api.blockchain.info/v2/receive'; $API_KEY = "0698d13e-56cd-47ec-9e98-f166b1cba5ec"; $XPUB = "xpub6CrqZSp5gsjSGSfVjzEnKxJ6hrQ2AsPh1rUzGSHWM4bFRKqsWEyYZ3YTJeNcusJJToq9G9WAmRzZ8PJYanQW3mLQcJVcVUqEL7v1Z3SP6jk"; $CALL_BACK_URL = "https://localhost"; my $do = URI->new($LINK); $do->query_form( xpub => $XPUB, callback => $CALL_BACK_URL, key => $API_KEY, ); my $req = HTTP::Request->new(GET => $do); $req->content_type('application/json'); my $res = $ua->request($req); $respons = JSON::XS->new->decode ($res->content); $wallet = $respons->{address}; $html_p_tag = "Your Sending $amount BTC"; $html_p_tag2 = "To This Wallet $wallet"; if ($res) { #IF REQUEST SENT THEN # URL TO CHECK RECEIVED PAYMENTS $doLink = 'https://insight.bitpay.com/api/addr/19By3YDM62ivoPQSxsshnPtcDzKh6nZMFR/?noTxList=1'; my $check_received = HTTP::Request->new(GET => $doLink); $check_received->content_type('application/json'); my $res_received = $ua->request($check_received); $respons_received = JSON::XS->new->decode ($res_received->content); $received = $respons_received->{totalReceived}; # CHECK FOR NOT RECEIVED PAYMENT if ($received ne $amount) { $msg_1 = "Not Yet Received Your Payment"; } # CHECK IF PAYMENT / ACTUAL AMOUNT RECEIVED if ($received eq $amount) { my $create_order = $DBH->prepare("INSERT INTO ORDERS(ORDER_ID, BUYER_ID) VALUES(?,?)"); $create_order->execute($ORDER_ID, $BUYER_ID); $create_order->finish(); $msg_2 = "Thank You. We Have Received Your Payment"; } }} print "Content-type: text/html\n\n"; print < Blockchain Receive Payment In Perl

$html_p_tag

$html_p_tag2

$msg_1
$msg_2
START_HTML