| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Rev: 702 $ | $LastChangedBy: brieb $ |
|---|
| 4 | $LastChangedDate: 2010-01-01 15:14:57 -0700 (Fri, 01 Jan 2010) $ |
|---|
| 5 | +-------------------------------------------------------------------------+ |
|---|
| 6 | | Copyright (c) 2004 - 2010, Kreotek LLC | |
|---|
| 7 | | All rights reserved. | |
|---|
| 8 | +-------------------------------------------------------------------------+ |
|---|
| 9 | | | |
|---|
| 10 | | Redistribution and use in source and binary forms, with or without | |
|---|
| 11 | | modification, are permitted provided that the following conditions are | |
|---|
| 12 | | met: | |
|---|
| 13 | | | |
|---|
| 14 | | - Redistributions of source code must retain the above copyright | |
|---|
| 15 | | notice, this list of conditions and the following disclaimer. | |
|---|
| 16 | | | |
|---|
| 17 | | - Redistributions in binary form must reproduce the above copyright | |
|---|
| 18 | | notice, this list of conditions and the following disclaimer in the | |
|---|
| 19 | | documentation and/or other materials provided with the distribution. | |
|---|
| 20 | | | |
|---|
| 21 | | - Neither the name of Kreotek LLC nor the names of its contributore may | |
|---|
| 22 | | be used to endorse or promote products derived from this software | |
|---|
| 23 | | without specific prior written permission. | |
|---|
| 24 | | | |
|---|
| 25 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
|---|
| 26 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
|---|
| 27 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | |
|---|
| 28 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
|---|
| 29 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
|---|
| 30 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
|---|
| 31 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
|---|
| 32 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
|---|
| 33 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
|---|
| 34 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
|---|
| 35 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
|---|
| 36 | | | |
|---|
| 37 | +-------------------------------------------------------------------------+ |
|---|
| 38 | */ |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | * payment processing template object and file layout |
|---|
| 42 | */ |
|---|
| 43 | class paymentProcessor{ |
|---|
| 44 | |
|---|
| 45 | var $db; |
|---|
| 46 | var $salesorderUUID; |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | /** |
|---|
| 50 | * function paymentProcessor |
|---|
| 51 | * |
|---|
| 52 | * initializes the class |
|---|
| 53 | * |
|---|
| 54 | * @param object $db the db object |
|---|
| 55 | * @param string $salesorderUUID the UUID of the salesorder that will be processed |
|---|
| 56 | */ |
|---|
| 57 | function paymentProcessor($db, $salesorderUUID){ |
|---|
| 58 | |
|---|
| 59 | $this->db = $db; |
|---|
| 60 | $this->db->errorFormat = "json"; |
|---|
| 61 | |
|---|
| 62 | $this->salesorderUUID = mysql_real_escape_string($salesorderUUID); |
|---|
| 63 | |
|---|
| 64 | }//end function init |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | /** |
|---|
| 68 | * function process |
|---|
| 69 | * |
|---|
| 70 | * process the actual payment. This function needs to do a couple of things |
|---|
| 71 | * It needs to retrieve any pertinent information from the sales order/client |
|---|
| 72 | * record that it needs to pass on to the payment gateway. It then needs |
|---|
| 73 | * to interact with the gateway. Next, if successfull it will probably need |
|---|
| 74 | * to update the sales order record with the appropriate transaction id that |
|---|
| 75 | * the gateway returned. Lastly, it needs to return the response in JSON format. |
|---|
| 76 | * |
|---|
| 77 | * Remember, if you hit any errors, it is best to return errors in JSON format |
|---|
| 78 | * |
|---|
| 79 | * @return string json struct with the response from the gateway |
|---|
| 80 | * |
|---|
| 81 | * @returnf 'result' should be either success, declined, or error |
|---|
| 82 | * @returnf 'transactionid' transactionid if success |
|---|
| 83 | * @returnf 'details' any error or decline details if not success |
|---|
| 84 | */ |
|---|
| 85 | function process(){ |
|---|
| 86 | |
|---|
| 87 | $thereturn = array(); |
|---|
| 88 | |
|---|
| 89 | /** |
|---|
| 90 | * Retrieve pertinent sales order / client information |
|---|
| 91 | * Also need to check if appropriate information is there to pass |
|---|
| 92 | * to getway |
|---|
| 93 | */ |
|---|
| 94 | |
|---|
| 95 | /** |
|---|
| 96 | * Make connection to gateway and send information |
|---|
| 97 | */ |
|---|
| 98 | |
|---|
| 99 | /** |
|---|
| 100 | * parse results from gateway and format the return. |
|---|
| 101 | */ |
|---|
| 102 | |
|---|
| 103 | $thereturn["result"] = "success"; |
|---|
| 104 | $thereturn["transactionid"] = "TR000001"; |
|---|
| 105 | |
|---|
| 106 | return json_encode($thereturn); |
|---|
| 107 | |
|---|
| 108 | }//end function process |
|---|
| 109 | |
|---|
| 110 | }//end class |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | /** |
|---|
| 114 | * PROCESSING ============================================================== |
|---|
| 115 | */ |
|---|
| 116 | if(!isset($noOutput)){ |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | require_once("../../include/session.php"); |
|---|
| 120 | |
|---|
| 121 | /** |
|---|
| 122 | * the processor will sent the sales order id via get |
|---|
| 123 | */ |
|---|
| 124 | if(!isset($_GET["soid"])) |
|---|
| 125 | $error = new appError(200, "Passed parameter expexted", "", true, true, false, "json"); |
|---|
| 126 | |
|---|
| 127 | $processor = new paymentProcessor($db, $_GET["soid"]); |
|---|
| 128 | |
|---|
| 129 | echo $processor->process(); |
|---|
| 130 | |
|---|
| 131 | }//endif |
|---|
| 132 | ?> |
|---|