merchant-frontend-examples

ZZZ: Inactive/Deprecated
Log | Files | Refs

generate-order.php (946B)


      1 <?php
      2   // This file is in the public domain.
      3 
      4   include 'order.php';
      5   include 'backend.php';
      6   include 'error.php';
      7 
      8   $order_id = "tutorial-" . dechex(rand(0,99999999)) . date("-H_i_s");
      9   session_start();
     10   $_SESSION["order_id"] = $order_id;
     11   if(!isset($_GET["nonce"]))
     12     return build_error(array("body" => null),
     13                        "no nonce given",
     14                        400);
     15   $order = make_order($_GET["nonce"],
     16                       strval($order_id),
     17                       new DateTime('now'));
     18   // Here the frontend POSTs the proposal to the backend
     19   $response = post_to_backend("/proposal", $order);
     20   // We always return verbatim what the backend returned
     21   http_response_code($response["status_code"]);
     22   if (200 != $response["status_code"]) {
     23     echo build_error($response,
     24                      "Failed to generate proposal",
     25                      $response['status_code']);
     26     return;
     27   }
     28   echo $response["body"];
     29 ?>