2 /** @package verysimple::Payment */
5 * import supporting libraries
7 require_once("PaymentProcessor.php");
10 * TestGateway is a PaymentProcessor implementation that does not
11 * actually process transactions, but is used specifically for
12 * application testing purposes.
13 * To succeed, pass in a credit card
14 * number of 4111111111111111 with a valid expiration date.
15 * Any other credit card number will cause a fail to occur.
17 * @package verysimple::Payment
18 * @author VerySimple Inc.
19 * @copyright 1997-2012 VerySimple, Inc.
20 * @license http://www.gnu.org/licenses/lgpl.html LGPL
23 class TestGateway
extends PaymentProcessor
27 * Called on contruction
29 function Init($testmode)
35 * @see PaymentProcessor::Refund()
37 function Refund(RefundRequest
$req)
39 $resp = new PaymentResponse();
40 $resp->OrderNumber
= $req->InvoiceId
;
42 // before bothering with contacting the processor, check for some basic fields
43 if ($req->TransactionId
== '') {
44 $resp->IsSuccess
= false;
45 $resp->ResponseCode
= "0";
46 $resp->ResponseMessage
= "TestGateway: No Transaction ID provided";
47 $resp->RawResponse
= "Submit any value in the TransactionId field for a successful response";
49 $resp->IsSuccess
= true;
50 $resp->TransactionId
= rand(1000000, 9999999);
51 $resp->ResponseCode
= "OK";
52 $resp->ResponseMessage
= "TestGateway: Full amount sucessfully refunded";
59 * Process a PaymentRequest
61 * @param PaymentRequest $req
62 * Request object to be processed
63 * @return PaymentResponse
65 function Process(PaymentRequest
$req)
68 // simulate a typical CC purchase lag
71 $resp = new PaymentResponse();
72 $resp->OrderNumber
= $req->OrderNumber
;
74 $expdate = strtotime("1/" . $req->CCExpMonth
. "/" . $this->GetFullYear($req->CCExpYear
) . " + 1 month");
76 // before bothering with contacting the processor, check for some basic fields
77 if ($req->CCNumber
== '') {
78 $resp->IsSuccess
= false;
79 $resp->ResponseCode
= "0";
80 $resp->ResponseMessage
= "TestGateway: No Credit Card Number Provided";
81 $resp->RawResponse
= "Submit card # 4111111111111111 for a successful transaction response";
82 } elseif ($req->CCNumber
!= '4111111111111111') {
83 $resp->IsSuccess
= false;
84 $resp->ResponseCode
= "1";
85 $resp->ResponseMessage
= "TestGateway: The credit card number '" . $req->CCNumber
. "' is invalid";
86 $resp->RawResponse
= "Submit card # 4111111111111111 for a successful transaction response";
87 } elseif ($expdate < time()) {
88 $resp->IsSuccess
= false;
89 $resp->ResponseCode
= "2";
90 $resp->ResponseMessage
= "TestGateway: The credit card is expired";
91 $resp->RawResponse
= "Set the expire date greater than today for a successful transaction response";
93 $resp->IsSuccess
= true;
94 $resp->TransactionId
= rand(1000000, 9999999);
95 $resp->ResponseCode
= "OK";
96 $resp->ResponseMessage
= "TestGateway: Charge of " . number_format($req->TransactionAmount
, 2) . " Posted";