From 31ab0b58cbc0ec57aa42036b6efb4e3f134ceb4d Mon Sep 17 00:00:00 2001 From: Chuck Scott Date: Tue, 10 Apr 2018 11:45:27 -0400 Subject: [PATCH] Converted files with CR/LF to LF only. --- .../Authorize.Net/paymentGateway.php | 484 +++---- .../MerchantSolutions/paymentGateway.php | 698 +++++----- .../PayPal/paymentGateway.php | 1182 ++++++++--------- lib/paymentProcessors/PayPal/test.php | 220 +-- .../TestByCardNumber/paymentGateway.php | 378 +++--- .../TestGood/paymentGateway.php | 190 +-- 6 files changed, 1576 insertions(+), 1576 deletions(-) diff --git a/lib/paymentProcessors/Authorize.Net/paymentGateway.php b/lib/paymentProcessors/Authorize.Net/paymentGateway.php index c7034e08..e998e8d3 100644 --- a/lib/paymentProcessors/Authorize.Net/paymentGateway.php +++ b/lib/paymentProcessors/Authorize.Net/paymentGateway.php @@ -16,19 +16,19 @@ use net\authorize\api\controller as AnetController; // use net\authorize\api\contract\v1\CustomerProfileIdType; // Uncomment the following line to activate log - DO NOT KEEP THIS ENABLED FOR NORMAL PRODUCTION! -// define("AUTHORIZENET_LOG_FILE", "phplog"); - -/** - * Authorize.net PaymentGateway class - * - * PHP version 5 - * - * @category Event Management Admin Tickets - * @package EventManagement - * @author Chuck Scott - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: AuthorizeNet.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ - * @link <> +// define("AUTHORIZENET_LOG_FILE", "phplog"); + +/** + * Authorize.net PaymentGateway class + * + * PHP version 5 + * + * @category Event Management Admin Tickets + * @package EventManagement + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: AuthorizeNet.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + * @link <> */ /* @@ -37,24 +37,24 @@ use net\authorize\api\controller as AnetController; * See following URL for API documentation (hover over "API" at top of page). * https://developer.authorize.net/api/ * - */ - -class PaymentGateway -{ - /** - * account - * - * @var array - * @access public - */ - var $account; - /** - * Merchant API Credentials - * - * @var object - * @acess private - */ - private $merchantAuthentication; + */ + +class PaymentGateway +{ + /** + * account + * + * @var array + * @access public + */ + var $account; + /** + * Merchant API Credentials + * + * @var object + * @acess private + */ + private $merchantAuthentication; /** * Test Mode * @@ -63,32 +63,32 @@ class PaymentGateway */ private $testMode; - /** - * Constructor - * - * @param array $account Account information - * - * @access public - * - * Information provided - * - * $account - * login Authorize.net login - * key Authorize.net login key - * test Test mode - * 0 = Production Mode (PRODUCTION) - * 1 = Local Transaction Approval Test - * 2 = Local Transaction Decline Test - * 3 = On-Line Transaction Test (SANDBOX) - * conf True if Authorize.net should send confirmation E-Mail to customer - Not used by Authroize.net API - * email Merchant E-Mail address to receive notices - Not used by Authorize.net API - * - * API Access for Authorize.net SANDBOX - * API Login ID: 44pvQ8D7d - * Transaction Key: 8rj6ME772K9Pe9pJ - * Secret Question: Simon - * - */ + /** + * Constructor + * + * @param array $account Account information + * + * @access public + * + * Information provided + * + * $account + * login Authorize.net login + * key Authorize.net login key + * test Test mode + * 0 = Production Mode (PRODUCTION) + * 1 = Local Transaction Approval Test + * 2 = Local Transaction Decline Test + * 3 = On-Line Transaction Test (SANDBOX) + * conf True if Authorize.net should send confirmation E-Mail to customer - Not used by Authroize.net API + * email Merchant E-Mail address to receive notices - Not used by Authorize.net API + * + * API Access for Authorize.net SANDBOX + * API Login ID: 44pvQ8D7d + * Transaction Key: 8rj6ME772K9Pe9pJ + * Secret Question: Simon + * + */ public function __construct($account) { @@ -105,138 +105,138 @@ class PaymentGateway $this->merchantAuthentication->setName($account['login']); $this->merchantAuthentication->setTransactionKey($account['key']); - } - - /** - * Process a Payment - * - * @param payment Array payment information - * @param contact Array contact information - * - * @access public - * @return array - * - * Information provided - * + } + + /** + * Process a Payment + * + * @param payment Array payment information + * @param contact Array contact information + * + * @access public + * @return array + * + * Information provided + * * $payment array - * transOpt Transaction option: 0 = Charge Card, 1 = Charge Card and stroe as Profile, 2 = Charge using Stored Profile + * transOpt Transaction option: 0 = Charge Card, 1 = Charge Card and stroe as Profile, 2 = Charge using Stored Profile * name Name of Venue * customerProfileId Customer Profile ID from stored profile - if using transOpt = 2 - * paymentProfileId Payment Profile ID from stored profile - if using transOpt = 2 - * charge Total to be charged - * cctype Card type (not used for Authorize.net) Not Required - * ccname Name on card (not used for Authorize.net) - * ccnumb Card number - * ccexp Expiration date (m/y) - * cccode Security code on back of card - * invoice Invoice # is session ID (or some part thereof) - * Max 20 chars, letters and digits only - * Only last 20 chars used if longer - * + * paymentProfileId Payment Profile ID from stored profile - if using transOpt = 2 + * charge Total to be charged + * cctype Card type (not used for Authorize.net) Not Required + * ccname Name on card (not used for Authorize.net) + * ccnumb Card number + * ccexp Expiration date (m/y) + * cccode Security code on back of card + * invoice Invoice # is session ID (or some part thereof) + * Max 20 chars, letters and digits only + * Only last 20 chars used if longer + * * $customer array * id Customer ID - Must be unique for all customers - * fname Customer first name - * lname Customer last name - * addr1 Address Line 1 - * addr2 Address Line 2 - * city City - * state State - * country Country - * zip ZIP/Postal code - * phone Customer phone number - * email Customer E-Mail address - * + * fname Customer first name + * lname Customer last name + * addr1 Address Line 1 + * addr2 Address Line 2 + * city City + * state State + * country Country + * zip ZIP/Postal code + * phone Customer phone number + * email Customer E-Mail address + * * return array - * gateway Name of this gateway - * status Numeric return status code - * 1 Approved - * 2 Bad data supplied - * 3 Communications failure - * 4 Bad response - * 5 Transaction not valid - * 6 Merchant account problem - * 7 Card declined - * statusText Short name of status + * gateway Name of this gateway + * status Numeric return status code + * 1 Approved + * 2 Bad data supplied + * 3 Communications failure + * 4 Bad response + * 5 Transaction not valid + * 6 Merchant account problem + * 7 Card declined + * statusText Short name of status * authCode Authorization code - blank if card not accepted * transId Authorize.Net Transaction ID for reference to this transaction - * refId Our reference ID for this request - this is also sent to Authorize.net for them to store with the transaction + * refId Our reference ID for this request - this is also sent to Authorize.net for them to store with the transaction * description Text description of result * customerProfileId Customer Profile ID - Required to use stored payment profile for future charges * paymentProfileId Payment Profile ID - Required to use stored payment profile for future charges * profileStatus Status of stored profile request - True if stored profile information is returned * profileStatusText Text descibing status of request to store payment profile - * - * Authorize.net test card numbers - * American Express 370000000000002 - * Discover 6011000000000012 - * Visa 4007000000027 - * 4012888818888 - * JCB 3088000000000017 - * Diners Club 38000000000006 - * Carte Blanche 38000000000006 - */ - public function processPayment($payment = false, $customer = false) - { + * + * Authorize.net test card numbers + * American Express 370000000000002 + * Discover 6011000000000012 + * Visa 4007000000027 + * 4012888818888 + * JCB 3088000000000017 + * Diners Club 38000000000006 + * Carte Blanche 38000000000006 + */ + public function processPayment($payment = false, $customer = false) + { $errorMsg = array(); // Set the transaction's refId using timestamp $refId = 'ref' . time(); - - // Check for required data ***** NEED TO ADD TO THIS TO TEST ALL NEEDED FIELDS ***** - if (!is_array($payment) || !is_array($payment)) { - $resp = array( - 'gateway' => 'Authorize.Net', - 'status' => 2, - 'statusText' => 'Bad Data Supplied', + + // Check for required data ***** NEED TO ADD TO THIS TO TEST ALL NEEDED FIELDS ***** + if (!is_array($payment) || !is_array($payment)) { + $resp = array( + 'gateway' => 'Authorize.Net', + 'status' => 2, + 'statusText' => 'Bad Data Supplied', 'authCode' => '', 'transId' => '', - 'refId' => $refId, - 'description' => 'The required payment and contact information was not supplied.' - ); - return $resp; - } - - // Check for specified test mode - switch ($this->account['test']) { - + 'refId' => $refId, + 'description' => 'The required payment and contact information was not supplied.' + ); + return $resp; + } + + // Check for specified test mode + switch ($this->account['test']) { + // Production Mode case 0: break; - // Local Test - case 1: - // Always return a card approval - $resp = array( - 'gateway' => 'Authorize.Net', - 'status' => 1, - 'statusText' => 'Card Approved', - 'authCode' => '12345678', + // Local Test + case 1: + // Always return a card approval + $resp = array( + 'gateway' => 'Authorize.Net', + 'status' => 1, + 'statusText' => 'Card Approved', + 'authCode' => '12345678', 'transId' => '0', 'refId' => $refId, - 'description' => '(TESTMODE) Local Test - Card Approved' - ); - return $resp; - break; - - // Fail Test - case 2: - $resp = array( - 'gateway' => 'Authorize.Net', - 'status' => 7, - 'statusText' => 'Card Declined', - 'authCode' => '', + 'description' => '(TESTMODE) Local Test - Card Approved' + ); + return $resp; + break; + + // Fail Test + case 2: + $resp = array( + 'gateway' => 'Authorize.Net', + 'status' => 7, + 'statusText' => 'Card Declined', + 'authCode' => '', 'transId' => '', 'refId' => $refId, - 'description' => '(TESTMODE) Local Test - Card Declined' - ); - return $resp; - break; - - // Online Test - case 3: - // Force Use of Authorize.net SANDBOX - $this->account['environment'] = 'SANDBOX'; + 'description' => '(TESTMODE) Local Test - Card Declined' + ); + return $resp; + break; + + // Online Test + case 3: + // Force Use of Authorize.net SANDBOX + $this->account['environment'] = 'SANDBOX'; break; // Invalid test setting @@ -252,8 +252,8 @@ class PaymentGateway ); return $resp; break; - - } + + } // Test for certain required data or data content issues if (isset($customer['id']) && trim($customer['id']) != '') { @@ -337,19 +337,19 @@ class PaymentGateway ); return $resp; } - - // Create order information + + // Create order information $order = new AnetAPI\OrderType(); if (isset($payment['invoice']) && trim($payment['invoice']) != '') { $order->setInvoiceNumber(substr($payment['invoice'], -20)); - } - $order->setDescription($payment['name']); + } + $order->setDescription($payment['name']); - // Set the customer's identifying information + // Set the customer's identifying information $customerIdent = new AnetAPI\CustomerDataType(); if (isset($customer['email']) && trim($customer['email']) != '') { $customerIdent->setEmail($customer['email']); - } + } // $customerIdentData->setType("individual"); // "individual" or "business" - Not required if (isset($customer['id']) && trim($customer['id']) != '') { $customerIdent->setId($customer['id']); @@ -408,7 +408,7 @@ class PaymentGateway } - // Payment reference ID (up to 20 characters) for this request - Possibly supplied + // Payment reference ID (up to 20 characters) for this request - Possibly supplied $request = new AnetAPI\CreateTransactionRequest(); $request->setMerchantAuthentication($this->merchantAuthentication); $request->setRefId($refId); @@ -434,9 +434,9 @@ class PaymentGateway die('Authorise.Net Payment Gateway: Serious error - processing environment not specified in calling code!'); break; - } + } - // echo "TRANSACTION RESPONSE
".print_r($response,1)."
"; + // echo "TRANSACTION RESPONSE
".print_r($response,1)."
"; // Assume the worst $respCode = 0; @@ -488,86 +488,86 @@ class PaymentGateway } } - - /* - * Possible returned Authorize.net status codes - * 1 = approved - * 2 = declined - * 3 = error - * 4 = held for review + + /* + * Possible returned Authorize.net status codes + * 1 = approved + * 2 = declined + * 3 = error + * 4 = held for review */ - - // Determine response method + + // Determine response method switch ($respCode) { - // Approved - case 1: - $resp = array( - 'gateway' => 'Authorize.Net', - 'status' => 1, - 'statusText' => 'Card Approved', + // Approved + case 1: + $resp = array( + 'gateway' => 'Authorize.Net', + 'status' => 1, + 'statusText' => 'Card Approved', 'authCode' => $transResponse->getAuthCode(), - 'transId' => $transResponse->getTransId(), + 'transId' => $transResponse->getTransId(), 'refId' => $refId, - 'description' => $respDescr - ); - break; + 'description' => $respDescr + ); + break; // Declined - - case 2: - $resp = array( - 'gateway' => 'Authorize.Net', - 'status' => 7, - 'statusText' => 'Card Declined', + + case 2: + $resp = array( + 'gateway' => 'Authorize.Net', + 'status' => 7, + 'statusText' => 'Card Declined', 'authCode' => '', - 'transId' => '', + 'transId' => '', 'refId' => $refId, - 'description' => $respDescr - ); - break; - - // Error - case 3: - $resp = array( - 'gateway' => 'Authorize.Net', - 'status' => 3, - 'statusText' => 'Transaction Error', - 'authCode' => '', + 'description' => $respDescr + ); + break; + + // Error + case 3: + $resp = array( + 'gateway' => 'Authorize.Net', + 'status' => 3, + 'statusText' => 'Transaction Error', + 'authCode' => '', 'transId' => '', 'refId' => $refId, - 'description' => $respDescr - ); - break; - - // Held for Review - case 4: - $resp = array( - 'gateway' => 'Authorize.Net', - 'status' => 7, - 'statusText' => 'Held for review', - 'authCode' => '', + 'description' => $respDescr + ); + break; + + // Held for Review + case 4: + $resp = array( + 'gateway' => 'Authorize.Net', + 'status' => 7, + 'statusText' => 'Held for review', + 'authCode' => '', 'transId' => '', 'refId' => $refId, - 'description' => $response->response_reason_text - ); - break; - - // Any other response code - default: - $resp = array( - 'gateway' => 'Authorize.Net', - 'status' => 4, - 'statusText' => 'Bad Response', - 'authCode' => '', + 'description' => $response->response_reason_text + ); + break; + + // Any other response code + default: + $resp = array( + 'gateway' => 'Authorize.Net', + 'status' => 4, + 'statusText' => 'Bad Response', + 'authCode' => '', 'transId' => '', 'refId' => $refId, - 'description' => $respDescr - ); - break; - + 'description' => $respDescr + ); + break; + } - + // echo "Response before profile
".print_r($resp,1)."
"; // Check if request to create a customer profile using this transaction @@ -597,9 +597,9 @@ class PaymentGateway } } - - return $resp; - + + return $resp; + } /** @@ -732,6 +732,6 @@ class PaymentGateway return $resp; - } - -} + } + +} diff --git a/lib/paymentProcessors/MerchantSolutions/paymentGateway.php b/lib/paymentProcessors/MerchantSolutions/paymentGateway.php index 6968fe8a..4621c972 100644 --- a/lib/paymentProcessors/MerchantSolutions/paymentGateway.php +++ b/lib/paymentProcessors/MerchantSolutions/paymentGateway.php @@ -1,349 +1,349 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: classes/paymentProcessors/MerchantSolutions.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ - * @link <> - */ - -/** - * MerchantSolutions PaymentGateway class - * - * PHP version 5 - * - * @category Event Management Admin Tickets - * @package EventManagement - * @author Chuck Scott - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: classes/paymentProcessors/MerchantSolutions.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ - * @link <> - */ - -define( "MS_WSDL", "https://trans.merchantsolution.com/Web/services/TransactionService?wsdl" ); - -/** - * Merchant Solutions Payment Gateway class - * - * PHP version 5 - */ - -class PaymentGateway -{ - /** - * Transaction Result - * - * @var $result - * @access public - */ - public $result = false; - /** - * Raw response data - * - * @var $response - * @access public - */ - public $response = false; - /** - * XML Soap Client Object - * - * @var $client - * @access public - */ - public $client; - /** - * Request Object - * - * @var $request - * @access public - */ - public $request; - - /** - * Constructor - * - * @param array $account Account information - * - * @return boolean Returns value of $success parameter - * @access public - * - * $account - * acctid MerchantSolutions account ID - Use "TEST0" for texting - * merchantpin MerchantSolutions account PIN - Login to Merchant center, then "FRISK(TM) Management" and "Configure Options" - * test Test mode - * 0 = Production Mode - * 1 = Local Transaction Approval Test - * 2 = Local Transaction Decline Test - * 3 = On-Line Transaction Test - * conf (not used for Merchant Solutions) - * email Merchant E-Mail address to receive notices from Merchant Solutions for the transaction - * - * Test Merchant Account - * AcctID: MSDMO - * Userid: Cscott - * Password: Glm3Merch#Sol - * MerchantPin: BVR0V3462V5GmZK03MXtWE5u9HeUJX62 - * - */ - public function __construct($account) - { - - // Setup request object - $this->request = (object) array( - 'acctid' => false, - 'merchantpin' => false, - 'amount' => false, - 'ccnum' => false, - 'expmon' => false, - 'expyear' => false, - 'ccname' => false, - 'cardpresent' => 0, - 'cardreaderpresent' => 0, - 'cvv2' => false, - 'accttype' => 1, - 'profileactiontype' => 2, - 'manualrecurring' => 0, - 'avs_override' => 0, - 'cvv2_override' => 0, - 'loadbalance_override' => 0, - 'duplicate_override' => 0, - 'accountlookupflag' => 0, - 'billaddress' => (object) array( - 'addr1' => '', - 'addr2' => '', - 'city' => '', - 'state' => '', - 'zip' => '', - 'country' => '' - ) - ); - - $this->account = $account; - $this->request->acctid = $account['acctid']; - $this->request->merchantpin = $account['merchantpin']; - - // Test to see if soap support has been installed - if (!extension_loaded('soap')) { - trigger_error('*** PHP SOAP not installed and required by MerchantSolutions payment gateway! ***', E_USER_ERROR); - } - - // Setup options related to doing the SOAP calls - ini_set('soap.wsdl_cache_enabled', 1); - use_soap_error_handler(false); - $soapOptions = array( - "exceptions" => 1, - 'connection_timeout' => 10 - ); - - // Setup SOAP client and get WSDL for gateway - try { - - // XDebug prevents catching fatal errors with the Soap calls - if (function_exists('xdebug_disable')) { - xdebug_disable(); - } - - // Create new soap client instance - $this->client = @new SoapClient(MS_WSDL, $soapOptions); - - // If XDebug was dissabled, re-enable it - if (function_exists('xdebug_enable')) { - xdebug_enable(); - } - - // Indicate setup OK - return true; - - } catch (SoapFault $exception) { - - return false; - } - - return false; - } - - /** - * Process a Payment - * - * @param payment Array payment information - * @param contact Array contact information - * - * @access public - * @return array - * - * Information provided - * - * $payment array - * name Name of Venue - * charge Total to be charged - * cctype Card type - * ccname Name on card - * ccnumb Card number - * ccexp Expiration date (m/y) - * cccode Security code on back of card - * invoice Invoice # is session ID (or some part thereof) - * - * $contact array - * fname Customer first name - * lname Customer last name - * addr1 Address Line 1 - * addr2 Address Line 2 - * city City - * state State - * country Country - * zip ZIP/Postal code - * phone Customer phone number - * email Customer E-Mail address - * - * return array - * status Numeric return status code - * 1 Approved - * 2 Bad data supplied - * 3 Communications failure - * 4 Bad response - * 5 Transaction not valid - * 6 Merchant account problem - * 7 Card declined - * statusText Short name of status - * authCode Authorization code - blank if card not accepted - * description Longer description of result - * - * - */ - public function processPayment($payment = false, $contact = false) - { - - // Set data - $this->request->amount = $payment['charge']; - $this->request->ccnum = $payment['ccnumb']; - $exp = explode('/', $payment['ccexp']); - $this->request->expmon = $exp[0]; - $this->request->expyear = $exp[1]; - $this->request->ccname = $payment['ccname']; - $this->request->cvv2 = $payment['cccode']; - $this->request->memo = $payment['name'].' - Event Tickets'; - $this->request->billaddress->addr1 = $contact['addr1']; - $this->request->billaddress->addr2 = $contact['addr2']; - $this->request->billaddress->city = $contact['city']; - $this->request->billaddress->state = $contact['state']; - $this->request->billaddress->zip = $contact['zip']; - $this->request->billaddress->addr1 = $contact['country']; - $this->request->phone = $contact['phone']; - $this->request->email = $contact['email']; - $this->request->merchantordernumber = substr($payment['invoice'], -20); - - // Check for local tests that don't require communication with Authorize.net - switch ($this->account['test']) { - - // Local Test - case 1: - // Always return a card approval - $resp = array( - 'gateway' => 'MerchantSolutions', - 'status' => 1, - 'statusText' => 'Card Approved', - 'authCode' => '000000', - 'description' => '(TESTMODE) Local Test - Card Approved' - ); - return $resp; - break; - - // Fail Test - case 2: - $resp = array( - 'gateway' => 'MerchantSolutions', - 'status' => 7, - 'statusText' => 'Card Declined', - 'authCode' => '', - 'description' => '(TESTMODE) Local Test - Card Declined' - ); - return $resp; - break; - - // Online Test - case 3: - $this->request->acctid = 'TEST0'; - break; - - // Production Mode - case 0: - break; - } - - - - // Try to process the transaction - try { - - // Deal with XDebug if that's enabled - if (function_exists('xdebug_disable')) { - xdebug_disable(); - } - - // Send request to Merchant Solutions - $this->response = $this->client->processCCSale($this->request); - - // Restore XDebug if that was enabled - if (function_exists('xdebug_enable')) { - xdebug_enable(); - } - - // If approved - if (strtoupper($this->result) == 'APPROVED') { - - $resp = array( - 'gateway' => 'MerchantSolutions', - 'status' => 1, - 'statusText' => 'Card Approved', - 'authCode' => $this->response->authcode, - 'description' => $this->response->status - ); - return $resp; - - // Must be declined - } else { - - $x = explode(":", $this->response->result); - $resp = array( - 'gateway' => 'MerchantSolutions', - 'status' => 7, - 'statusText' => 'Card Declined', - 'authCode' => '', - 'description' => $x[2] - ); - return $resp; - - - } - - // If there's a communications failure - } catch (SoapFault $exception) { - - // Return communications failure - $resp = array( - 'gateway' => 'MerchantSolutions', - 'status' => 3, - 'statusText' => 'Transaction Error', - 'authCode' => '', - 'description' => 'Unable to communicate with credit card processing service.' - ); - return $resp; - - } - - $resp = array( - 'gateway' => 'MerchantSolutions', - 'status' => 4, - 'statusText' => 'Bad Response', - 'authCode' => '', - 'description' => 'Received unknown response from the credit card processing service.' - ); - return $resp; - - } - -} + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: classes/paymentProcessors/MerchantSolutions.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + * @link <> + */ + +/** + * MerchantSolutions PaymentGateway class + * + * PHP version 5 + * + * @category Event Management Admin Tickets + * @package EventManagement + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: classes/paymentProcessors/MerchantSolutions.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + * @link <> + */ + +define( "MS_WSDL", "https://trans.merchantsolution.com/Web/services/TransactionService?wsdl" ); + +/** + * Merchant Solutions Payment Gateway class + * + * PHP version 5 + */ + +class PaymentGateway +{ + /** + * Transaction Result + * + * @var $result + * @access public + */ + public $result = false; + /** + * Raw response data + * + * @var $response + * @access public + */ + public $response = false; + /** + * XML Soap Client Object + * + * @var $client + * @access public + */ + public $client; + /** + * Request Object + * + * @var $request + * @access public + */ + public $request; + + /** + * Constructor + * + * @param array $account Account information + * + * @return boolean Returns value of $success parameter + * @access public + * + * $account + * acctid MerchantSolutions account ID - Use "TEST0" for texting + * merchantpin MerchantSolutions account PIN - Login to Merchant center, then "FRISK(TM) Management" and "Configure Options" + * test Test mode + * 0 = Production Mode + * 1 = Local Transaction Approval Test + * 2 = Local Transaction Decline Test + * 3 = On-Line Transaction Test + * conf (not used for Merchant Solutions) + * email Merchant E-Mail address to receive notices from Merchant Solutions for the transaction + * + * Test Merchant Account + * AcctID: MSDMO + * Userid: Cscott + * Password: Glm3Merch#Sol + * MerchantPin: BVR0V3462V5GmZK03MXtWE5u9HeUJX62 + * + */ + public function __construct($account) + { + + // Setup request object + $this->request = (object) array( + 'acctid' => false, + 'merchantpin' => false, + 'amount' => false, + 'ccnum' => false, + 'expmon' => false, + 'expyear' => false, + 'ccname' => false, + 'cardpresent' => 0, + 'cardreaderpresent' => 0, + 'cvv2' => false, + 'accttype' => 1, + 'profileactiontype' => 2, + 'manualrecurring' => 0, + 'avs_override' => 0, + 'cvv2_override' => 0, + 'loadbalance_override' => 0, + 'duplicate_override' => 0, + 'accountlookupflag' => 0, + 'billaddress' => (object) array( + 'addr1' => '', + 'addr2' => '', + 'city' => '', + 'state' => '', + 'zip' => '', + 'country' => '' + ) + ); + + $this->account = $account; + $this->request->acctid = $account['acctid']; + $this->request->merchantpin = $account['merchantpin']; + + // Test to see if soap support has been installed + if (!extension_loaded('soap')) { + trigger_error('*** PHP SOAP not installed and required by MerchantSolutions payment gateway! ***', E_USER_ERROR); + } + + // Setup options related to doing the SOAP calls + ini_set('soap.wsdl_cache_enabled', 1); + use_soap_error_handler(false); + $soapOptions = array( + "exceptions" => 1, + 'connection_timeout' => 10 + ); + + // Setup SOAP client and get WSDL for gateway + try { + + // XDebug prevents catching fatal errors with the Soap calls + if (function_exists('xdebug_disable')) { + xdebug_disable(); + } + + // Create new soap client instance + $this->client = @new SoapClient(MS_WSDL, $soapOptions); + + // If XDebug was dissabled, re-enable it + if (function_exists('xdebug_enable')) { + xdebug_enable(); + } + + // Indicate setup OK + return true; + + } catch (SoapFault $exception) { + + return false; + } + + return false; + } + + /** + * Process a Payment + * + * @param payment Array payment information + * @param contact Array contact information + * + * @access public + * @return array + * + * Information provided + * + * $payment array + * name Name of Venue + * charge Total to be charged + * cctype Card type + * ccname Name on card + * ccnumb Card number + * ccexp Expiration date (m/y) + * cccode Security code on back of card + * invoice Invoice # is session ID (or some part thereof) + * + * $contact array + * fname Customer first name + * lname Customer last name + * addr1 Address Line 1 + * addr2 Address Line 2 + * city City + * state State + * country Country + * zip ZIP/Postal code + * phone Customer phone number + * email Customer E-Mail address + * + * return array + * status Numeric return status code + * 1 Approved + * 2 Bad data supplied + * 3 Communications failure + * 4 Bad response + * 5 Transaction not valid + * 6 Merchant account problem + * 7 Card declined + * statusText Short name of status + * authCode Authorization code - blank if card not accepted + * description Longer description of result + * + * + */ + public function processPayment($payment = false, $contact = false) + { + + // Set data + $this->request->amount = $payment['charge']; + $this->request->ccnum = $payment['ccnumb']; + $exp = explode('/', $payment['ccexp']); + $this->request->expmon = $exp[0]; + $this->request->expyear = $exp[1]; + $this->request->ccname = $payment['ccname']; + $this->request->cvv2 = $payment['cccode']; + $this->request->memo = $payment['name'].' - Event Tickets'; + $this->request->billaddress->addr1 = $contact['addr1']; + $this->request->billaddress->addr2 = $contact['addr2']; + $this->request->billaddress->city = $contact['city']; + $this->request->billaddress->state = $contact['state']; + $this->request->billaddress->zip = $contact['zip']; + $this->request->billaddress->addr1 = $contact['country']; + $this->request->phone = $contact['phone']; + $this->request->email = $contact['email']; + $this->request->merchantordernumber = substr($payment['invoice'], -20); + + // Check for local tests that don't require communication with Authorize.net + switch ($this->account['test']) { + + // Local Test + case 1: + // Always return a card approval + $resp = array( + 'gateway' => 'MerchantSolutions', + 'status' => 1, + 'statusText' => 'Card Approved', + 'authCode' => '000000', + 'description' => '(TESTMODE) Local Test - Card Approved' + ); + return $resp; + break; + + // Fail Test + case 2: + $resp = array( + 'gateway' => 'MerchantSolutions', + 'status' => 7, + 'statusText' => 'Card Declined', + 'authCode' => '', + 'description' => '(TESTMODE) Local Test - Card Declined' + ); + return $resp; + break; + + // Online Test + case 3: + $this->request->acctid = 'TEST0'; + break; + + // Production Mode + case 0: + break; + } + + + + // Try to process the transaction + try { + + // Deal with XDebug if that's enabled + if (function_exists('xdebug_disable')) { + xdebug_disable(); + } + + // Send request to Merchant Solutions + $this->response = $this->client->processCCSale($this->request); + + // Restore XDebug if that was enabled + if (function_exists('xdebug_enable')) { + xdebug_enable(); + } + + // If approved + if (strtoupper($this->result) == 'APPROVED') { + + $resp = array( + 'gateway' => 'MerchantSolutions', + 'status' => 1, + 'statusText' => 'Card Approved', + 'authCode' => $this->response->authcode, + 'description' => $this->response->status + ); + return $resp; + + // Must be declined + } else { + + $x = explode(":", $this->response->result); + $resp = array( + 'gateway' => 'MerchantSolutions', + 'status' => 7, + 'statusText' => 'Card Declined', + 'authCode' => '', + 'description' => $x[2] + ); + return $resp; + + + } + + // If there's a communications failure + } catch (SoapFault $exception) { + + // Return communications failure + $resp = array( + 'gateway' => 'MerchantSolutions', + 'status' => 3, + 'statusText' => 'Transaction Error', + 'authCode' => '', + 'description' => 'Unable to communicate with credit card processing service.' + ); + return $resp; + + } + + $resp = array( + 'gateway' => 'MerchantSolutions', + 'status' => 4, + 'statusText' => 'Bad Response', + 'authCode' => '', + 'description' => 'Received unknown response from the credit card processing service.' + ); + return $resp; + + } + +} diff --git a/lib/paymentProcessors/PayPal/paymentGateway.php b/lib/paymentProcessors/PayPal/paymentGateway.php index 1161fca2..73a04ad2 100755 --- a/lib/paymentProcessors/PayPal/paymentGateway.php +++ b/lib/paymentProcessors/PayPal/paymentGateway.php @@ -1,591 +1,591 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: PayPal.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ - * @link <> - */ - - -/** - * Account Information - * - * Developer account - * PayPal API: https://developer.paypal.com/webapps/developer/ - * E-Mail Address: PayPal@n8dnx.org - * Password: pAy#glM2Pal - * - * PayPal test account - * E-Mail address: paypalAcct2@n8dnx.org - * Password: {std insecure}2 - * - * Test credentials - * Test account: PayPal-facilitator@n8dnx.org - * Endpoint: api.sandbox.paypal.com - * Client ID: AY2IlhCAFCgTaYSgrGfBQ0h5WKKgpLwU-jd2QkKsEbDpGEWtCDZKtp2VLhu1 - * Secret: EOWLsBDrkvdOKUlfhAKJ47aXHBr5xzw-2o7JdLCcLVciGqNGXlhMayP1WKhe - * - * Gaslight Media Live credentials - * Endpoint: api.paypal.com - * Client ID: AZw7VxC8rVTxlKoZVBd60ugOy_9PZWLDazQHF0RlYYWBQbAvkX2MBLy2vfmQ - * Secret: EN3ZaxB4AhZ3J1814MtpfFjUXOqRTR8dto-fhFgk2wuLDTCoPfD0I0Dpbwuu - * - * Standard PayPal buttons and images - * https://ppmts.custhelp.com/app/answers/detail/a_id/632 - * https://www.paypal.com/en_US/i/btn/x-click-but6.gif - */ - -/** - * EventManagementPayPalPaymentProcessing class - * - * PHP version 5 - * - * @category Event Management PayPal Payment Processing - * @package EventManagement - * @author Chuck Scott - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: PayPal.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ - * @link <> - */ - -class PaymentGateway -{ - /** - * Curl Object - * - * @var $curl - * @access private - */ - private $curl = false; - /** - * Result Status - * - * @var $status - * @access public - */ - public $status = false; - /** - * Access Data - * - * @var $access - * @access private - */ - public $access = false; - /** - * Curl Errors - * - * @var $error - * @access public - */ - public $error = ''; - /** - * PayPal Transaction - * - * @var $trans - * @access public - */ - public $trans; - /** - * Test Mode - Use Sandbox - * - * @var $sandbox - * @access public - */ - public $sandbox = false; - /** - * API URLs - * - * @var $apiURLs - * @access public - */ - public $apiURLs = false; - - /** - * Constructor - * - * To facilitate continuing after a return URL has been followed - * as required to execute or cancel the transaction, the constructor - * may optionally take an "access" object created in a previous - * instance (probably stored in a session or database) to re-establish - * a connection to the same transaction. - * - * @param array $account Account information - * @param object $access Access object from previous instance that should - * be used instead of creating a new one - * @param object $trans Transaction object from a previous instance. - * - * @return boolean Returns value of $success parameter - * @access public - * - * $account - * clientID PayPal Client ID - * secret PayPal Secret - * returnURL URL for PayPal to return to after payment confirmation by customer - * cancelURL URL for PayPal to return to after payment cancelation by customer - * test 1=Local Test (not available for PayPal), 2=Fail test (not available for PayPal), 3=PayPal Sandbox test, 0=Live production - * - */ - public function __construct($account, $access = false, $trans = false) - { - - // URLs to use for requests if we're using the development sandbox - $sandboxURLs = (object) array( - 'access' => 'https://api.sandbox.paypal.com/v1/oauth2/token', - 'process' => 'https://api.sandbox.paypal.com/v1/payments/payment', - 'execute' => 'https://api.sandbox.paypal.com/v1/payments/payment/{transID}/execute/' - ); - - // URLs to use for requests if we're doing live transactions - $liveURLs = (object) array( - 'access' => 'https://api.paypal.com/v1/oauth2/token', - 'process' => 'https://api.paypal.com/v1/payments/payment', - 'execute' => 'https://api.paypal.com/v1/payments/payment/{transID}/execute/' - ); - - - // Save account information - $this->account = $account; - - // Check for various test modes - switch ($this->account['test']) { - - // Local Test - case 1: - break; - - // Fail Test - case 2: - break; - - // Online Test - Use sandbox - case 3: - $this->sandbox = true; - $this->apiURLs = $sandboxURLs; - break; - - // Production Mode - case 0: - $this->sandbox = false; - $this->apiURLs = $liveURLs; - break; - } - - // Was an access object from a previous instance supplied? - if ($access) { - - // Yes, so store that and be done - $this->access = $access; - $this->status = true; - - // If we also have a transaction object - if ($trans) { - - // Store that - $this->trans = $trans; - } - - if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { - echo - '__construct() - Existing Instance

' - .'Account Data:
' - .'

'.print_r($account,1).'
' - .'Access:
' - .'
'.print_r($access,1)."
" - .'Transaction:
' - .'
'.print_r($trans,1)."
"; - } - - - // Otherwise, we need to create an access object - } else { - - // Build request information - $url = $this->apiURLs->access; - $headers = array( - "Accept: application/json", - "Accept-Language: en_US", - "Content-type: application/x-www-form-urlencoded" - ); - $request = 'grant_type=client_credentials'; - - if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { - echo - '__construct() - New Instance

' - .'Account Data:
' - .'

'.print_r($account,1).'
' - .'Headers:
' - .'
'.print_r($headers,1)."
" - .'Request:
' - .'
'.print_r($request,1)."
"; - } - - // Send request - $response = $this->sendRequest($url, $headers, $request); - - // If bad response - if (!$response) { - $this->access = false; - $this->status = false; - return; - } - - // Store our access data - $this->access = $response; - $this->status = true; - - } - - return $this->status; - } - - /** - * Process a Payment - * - * NOTE: For PayPal, this method only requests the payment. - * The user must follow the approval_url supplied by this - * method and confirm the payment. When that is done, PayPal - * will send the user to the approval_url along with a - * PayerID. The executePayment() method must then be called - * to actually execute the payment. - * - * @param array $payment Array payment information - * @param array $contact Array contact information - * - * @access public - * @return array - * - * Information provided - * - * $payment array - * name Name of vendor - required - * charge Total to be charged - required - * cctype Card type - not used - * ccname Name on card - not used - * ccnumb Card number - not used - * ccexp Expiration date (m/y) - not used - * cccode Security code on back of card - not used - * invoice Invoice # is session ID (or some part thereof) - not used - * description Description of transaction - not used - * items Array of items being purchased - required - * Each item has following - * - * quantity A number - Required - * name Name of the item - Required - * price Price of the item (numeric float) - Required - * sku SKU string - Optional - * - * - * $contact array - * fname Customer first name - * lname Customer last name - * addr1 Address Line 1 - * addr2 Address Line 2 - * city City - * state State - * country Country - * zip ZIP/Postal code - * phone Customer phone number - * email Customer E-Mail address - * - * return array - * status Numeric return status code - * 1 Approved - * 2 Bad data supplied - * 3 Communications failure - * 4 Bad response - * 5 Transaction not valid - * 6 Merchant account problem - * 7 Card declined - * statusText Short name of status - * authCode Authorization code - blank if card not accepted - * description Longer description of result - * - * - */ - public function processPayment($payment = false, $contact = false) - { - - // Check for local tests that don't require communication with PayPal - switch ($this->account['test']) { - - // Local Test - case 1: - // invalid type for PayPal class - default to sandbox - case 2: - // invalid type for PayPal class - default to sandbox - case 3: - $this->sandbox = true; - break; - - // Production Mode - case 0: - break; - } - - // Build request information - $url = $this->apiURLs->process; - $headers = array( - "Content-type:application/json", - 'Authorization:'.$this->access->token_type.' '.$this->access->access_token - ); - - // Build payment request - $charge = number_format($payment['charge'], 2, '.', ''); - $requestArray = array( - 'intent' => 'sale', - 'redirect_urls' => array( - 'return_url' => $this->account['returnURL'], - 'cancel_url' => $this->account['cancelURL'] - ), - 'payer' => array( - 'payment_method' => 'paypal' - ), - 'transactions' => array( - 0 => array( - 'amount' => array( - 'total' => $charge, - 'currency' => 'USD' - ), - 'item_list' => array( - 'items' => array( - ) - ) - ) - ) - ); - - // Add item list - if (isset($payment['items']) && count($payment['items']) > 0) { - - foreach ($payment['items'] as $item) { - - $item['name'] = trim($item['name']); - $item['currency'] = 'USD'; - $item['price'] = number_format($item['price'], 2, '.', ''); - - // Check required items - if ( - ($item['quantity']-0) <= 0 || - $item['name'] == '' || - ($item['price']-0) <= 0 - ) { - - if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { - echo "

ERROR: payment item incomplete

".print_r($item,1)."
"; - } - - // Can't proceed, bad data supplied - May need to warn someone of this problem here - $this->trans = false; - $this->status = false; - return; - - } - - // Add this item to the list - $requestArray['transactions'][0]['item_list']['items'][] = $item; - - } - - // If not, then we can't proceed - While not required by PayPal, we are requiring it - } else { - - echo "ERROR: PayPal integration requires an item list but none was provided along with " - ."the payment information to the processPayment() method."; - exit; - - } - - // Convert request to a JSON - $request = json_encode($requestArray, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - - if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { - echo 'processPayment()

' - .'Headers:
' - .'

'.print_r($headers,1)."
" - .'Request:
' - .'
'.$request.'
'; - } - - // Send request - $response = $this->sendRequest($url, $headers, $request); - - // If bad response - if (!$response) { - $this->trans = false; - $this->status = false; - return; - } - - // Store URLs in a way they can be easily accessed - $response->urls = new stdClass(); - foreach ($response->links as $link) { - $response->urls->{$link->rel} = $link; - } - - // Store our access data - $this->trans = $response; - $this->status = true; - - - return $this->status; - - - } - - /** - * Execute the Payment - * - * This is the final step in PayPal payment approval. - * This method should be called with the PayerID provided - * when the user is sent back to us on a return URL. - * - * Note for this to work, the constructor must have been - * suppled the access and transaction data. - * - * Since the transaction ID is passed to PayPal in the URL - * we're assuming that the response we get back is for the - * correct transaction, so we don't check that. - * - * @param string $payerID PayerID returned by PayPal on the return link - * - * @access public - * @return array - * - * - */ - public function executePayment($payerID) - { - - // Build request information - $url = str_replace('{transID}', $this->trans->id, $this->apiURLs->execute); - - $headers = array( - "Content-type:application/json", - 'Authorization:'.$this->access->token_type.' '.$this->access->access_token - ); - - // Build payment request - $charge = number_format($payment['charge'], 2, '.', ''); - $request = '{"payer_id" : "'.$payerID.'" }'; - - if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { - echo 'executePayment()

' - .'Headers:
' - .'

'.print_r($headers,1)."
" - .'Request:
' - .'
'.$request.'
'; - } - - // Send request - $response = $this->sendRequest($url, $headers, $request); - - // If bad response - if (!$response) { - $this->confirmation = false; - $this->status = false; - return false; - } - - // Save results - $this->confirmation = $response; - - // Check if payment not approved - if ($response->state != 'approved') { - $this->status = false; - return false; - } - - $r = array( - 'status' => 1, - 'statusText' => 'Approved', - 'authCode' => '', - 'description' => 'PayPal approval: ' - .$this->response->payer->payer_info->first_name.' ' - .$this->response->payer->payer_info->last_name.' ' - .$this->response->update_time, - 'payerName' => $this->response->payer->payer_info->first_name.' ' - .$this->response->payer->payer_info->last_name.' ' - - ); - - return $r; - } - - /** - * Make Curl call to place request - * - * @param array $headers Array of headers to include - * @param mixed $request Fields to supply as POST data, either string, array, or json - * - * @access public - * @return array - * - */ - private function sendRequest($url, $headers, $request) - { - - if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { - echo '

sendRequest():
URL = '.$url.'
Headers:

'
-    			.print_r($headers,1).'
Request:
'.print_r($request,1).'
'; - } - - // Init Curl - $this->curl = curl_init(); - - // Curl Parameters - $id_pw = $this->account['clientID'].':'.$this->account['secret']; - $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; - - // Set curl options - curl_setopt($this->curl, CURLOPT_URL, $url); - curl_setopt($this->curl, CURLOPT_SSLVERSION,4); - curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 2); - curl_setopt($this->curl, CURLOPT_HEADER, false); - curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers); - curl_setopt($this->curl, CURLOPT_POST, true); - curl_setopt($this->curl, CURLOPT_POSTFIELDS, $request); - curl_setopt($this->curl, CURLOPT_USERPWD, $id_pw); - curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($this->curl, CURLOPT_USERAGENT, $agent); - - // Place Curl call to get access token - $raw = curl_exec($this->curl); - - // If we received a good response - if (!curl_errno($this->curl)) { - - // Save access data - $response = json_decode($raw); - - if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { - echo 'Response:
' - .'
'.print_r($response,1).'
'; - } - - // Otherwise - } else { - - // Save our error message - $this->error = curl_error($this->curl); - $response = false; - - if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { - echo "Curl Error: ".$this->error."

"; - } - - } - - // Close our curl object - curl_close($this->curl); - - return $response; - - } - -} + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: PayPal.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + * @link <> + */ + + +/** + * Account Information + * + * Developer account + * PayPal API: https://developer.paypal.com/webapps/developer/ + * E-Mail Address: PayPal@n8dnx.org + * Password: pAy#glM2Pal + * + * PayPal test account + * E-Mail address: paypalAcct2@n8dnx.org + * Password: {std insecure}2 + * + * Test credentials + * Test account: PayPal-facilitator@n8dnx.org + * Endpoint: api.sandbox.paypal.com + * Client ID: AY2IlhCAFCgTaYSgrGfBQ0h5WKKgpLwU-jd2QkKsEbDpGEWtCDZKtp2VLhu1 + * Secret: EOWLsBDrkvdOKUlfhAKJ47aXHBr5xzw-2o7JdLCcLVciGqNGXlhMayP1WKhe + * + * Gaslight Media Live credentials + * Endpoint: api.paypal.com + * Client ID: AZw7VxC8rVTxlKoZVBd60ugOy_9PZWLDazQHF0RlYYWBQbAvkX2MBLy2vfmQ + * Secret: EN3ZaxB4AhZ3J1814MtpfFjUXOqRTR8dto-fhFgk2wuLDTCoPfD0I0Dpbwuu + * + * Standard PayPal buttons and images + * https://ppmts.custhelp.com/app/answers/detail/a_id/632 + * https://www.paypal.com/en_US/i/btn/x-click-but6.gif + */ + +/** + * EventManagementPayPalPaymentProcessing class + * + * PHP version 5 + * + * @category Event Management PayPal Payment Processing + * @package EventManagement + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: PayPal.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + * @link <> + */ + +class PaymentGateway +{ + /** + * Curl Object + * + * @var $curl + * @access private + */ + private $curl = false; + /** + * Result Status + * + * @var $status + * @access public + */ + public $status = false; + /** + * Access Data + * + * @var $access + * @access private + */ + public $access = false; + /** + * Curl Errors + * + * @var $error + * @access public + */ + public $error = ''; + /** + * PayPal Transaction + * + * @var $trans + * @access public + */ + public $trans; + /** + * Test Mode - Use Sandbox + * + * @var $sandbox + * @access public + */ + public $sandbox = false; + /** + * API URLs + * + * @var $apiURLs + * @access public + */ + public $apiURLs = false; + + /** + * Constructor + * + * To facilitate continuing after a return URL has been followed + * as required to execute or cancel the transaction, the constructor + * may optionally take an "access" object created in a previous + * instance (probably stored in a session or database) to re-establish + * a connection to the same transaction. + * + * @param array $account Account information + * @param object $access Access object from previous instance that should + * be used instead of creating a new one + * @param object $trans Transaction object from a previous instance. + * + * @return boolean Returns value of $success parameter + * @access public + * + * $account + * clientID PayPal Client ID + * secret PayPal Secret + * returnURL URL for PayPal to return to after payment confirmation by customer + * cancelURL URL for PayPal to return to after payment cancelation by customer + * test 1=Local Test (not available for PayPal), 2=Fail test (not available for PayPal), 3=PayPal Sandbox test, 0=Live production + * + */ + public function __construct($account, $access = false, $trans = false) + { + + // URLs to use for requests if we're using the development sandbox + $sandboxURLs = (object) array( + 'access' => 'https://api.sandbox.paypal.com/v1/oauth2/token', + 'process' => 'https://api.sandbox.paypal.com/v1/payments/payment', + 'execute' => 'https://api.sandbox.paypal.com/v1/payments/payment/{transID}/execute/' + ); + + // URLs to use for requests if we're doing live transactions + $liveURLs = (object) array( + 'access' => 'https://api.paypal.com/v1/oauth2/token', + 'process' => 'https://api.paypal.com/v1/payments/payment', + 'execute' => 'https://api.paypal.com/v1/payments/payment/{transID}/execute/' + ); + + + // Save account information + $this->account = $account; + + // Check for various test modes + switch ($this->account['test']) { + + // Local Test + case 1: + break; + + // Fail Test + case 2: + break; + + // Online Test - Use sandbox + case 3: + $this->sandbox = true; + $this->apiURLs = $sandboxURLs; + break; + + // Production Mode + case 0: + $this->sandbox = false; + $this->apiURLs = $liveURLs; + break; + } + + // Was an access object from a previous instance supplied? + if ($access) { + + // Yes, so store that and be done + $this->access = $access; + $this->status = true; + + // If we also have a transaction object + if ($trans) { + + // Store that + $this->trans = $trans; + } + + if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { + echo + '__construct() - Existing Instance

' + .'Account Data:
' + .'

'.print_r($account,1).'
' + .'Access:
' + .'
'.print_r($access,1)."
" + .'Transaction:
' + .'
'.print_r($trans,1)."
"; + } + + + // Otherwise, we need to create an access object + } else { + + // Build request information + $url = $this->apiURLs->access; + $headers = array( + "Accept: application/json", + "Accept-Language: en_US", + "Content-type: application/x-www-form-urlencoded" + ); + $request = 'grant_type=client_credentials'; + + if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { + echo + '__construct() - New Instance

' + .'Account Data:
' + .'

'.print_r($account,1).'
' + .'Headers:
' + .'
'.print_r($headers,1)."
" + .'Request:
' + .'
'.print_r($request,1)."
"; + } + + // Send request + $response = $this->sendRequest($url, $headers, $request); + + // If bad response + if (!$response) { + $this->access = false; + $this->status = false; + return; + } + + // Store our access data + $this->access = $response; + $this->status = true; + + } + + return $this->status; + } + + /** + * Process a Payment + * + * NOTE: For PayPal, this method only requests the payment. + * The user must follow the approval_url supplied by this + * method and confirm the payment. When that is done, PayPal + * will send the user to the approval_url along with a + * PayerID. The executePayment() method must then be called + * to actually execute the payment. + * + * @param array $payment Array payment information + * @param array $contact Array contact information + * + * @access public + * @return array + * + * Information provided + * + * $payment array + * name Name of vendor - required + * charge Total to be charged - required + * cctype Card type - not used + * ccname Name on card - not used + * ccnumb Card number - not used + * ccexp Expiration date (m/y) - not used + * cccode Security code on back of card - not used + * invoice Invoice # is session ID (or some part thereof) - not used + * description Description of transaction - not used + * items Array of items being purchased - required + * Each item has following + * + * quantity A number - Required + * name Name of the item - Required + * price Price of the item (numeric float) - Required + * sku SKU string - Optional + * + * + * $contact array + * fname Customer first name + * lname Customer last name + * addr1 Address Line 1 + * addr2 Address Line 2 + * city City + * state State + * country Country + * zip ZIP/Postal code + * phone Customer phone number + * email Customer E-Mail address + * + * return array + * status Numeric return status code + * 1 Approved + * 2 Bad data supplied + * 3 Communications failure + * 4 Bad response + * 5 Transaction not valid + * 6 Merchant account problem + * 7 Card declined + * statusText Short name of status + * authCode Authorization code - blank if card not accepted + * description Longer description of result + * + * + */ + public function processPayment($payment = false, $contact = false) + { + + // Check for local tests that don't require communication with PayPal + switch ($this->account['test']) { + + // Local Test + case 1: + // invalid type for PayPal class - default to sandbox + case 2: + // invalid type for PayPal class - default to sandbox + case 3: + $this->sandbox = true; + break; + + // Production Mode + case 0: + break; + } + + // Build request information + $url = $this->apiURLs->process; + $headers = array( + "Content-type:application/json", + 'Authorization:'.$this->access->token_type.' '.$this->access->access_token + ); + + // Build payment request + $charge = number_format($payment['charge'], 2, '.', ''); + $requestArray = array( + 'intent' => 'sale', + 'redirect_urls' => array( + 'return_url' => $this->account['returnURL'], + 'cancel_url' => $this->account['cancelURL'] + ), + 'payer' => array( + 'payment_method' => 'paypal' + ), + 'transactions' => array( + 0 => array( + 'amount' => array( + 'total' => $charge, + 'currency' => 'USD' + ), + 'item_list' => array( + 'items' => array( + ) + ) + ) + ) + ); + + // Add item list + if (isset($payment['items']) && count($payment['items']) > 0) { + + foreach ($payment['items'] as $item) { + + $item['name'] = trim($item['name']); + $item['currency'] = 'USD'; + $item['price'] = number_format($item['price'], 2, '.', ''); + + // Check required items + if ( + ($item['quantity']-0) <= 0 || + $item['name'] == '' || + ($item['price']-0) <= 0 + ) { + + if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { + echo "

ERROR: payment item incomplete

".print_r($item,1)."
"; + } + + // Can't proceed, bad data supplied - May need to warn someone of this problem here + $this->trans = false; + $this->status = false; + return; + + } + + // Add this item to the list + $requestArray['transactions'][0]['item_list']['items'][] = $item; + + } + + // If not, then we can't proceed - While not required by PayPal, we are requiring it + } else { + + echo "ERROR: PayPal integration requires an item list but none was provided along with " + ."the payment information to the processPayment() method."; + exit; + + } + + // Convert request to a JSON + $request = json_encode($requestArray, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); + + if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { + echo 'processPayment()

' + .'Headers:
' + .'

'.print_r($headers,1)."
" + .'Request:
' + .'
'.$request.'
'; + } + + // Send request + $response = $this->sendRequest($url, $headers, $request); + + // If bad response + if (!$response) { + $this->trans = false; + $this->status = false; + return; + } + + // Store URLs in a way they can be easily accessed + $response->urls = new stdClass(); + foreach ($response->links as $link) { + $response->urls->{$link->rel} = $link; + } + + // Store our access data + $this->trans = $response; + $this->status = true; + + + return $this->status; + + + } + + /** + * Execute the Payment + * + * This is the final step in PayPal payment approval. + * This method should be called with the PayerID provided + * when the user is sent back to us on a return URL. + * + * Note for this to work, the constructor must have been + * suppled the access and transaction data. + * + * Since the transaction ID is passed to PayPal in the URL + * we're assuming that the response we get back is for the + * correct transaction, so we don't check that. + * + * @param string $payerID PayerID returned by PayPal on the return link + * + * @access public + * @return array + * + * + */ + public function executePayment($payerID) + { + + // Build request information + $url = str_replace('{transID}', $this->trans->id, $this->apiURLs->execute); + + $headers = array( + "Content-type:application/json", + 'Authorization:'.$this->access->token_type.' '.$this->access->access_token + ); + + // Build payment request + $charge = number_format($payment['charge'], 2, '.', ''); + $request = '{"payer_id" : "'.$payerID.'" }'; + + if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { + echo 'executePayment()

' + .'Headers:
' + .'

'.print_r($headers,1)."
" + .'Request:
' + .'
'.$request.'
'; + } + + // Send request + $response = $this->sendRequest($url, $headers, $request); + + // If bad response + if (!$response) { + $this->confirmation = false; + $this->status = false; + return false; + } + + // Save results + $this->confirmation = $response; + + // Check if payment not approved + if ($response->state != 'approved') { + $this->status = false; + return false; + } + + $r = array( + 'status' => 1, + 'statusText' => 'Approved', + 'authCode' => '', + 'description' => 'PayPal approval: ' + .$this->response->payer->payer_info->first_name.' ' + .$this->response->payer->payer_info->last_name.' ' + .$this->response->update_time, + 'payerName' => $this->response->payer->payer_info->first_name.' ' + .$this->response->payer->payer_info->last_name.' ' + + ); + + return $r; + } + + /** + * Make Curl call to place request + * + * @param array $headers Array of headers to include + * @param mixed $request Fields to supply as POST data, either string, array, or json + * + * @access public + * @return array + * + */ + private function sendRequest($url, $headers, $request) + { + + if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { + echo '

sendRequest():
URL = '.$url.'
Headers:

'
+    			.print_r($headers,1).'
Request:
'.print_r($request,1).'
'; + } + + // Init Curl + $this->curl = curl_init(); + + // Curl Parameters + $id_pw = $this->account['clientID'].':'.$this->account['secret']; + $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; + + // Set curl options + curl_setopt($this->curl, CURLOPT_URL, $url); + curl_setopt($this->curl, CURLOPT_SSLVERSION,4); + curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 2); + curl_setopt($this->curl, CURLOPT_HEADER, false); + curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers); + curl_setopt($this->curl, CURLOPT_POST, true); + curl_setopt($this->curl, CURLOPT_POSTFIELDS, $request); + curl_setopt($this->curl, CURLOPT_USERPWD, $id_pw); + curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($this->curl, CURLOPT_USERAGENT, $agent); + + // Place Curl call to get access token + $raw = curl_exec($this->curl); + + // If we received a good response + if (!curl_errno($this->curl)) { + + // Save access data + $response = json_decode($raw); + + if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { + echo 'Response:
' + .'
'.print_r($response,1).'
'; + } + + // Otherwise + } else { + + // Save our error message + $this->error = curl_error($this->curl); + $response = false; + + if (defined('PAYPAL_DEBUG') && PAYPAL_DEBUG) { + echo "Curl Error: ".$this->error."

"; + } + + } + + // Close our curl object + curl_close($this->curl); + + return $response; + + } + +} diff --git a/lib/paymentProcessors/PayPal/test.php b/lib/paymentProcessors/PayPal/test.php index 6ee2f988..dc78ca57 100755 --- a/lib/paymentProcessors/PayPal/test.php +++ b/lib/paymentProcessors/PayPal/test.php @@ -1,111 +1,111 @@ - 'AY2IlhCAFCgTaYSgrGfBQ0h5WKKgpLwU-jd2QkKsEbDpGEWtCDZKtp2VLhu1', - 'secret' => 'EOWLsBDrkvdOKUlfhAKJ47aXHBr5xzw-2o7JdLCcLVciGqNGXlhMayP1WKhe', - 'returnURL' => $thisScript.'?PayPalAction=Approved', - 'cancelURL' => $thisScript.'?PayPalAction=Canceled', - 'test' => 3 -); -$payment = array( - 'name' => 'Gaslight Media', - 'charge' => 22.4, - 'invoice' => '123abc', - 'description' => 'Event Tickets Purchase', - 'items' => array( - array( - 'quantity' => '2', - 'name' => 'Fancy Dancy Dance', - 'price' => 5.6, - 'sku' => '123ABC1' - ), - array( - 'quantity' => '1', - 'name' => 'TuTu Tango', - 'price' => 11.2, - 'sku' => '123ABC2' - ) - ) -); -$contact = array(); - -// Load the PayPal class file -require_once dirname(__FILE__).'/PayPal.php'; - -// Start session -session_start(); - - -// Check for certain actions related to sending user to PayPal site for approval -switch ($_REQUEST['PayPalAction']) { - - case 'GetApproval': - - // Use browser redirect 302 to send user to PayPal. - // This is proper way to do so according to the API documentation. - $trans = $_SESSION['trans']; - header('Location: '.$trans->urls->approval_url->href); - exit; - - break; - - case 'Approved': - - echo "Return link followed.

"; - - // Save Payer ID - $_SESSION['payerID'] = $_REQUEST['PayerID']; // NEED TO FILTER THIS FOR PRODUCTION - - // Create PayPal object with existing access object from the session - $PayPal = new PaymentGateway($account, $_SESSION['access'], $_SESSION['trans']); - - // Execute the PayPal payment - $r = $PayPal->executePayment($_SESSION['payerID']); - - echo "Payment Executed Successfully

"; - - exit; - - break; - - case 'Canceled': - - echo "Payment Cancelled

"; - exit; - - break; -} - -// Create the PayPal object (note no previous access object) -$PayPal = new PaymentGateway($account, false, false); - -// Was there an error? -if (!$PayPal->status) { - echo "Received an error: ".$PayPal->error; - exit; -} - -// Store access information -$_SESSION['access'] = $PayPal->access; - -// Try to enter Payment -$PayPal->processPayment($payment, $contact); - -// Was there an error? -if (!$PayPal->status) { - echo "Received an error: ".$PayPal->error; - exit; -} - -// Store Transaction data to session -$_SESSION['trans'] = $PayPal->trans; - -// Show user link to PayPal for them to approve payment -// Note that uses a target to create a new window/tab -echo 'Proceed to PayPal'; - + 'AY2IlhCAFCgTaYSgrGfBQ0h5WKKgpLwU-jd2QkKsEbDpGEWtCDZKtp2VLhu1', + 'secret' => 'EOWLsBDrkvdOKUlfhAKJ47aXHBr5xzw-2o7JdLCcLVciGqNGXlhMayP1WKhe', + 'returnURL' => $thisScript.'?PayPalAction=Approved', + 'cancelURL' => $thisScript.'?PayPalAction=Canceled', + 'test' => 3 +); +$payment = array( + 'name' => 'Gaslight Media', + 'charge' => 22.4, + 'invoice' => '123abc', + 'description' => 'Event Tickets Purchase', + 'items' => array( + array( + 'quantity' => '2', + 'name' => 'Fancy Dancy Dance', + 'price' => 5.6, + 'sku' => '123ABC1' + ), + array( + 'quantity' => '1', + 'name' => 'TuTu Tango', + 'price' => 11.2, + 'sku' => '123ABC2' + ) + ) +); +$contact = array(); + +// Load the PayPal class file +require_once dirname(__FILE__).'/PayPal.php'; + +// Start session +session_start(); + + +// Check for certain actions related to sending user to PayPal site for approval +switch ($_REQUEST['PayPalAction']) { + + case 'GetApproval': + + // Use browser redirect 302 to send user to PayPal. + // This is proper way to do so according to the API documentation. + $trans = $_SESSION['trans']; + header('Location: '.$trans->urls->approval_url->href); + exit; + + break; + + case 'Approved': + + echo "Return link followed.

"; + + // Save Payer ID + $_SESSION['payerID'] = $_REQUEST['PayerID']; // NEED TO FILTER THIS FOR PRODUCTION + + // Create PayPal object with existing access object from the session + $PayPal = new PaymentGateway($account, $_SESSION['access'], $_SESSION['trans']); + + // Execute the PayPal payment + $r = $PayPal->executePayment($_SESSION['payerID']); + + echo "Payment Executed Successfully

"; + + exit; + + break; + + case 'Canceled': + + echo "Payment Cancelled

"; + exit; + + break; +} + +// Create the PayPal object (note no previous access object) +$PayPal = new PaymentGateway($account, false, false); + +// Was there an error? +if (!$PayPal->status) { + echo "Received an error: ".$PayPal->error; + exit; +} + +// Store access information +$_SESSION['access'] = $PayPal->access; + +// Try to enter Payment +$PayPal->processPayment($payment, $contact); + +// Was there an error? +if (!$PayPal->status) { + echo "Received an error: ".$PayPal->error; + exit; +} + +// Store Transaction data to session +$_SESSION['trans'] = $PayPal->trans; + +// Show user link to PayPal for them to approve payment +// Note that uses a target to create a new window/tab +echo 'Proceed to PayPal'; + ?> \ No newline at end of file diff --git a/lib/paymentProcessors/TestByCardNumber/paymentGateway.php b/lib/paymentProcessors/TestByCardNumber/paymentGateway.php index 9098c5fc..af02d0c7 100644 --- a/lib/paymentProcessors/TestByCardNumber/paymentGateway.php +++ b/lib/paymentProcessors/TestByCardNumber/paymentGateway.php @@ -1,190 +1,190 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: classes/paymentProcessors/test.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ - * @link <> - */ - -/** - * EventManagementAuthorizeNetPaymentProcessing class - * - * PHP version 5 - * - * @category Event Management Admin Tickets - * @package EventManagement - * @author Chuck Scott - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: classes/paymentProcessors/test.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ - * @link <> - */ - -/** - * Test Payment Gateway class - * - * PHP version 5 - */ - -class PaymentGateway -{ - - /** - * Constructor - * - * @param $account Array of account information - Not used for Test Processor - * - * @return boolean Returns value of $success parameter - * @access public - */ - function __construct($account = false) - { - - // Nothing to do here for the test processor - return true; - - } - - /* - * Process Credit Card Payment - * - * @param array $pmt Payment information - * - * array( - * 'gateway' => {selected payment gateway}, - * 'name' => {name of venue} - * 'charge' => {amount to charge card} - * 'cctype' => {type of card - text} - * 'ccnumb' => {card number - digits only} - * 'ccexp' => {expiration date as m/Y} - * 'ccode' => {security code on back of card} - * ) - * - * @param array $contact Billing contact information (not used in this class) - * - * This Test Processor looks at the last digit of the card number - * and synthesizes a corresponding response. - * - * 1 Card Approved - * 2 Bad Data Supplied - * 3 Communications Failure - * 4 Bad response or no response from processor - * 5 Transaction validation not accepted - * 6 Merchant authentication failure or bad account - * 7 Card Declined - * - * @return array Returns array of results - */ - function processPayment($pmt, $contact = false) - { - - // Get last digit of card number that indicates desired response - $respCode = substr($pmt['ccnumb'], 15, 1); - - // Approved flag - $approved = false; - - // Prepare synthesized response - switch ($respCode) { - - case 1: - - $resp = array( - 'gateway' => 'Card # Tests', - 'status' => 1, - 'statusText' => 'Card Approved', - 'authCode' => '00110011', - 'description' => 'Card Approved' - ); - break; - - case 2: - - $resp = array( - 'gateway' => 'Card # Tests', - 'status' => 2, - 'statusText' => 'Bad data supplied', - 'authCode' => '', - 'description' => 'Card number was not recognizable' - ); - break; - - case 3: - - $resp = array( - 'gateway' => 'Card # Tests', - 'status' => 3, - 'statusText' => 'Communications failure', - 'authCode' => '', - 'description' => 'We were unable to communicate with the credit card processing service.' - ); - break; - - case 4: - - $resp = array( - 'gateway' => 'Card # Tests', - 'status' => 4, - 'statusText' => 'Bad Response', - 'authCode' => '', - 'description' => 'We received an unrecognizable response from the credit card processing service.' - ); - break; - - case 5: - - $resp = array( - 'gateway' => 'Card # Tests', - 'status' => 5, - 'statusText' => 'Transaction not valid', - 'authCode' => '', - 'description' => 'We were unable to validate the response from the credit card processor.' - ); - break; - - case 6: - - $resp = array( - 'gateway' => 'Card # Tests', - 'status' => 6, - 'statusText' => 'Merchant account problem', - 'authCode' => '00110011', - 'description' => 'The merchant account for this venue was not recognized by the credit card processor.' - ); - break; - - case 7: - - $resp = array( - 'gateway' => 'Card # Tests', - 'status' => 7, - 'statusText' => 'Card Declined', - 'authCode' => '', - 'description' => 'Your credit card purchase was declined.' - ); - break; - - default: // Consider any other last digit as approved - - $resp = array( - 'gateway' => 'Card # Tests', - 'status' => 1, - 'statusText' => 'Card Approved', - 'authCode' => '00110011', - 'description' => 'Card Approved' - ); - break; - - } - - return $resp; - } - -} - - + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: classes/paymentProcessors/test.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + * @link <> + */ + +/** + * EventManagementAuthorizeNetPaymentProcessing class + * + * PHP version 5 + * + * @category Event Management Admin Tickets + * @package EventManagement + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: classes/paymentProcessors/test.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + * @link <> + */ + +/** + * Test Payment Gateway class + * + * PHP version 5 + */ + +class PaymentGateway +{ + + /** + * Constructor + * + * @param $account Array of account information - Not used for Test Processor + * + * @return boolean Returns value of $success parameter + * @access public + */ + function __construct($account = false) + { + + // Nothing to do here for the test processor + return true; + + } + + /* + * Process Credit Card Payment + * + * @param array $pmt Payment information + * + * array( + * 'gateway' => {selected payment gateway}, + * 'name' => {name of venue} + * 'charge' => {amount to charge card} + * 'cctype' => {type of card - text} + * 'ccnumb' => {card number - digits only} + * 'ccexp' => {expiration date as m/Y} + * 'ccode' => {security code on back of card} + * ) + * + * @param array $contact Billing contact information (not used in this class) + * + * This Test Processor looks at the last digit of the card number + * and synthesizes a corresponding response. + * + * 1 Card Approved + * 2 Bad Data Supplied + * 3 Communications Failure + * 4 Bad response or no response from processor + * 5 Transaction validation not accepted + * 6 Merchant authentication failure or bad account + * 7 Card Declined + * + * @return array Returns array of results + */ + function processPayment($pmt, $contact = false) + { + + // Get last digit of card number that indicates desired response + $respCode = substr($pmt['ccnumb'], 15, 1); + + // Approved flag + $approved = false; + + // Prepare synthesized response + switch ($respCode) { + + case 1: + + $resp = array( + 'gateway' => 'Card # Tests', + 'status' => 1, + 'statusText' => 'Card Approved', + 'authCode' => '00110011', + 'description' => 'Card Approved' + ); + break; + + case 2: + + $resp = array( + 'gateway' => 'Card # Tests', + 'status' => 2, + 'statusText' => 'Bad data supplied', + 'authCode' => '', + 'description' => 'Card number was not recognizable' + ); + break; + + case 3: + + $resp = array( + 'gateway' => 'Card # Tests', + 'status' => 3, + 'statusText' => 'Communications failure', + 'authCode' => '', + 'description' => 'We were unable to communicate with the credit card processing service.' + ); + break; + + case 4: + + $resp = array( + 'gateway' => 'Card # Tests', + 'status' => 4, + 'statusText' => 'Bad Response', + 'authCode' => '', + 'description' => 'We received an unrecognizable response from the credit card processing service.' + ); + break; + + case 5: + + $resp = array( + 'gateway' => 'Card # Tests', + 'status' => 5, + 'statusText' => 'Transaction not valid', + 'authCode' => '', + 'description' => 'We were unable to validate the response from the credit card processor.' + ); + break; + + case 6: + + $resp = array( + 'gateway' => 'Card # Tests', + 'status' => 6, + 'statusText' => 'Merchant account problem', + 'authCode' => '00110011', + 'description' => 'The merchant account for this venue was not recognized by the credit card processor.' + ); + break; + + case 7: + + $resp = array( + 'gateway' => 'Card # Tests', + 'status' => 7, + 'statusText' => 'Card Declined', + 'authCode' => '', + 'description' => 'Your credit card purchase was declined.' + ); + break; + + default: // Consider any other last digit as approved + + $resp = array( + 'gateway' => 'Card # Tests', + 'status' => 1, + 'statusText' => 'Card Approved', + 'authCode' => '00110011', + 'description' => 'Card Approved' + ); + break; + + } + + return $resp; + } + +} + + ?> \ No newline at end of file diff --git a/lib/paymentProcessors/TestGood/paymentGateway.php b/lib/paymentProcessors/TestGood/paymentGateway.php index 2dd38a87..d5e5dbe1 100644 --- a/lib/paymentProcessors/TestGood/paymentGateway.php +++ b/lib/paymentProcessors/TestGood/paymentGateway.php @@ -1,96 +1,96 @@ - - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: classes/paymentProcessors/no_payment.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ - * @link <> - */ - -/** - * No Payment PaymentGateway class - * - * PHP version 5 - * - * @category Event Management Admin Tickets - * @package EventManagement - * @author Chuck Scott - * @license http://www.gaslightmedia.com Gaslightmedia - * @release SVN: $Id: classes/paymentProcessors/no_payment.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ - * @link <> - */ - -/** - * No Payment Gateway class - * - * PHP version 5 - */ - -class PaymentGateway -{ - - /** - * Constructor - * - * @param $account Array of account information - Not used for Test Processor - * - * @return boolean Returns value of $success parameter - * @access public - */ - function __construct($account = false) - { - - // Nothing to do here - return true; - - } - - /* - * No Payment Required - * - * @param array $pmt Payment information - * - * array( - * 'gateway' => {selected payment gateway}, - * 'name' => {name of venue} - * 'charge' => {amount to charge card} - * 'cctype' => {type of card - text} - * 'ccnumb' => {card number - digits only} - * 'ccexp' => {expiration date as m/Y} - * 'ccode' => {security code on back of card} - * ) - * - * @param array $contact Billing contact information (not used in this class) - * - * This Processor always returns a "Card Approved" status - * and synthesizes a corresponding response. - * - * 1 Card Approved - * - * @return array Returns array of results - */ - function processPayment($pmt, $contact = false) - { - - // Get last digit of card number that indicates desired response - $respCode = 'NO-PAYMENT'; - - // Approved flag - $approved = false; - - $resp = array( - 'gateway' => 'Card Good', - 'status' => 1, - 'statusText' => 'No Payment', - 'authCode' => '000000', - 'description' => 'No Payment Required' - ); - - return $resp; - } - + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: classes/paymentProcessors/no_payment.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + * @link <> + */ + +/** + * No Payment PaymentGateway class + * + * PHP version 5 + * + * @category Event Management Admin Tickets + * @package EventManagement + * @author Chuck Scott + * @license http://www.gaslightmedia.com Gaslightmedia + * @release SVN: $Id: classes/paymentProcessors/no_payment.php,v 1.0 2011/01/25 19:31:47 cscott Exp $ + * @link <> + */ + +/** + * No Payment Gateway class + * + * PHP version 5 + */ + +class PaymentGateway +{ + + /** + * Constructor + * + * @param $account Array of account information - Not used for Test Processor + * + * @return boolean Returns value of $success parameter + * @access public + */ + function __construct($account = false) + { + + // Nothing to do here + return true; + + } + + /* + * No Payment Required + * + * @param array $pmt Payment information + * + * array( + * 'gateway' => {selected payment gateway}, + * 'name' => {name of venue} + * 'charge' => {amount to charge card} + * 'cctype' => {type of card - text} + * 'ccnumb' => {card number - digits only} + * 'ccexp' => {expiration date as m/Y} + * 'ccode' => {security code on back of card} + * ) + * + * @param array $contact Billing contact information (not used in this class) + * + * This Processor always returns a "Card Approved" status + * and synthesizes a corresponding response. + * + * 1 Card Approved + * + * @return array Returns array of results + */ + function processPayment($pmt, $contact = false) + { + + // Get last digit of card number that indicates desired response + $respCode = 'NO-PAYMENT'; + + // Approved flag + $approved = false; + + $resp = array( + 'gateway' => 'Card Good', + 'status' => 1, + 'statusText' => 'No Payment', + 'authCode' => '000000', + 'description' => 'No Payment Required' + ); + + return $resp; + } + } \ No newline at end of file -- 2.17.1