merchant-frontend-examples

ZZZ: Inactive/Deprecated
Log | Files | Refs

fulfillment-js.php (1402B)


      1 <?php
      2   // This file is in the public domain.
      3 
      4   include 'contract.php';
      5   include 'backend.php';
      6   include 'error.php';
      7 
      8   session_start();
      9 
     10   if(pull($_SESSION, 'paid', false)){
     11     echo sprintf("<p>Thanks for your donation!</p>
     12                   <br>
     13                   <p>The transaction ID was: %s; use it to
     14                   track your money.</p>",
     15                   $_SESSION['transaction_id']);
     16     return;
     17   }
     18 
     19   $_SESSION['transaction_id'] = $_GET['transaction_id'];
     20 
     21   $now = new DateTime();
     22   $now->setTimestamp(intval($_GET["timestamp"]));
     23 
     24   $rec_proposal = make_contract(intval($_GET['transaction_id']), $now);
     25   $response = post_to_backend("/contract", $rec_proposal);
     26   http_response_code($response["status_code"]);
     27   if (200 != $response["status_code"]) {
     28     echo build_error($response,
     29                      "Failed to reconstruct the contract",
     30                      $response['code']);
     31     return;
     32   }
     33 
     34   // Import the script
     35   echo "<script src=\"/taler-wallet-lib.js\" type=\"application/javascript\"></script>";
     36   // Invoke executePayment(). Note that the returned status code
     37   // does not matter now, so 200 OK is fine.
     38   $body = json_decode($response['body']);
     39   echo sprintf("<script>taler.executePayment(\"%s\", \"%s\", \"%s\");</script>",
     40                $body->H_contract,
     41                url_rel("/pay.php"),
     42                url_rel("/generate-contract.php"));
     43   return;
     44 ?>