payment-test.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * This is a script for testing payments.
  4. * Users will arrive here after having completed a booking.
  5. * Depending on the config, this will simulate a completed or a failed payment
  6. * and then return the user to their booking.
  7. */
  8. if ($_POST['Result'])
  9. {
  10. // This is the API key from the main setup page
  11. define('API_TOKEN', '[paste your payment api token here]');
  12. // This is the secret key from the payments API setup page on dancecamps.org
  13. define('SECRET', '[paste your secret key here]');
  14. // Include the PHP SDK
  15. include_once 'dancecampsPayment.class.php';
  16. $BookingID=$_POST['BookingID'];
  17. $Amount=$_POST['Amount'];
  18. $CampURL=$_POST['CampURL'];
  19. // This is where a real payment would be made.
  20. // Here will we just simulate the results
  21. $Result=$_POST['Result'];
  22. $Currency=$_POST['Currency'];
  23. $TxnID=$_POST['TxnID'];
  24. $Fee=$_POST['FeeAmount'];
  25. // The payment was made, send the info to dancecamps.org
  26. $obj = new \DANCECAMPS\dancecampsPayment($CampURL);
  27. $apiSendResult = $obj->sendPaymentToDanceCamps($BookingID, API_TOKEN, SECRET, $Result, $Amount, $Fee, $Currency, $TxnID, "This is a simulated payment", "Your payment has been processed");
  28. // Was the payment successful and was it succesfully sent to dancecamps.org?
  29. // If so, send the user on to the success page. If not, send them to the fail
  30. // page. In a real application, if the payment send to dancecamps.org failed,
  31. // you may want to also send yourself an alert
  32. if ($Result==="Completed" && $apiSendResult) header("Location: ".$CampURL."/payment-success.php");
  33. else
  34. {
  35. // Maybe send an email to let me know something went wrong and let me fix it manually!
  36. header("Location: ".$CampURL."/payment-fail.php?message=Simulated-Payment+Failed");
  37. }
  38. exit();
  39. }
  40. else
  41. {
  42. ?>
  43. <html>
  44. <head>
  45. <title>Test dancecamps payment via API</title>
  46. <style>
  47. label {
  48. display: inline-block;
  49. width: 130px;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <h1>Test dancecamps payment via API</h1>
  55. <form action='payment-test.php' method='post'>
  56. <input type="hidden" name="CampURL" value="<?php echo htmlentities($_POST['CampURL']); ?>">
  57. <input type="hidden" name="BookingID" value="<?php echo $_POST['BookingID']; ?>">
  58. <label for="Result">Result : </label><input name="Result" id="Result" value="Completed"><br>
  59. <label for="Currency">Currency : </label><input name="Currency" id="Currency" value="USD"><br>
  60. <label for="Amount">Amount : </label><input name="Amount" id="Amount" value="<?php echo $_POST["Amount"]; ?>"><br>
  61. <label for="FeeAmount">Fee : </label><input name="FeeAmount" id="FeeAmount" value="<?php echo $_POST["Amount"]*0.02; ?>"><br>
  62. <label for="TxnID">Transaction ID : </label><input name="TxnID" id="TxnID" value="<?php echo substr(base64_encode(hash("sha256", mt_rand(0,99999).microtime())), 0, 16); ?>"><br>
  63. <input type="submit" value="Simulate Transaction">
  64. </form>
  65. </body>
  66. </html>
  67. <?php
  68. }
  69. ?>