am having my script for receiving bitcoin payments similar to PHP Receive Bitcoin Payments. almost that's what inspired me to do one in Perl.

I can check the received amount or if payment received but my problem is that how my script can determine that payment received and form action

I had a plan of using javascript to keep reloading the page. if our Perl scripts print Thank You. We Have Received Your Payment. then javascript can determine and stops reloading page frequently

I appricaite for any idea, and sample to do it better than that

Please, Feedback should not include of using mojo, dancer or crystal. Thanks

The Blockchain API Key and XPUB is valid. anyone is allowed to test

#!/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/to +btc?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 = "xpub6CrqZSp5gsjSGSfVjzEnKxJ6hrQ2AsPh1rUzGSHWM4bFRKqsWEyYZ3 +YTJeNcusJJToq9G9WAmRzZ8PJYanQW3mLQcJVcVUqEL7v1Z3SP6jk"; $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/19By3YDM62ivoPQSxsshnPt +cDzKh6nZMFR/?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, BUY +ER_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 <<START_HTML; <!DOCTYPE html> <html lang="en"> <head> <title>Blockchain Receive Payment In Perl</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <style type="text/css"> <!-- .red {color: #FF0000} .green {color: #006600} --> </style> </head> <body> <form method="post"> <p> <input type="text" name="usd_amount" placeholder="Amount In USD" req +uired> </p> <label> <input type="submit" name="Submit" value="Pay Now" /> </label> </form> <p>$html_p_tag</p> <p>$html_p_tag2</p> <div class="red"> $msg_1 </div> </div> <div class="green"> $msg_2 </div> </div> </body> </html> START_HTML

In reply to receiving btc payments by bigup401

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.