diff options
Diffstat (limited to 'doc/examples/pay_handler.php')
-rw-r--r-- | doc/examples/pay_handler.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/doc/examples/pay_handler.php b/doc/examples/pay_handler.php new file mode 100644 index 00000000..3b10b0c2 --- /dev/null +++ b/doc/examples/pay_handler.php @@ -0,0 +1,20 @@ +# Check if a session exists already +session_start(); +if (! isset($_SESSION['paid'])) @{ + echo "<p>There is no session for this purchase. Something is wrong.</p>"; + return; +@} +# Get the HTTP POST body +$payment = file_get_contents('php://input'); +$response = post_to_backend("/pay", $payment); +if (200 != $response->getResponseCode())@{ + echo json_encode(array( + 'error' => "internal error", + 'hint' => "failed to POST coins to the backend", + 'detail' => $response->body->toString() + ), JSON_PRETTY_PRINT); + return; +@} +$_SESSION['paid'] = true; +return $response->body; + |