| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- /*
- * This is a script for testing payments.
- * Users will arrive here after having completed a booking.
- * Depending on the config, this will simulate a completed or a failed payment
- * and then return the user to their booking.
- */
- if ($_POST['Result'])
- {
- // This is the API key from the main setup page
- define('API_TOKEN', '[paste your payment api token here]');
- // This is the secret key from the payments API setup page on dancecamps.org
- define('SECRET', '[paste your secret key here]');
- // Include the PHP SDK
- include_once 'dancecampsPayment.class.php';
- $BookingID=$_POST['BookingID'];
- $Amount=$_POST['Amount'];
- $CampURL=$_POST['CampURL'];
- // This is where a real payment would be made.
- // Here will we just simulate the results
- $Result=$_POST['Result'];
- $Currency=$_POST['Currency'];
- $TxnID=$_POST['TxnID'];
- $Fee=$_POST['FeeAmount'];
- // The payment was made, send the info to dancecamps.org
- $obj = new \DANCECAMPS\dancecampsPayment($CampURL);
- $apiSendResult = $obj->sendPaymentToDanceCamps($BookingID, API_TOKEN, SECRET, $Result, $Amount, $Fee, $Currency, $TxnID, "This is a simulated payment", "Your payment has been processed");
- // Was the payment successful and was it succesfully sent to dancecamps.org?
- // If so, send the user on to the success page. If not, send them to the fail
- // page. In a real application, if the payment send to dancecamps.org failed,
- // you may want to also send yourself an alert
- if ($Result==="Completed" && $apiSendResult) header("Location: ".$CampURL."/payment-success.php");
- else
- {
- // Maybe send an email to let me know something went wrong and let me fix it manually!
- header("Location: ".$CampURL."/payment-fail.php?message=Simulated-Payment+Failed");
- }
- exit();
- }
- else
- {
- ?>
- <html>
- <head>
- <title>Test dancecamps payment via API</title>
- <style>
- label {
- display: inline-block;
- width: 130px;
- }
- </style>
- </head>
- <body>
- <h1>Test dancecamps payment via API</h1>
- <form action='payment-test.php' method='post'>
- <input type="hidden" name="CampURL" value="<?php echo htmlentities($_POST['CampURL']); ?>">
- <input type="hidden" name="BookingID" value="<?php echo $_POST['BookingID']; ?>">
- <label for="Result">Result : </label><input name="Result" id="Result" value="Completed"><br>
- <label for="Currency">Currency : </label><input name="Currency" id="Currency" value="USD"><br>
- <label for="Amount">Amount : </label><input name="Amount" id="Amount" value="<?php echo $_POST["Amount"]; ?>"><br>
- <label for="FeeAmount">Fee : </label><input name="FeeAmount" id="FeeAmount" value="<?php echo $_POST["Amount"]*0.02; ?>"><br>
- <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>
- <input type="submit" value="Simulate Transaction">
- </form>
- </body>
- </html>
- <?php
- }
- ?>
|