Git Product home page Git Product logo

algo-pay-only-javascript's Introduction

algo-pay-only-javascript

Work in progress project to port AlgoPay react to pure javascript

build command (to dist folder, will create if does not exist):

npm run build

to correctly show css after bulding, modify the index.html that is generated in the dist folder by:

  • removing one of the <link> tags for the css
  • removing the numeric hash from the remaining <link>tag so that the href reads "styles.css"
  • renaming the js file to "index.js"
  • renaming the <script> tag src to "index.js"

Finally, copy your styles.css file into the dist folder.

Test build command on localhost:

serve -s dist

Algopay 2.1 Update: Add Post to custom URL (temp documentation for post)

in window details, add "backend_enable":false Script will work like always.

In window details, add "backend_enable":true,backend_url":"your_backend_url",backend_value1=your_value...." TXID and custom parameters will be sent by post to chosen URL

Example using pseudoPHP:

//Get the POST data $update = json_decode(file_get_contents("php://input"), TRUE); //Get the TXID $txid = $update["txid"]; //Get value 1, lets say we send customer email $email = $update["backend_value1"];

//Wait block for being processed sleep(5);

//Get the TX from algoexplorer $api_url = "https://algoexplorerapi.io/v2/transactions/pending/".$txid.""; $json_data = file_get_contents($api_url); $response_data = json_decode($json_data, true);

//There are several ways to do this (nonce, check only latest blocks) but this time we will check if transfer is not being reused //Define receiver account and price $account = "K3NSXYMHPRCK7PMYT3QUQXUGPZJ4MKWJXW2HJRYPVMQUMKJAOJEIEO4HK4" $price = 20000 //Look in database if TXID is being reinjected to disallow reusing payments $sql = "SELECT * FROM payments WHERE txid =".$txid.""; $result = $conn->query($sql); //If payment is being reused, exit. Client trying to hack. if (!empty($result)) { exit(); }

//If the paid amount is correct and the receiver address is correct and the product is still on sale process it if ($response_data["txn"]["txn"]["aamt"] == $price) { if ($response_data["txn"]["txn"]["arcv"] == $account) { if ($on_sale == 1) { //Mark product as sold, and save TxId to avoid future reuse $sql = "UPDATE payments set on_sale = 0, txid = $txid, email = $email WHERE id = $id; $conn->query($sql); //DO ACTIONS, for example, sending a confirmation email require 'PHPMailer/src/PHPMailer.php'; (...) $mail->addAddress($email) $mail->send(); }}

**THIS IS NOT A COMPLETE INTEGRATION, BUT ITS VALID ESPECIALLY FOR INEXHAUSTIBLE PRODUCTS (Like API keys or replaceable physical products) **** Not fully tested, make your own test!

algo-pay-only-javascript's People

Contributors

headline-design avatar derciamas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.