From 09c4f1f43f4c93570665f7d900bb8c376a1599ee Mon Sep 17 00:00:00 2001 From: Nicholas Wech Date: Thu, 2 Mar 2017 16:04:41 -0600 Subject: [PATCH 1/5] Fixed inspection errors. Added author --- Class.PayFlow.php | 1580 ++++++++++++++++++++++----------------------- 1 file changed, 776 insertions(+), 804 deletions(-) diff --git a/Class.PayFlow.php b/Class.PayFlow.php index 7741cb9..7ff15d2 100644 --- a/Class.PayFlow.php +++ b/Class.PayFlow.php @@ -1,817 +1,789 @@ 'https://payflowpro.paypal.com', - 'test'=>'https://pilot-payflowpro.paypal.com', - ); - - - /** - * @uses Contains the keys for submitting a transaction to PayPal. - * @access Private - * @var Array - */ - private $NVP = array(); - - - /** - * @uses Contains an array of values returned from processing the transaction. - * @access Private - * @var Array - */ - private $response = ''; - - - - - - /** - * @uses Constructor - User paramters to provide the merchant authentication required for access to the payment gateway. - * @access Public - * @param String $vendor - Your merchant login ID that you created when you registered for the account. - * @param String $partner - The ID provided to you by the authorized PayPal Reseller who registered you for the Payflow SDK. - * @param String $user - If you set up one or more additional users on the account, this value is the ID of the user authorized to process transactions. If, however, you have not set up additional users on the account, USER has the same value as VENDOR. - * @param String $password - The password that you defined while registering for the account. - * @param String $billingType - Type of billing transaction this will be 'single' or 'recurring'. - * @return None. - * @example $PayFlow = new PayFlow('VENDER', 'PARTNER', 'USER', 'PASSWORD', 'single'); - */ - public function __construct($vendor = '', $partner = '', $user = '', $password = '', $billingType = 'single') { - $this->vendor = $this->truncateChars($vendor, 64); - $this->partner = $this->truncateChars($partner, 64); - $this->user = $this->truncateChars($user, 64); - $this->password = $this->truncateChars($password, 32); - $this->billingType = $billingType; - - // Setup some default values. - $this->setupDefaults(); - } - - - /** - * @uses Destructor. - * @access Public - * @param None. - * @return None. - * @example unset($obj); - */ - public function __destruct() { - unset($this); - } - - - /** - * @uses Sets up default transaction information. - * @access Private - * @param None. - * @return None. - * @example $this->setupDefaults(); - */ - private function setupDefaults() { - $defaults = array( - 'VENDOR'=>$this->vendor, - 'PARTNER'=>$this->partner, - 'USER'=>$this->user, - 'PWD'=>$this->password, - 'CUSTIP'=>$_SERVER['REMOTE_ADDR'], - 'VERBOSITY'=>'MEDIUM', - ); - - $this->NVP = array_merge($this->NVP, $defaults); - } - - - /** - * @uses Sets the Environment of the transaction. - * @access Public - * @param String $environment - Available values: ('test', 'live'). - * @return None. - * @example $PayFlow->setEnvironment('test'); - */ - public function setEnvironment($environment = 'test') { - if(strtolower($environment) == 'test') { - $this->environment = $this->gatewayURL['test']; - } - else { - $this->environment = $this->gatewayURL['live']; - } - } - - - /** - * @uses Returns the Environment of the transaction. - * @access Public - * @param None. - * @return String - The environment set. - * @example $PayFlow->getEnvironment(); - */ - public function getEnvironment() { - return $this->environment; - } - - - /** - * @uses Sets the type of transaction. - * @access Public - * @param String $transactionType - Available values: S = Sale transaction, R = Recurring, C = Credit, A = Authorization, D = Delayed Capture, V = Void, F = Voice Authorization, I = Inquiry, N = Duplicate transaction - * @return None. - * @example $PayFlow->setTransactionType('S'); - */ - public function setTransactionType($transactionType = 'S') { - $type = array( - 'TRXTYPE'=>strtoupper($transactionType), - ); - - $this->NVP = array_merge($this->NVP, $type); - } - - - /** - * @uses Sets the Payment Method. - * @access Public - * @param String $paymentMethod - Available values: A = Automated clearinghouse, C = Credit card, D = Pinless debit, K = Telecheck, P = PayPal. - * @return None. - * @example $PayFlow->setPaymentMethod('C'); - */ - public function setPaymentMethod($paymentMethod = 'C') { - $method = array( - 'TENDER'=>strtoupper($paymentMethod), - ); - - $this->NVP = array_merge($this->NVP, $method); - } - - - /** - * @uses Sets the Payment Currency. - * @access Public - * @param String $paymentCurrency - Available values: 'USD', 'EUR', 'GBP', 'CAD', 'JPY', 'AUD'. - * @return None. - * @example $PayFlow->setPaymentCurrency('USD'); - */ - public function setPaymentCurrency($paymentCurrency = 'USD') { - $currency = array( - 'CURRENCY'=>strtoupper($paymentCurrency), - ); - - $this->NVP = array_merge($this->NVP, $currency); - } - - - /** - * @uses Sets the Profile Action for recurring payments. - * @access Public - * @param String $profileAction - Available values: A = Add, M = Modify, R = Reactivate, C = Cancel, I = Inquiry, P = Payment. - * @return None. - * @example $PayFlow->setProfileAction('A'); - */ - public function setProfileAction($profileAction = 'A') { - $action = array( - 'ACTION'=>strtoupper($profileAction), - ); - - $this->NVP = array_merge($this->NVP, $action); - } - - - /** - * @uses Sets the Profile name for recurring payments. - * @access Public - * @param String $profileName - Non-unique Name for the profile (user-specified). Can be used to search for a profile. - * @return None. - * @example $PayFlow->setProfileName('RegularSubscription'); - */ - public function setProfileName($profileName = 'RecurringTransaction') { - $name = array( - 'PROFILENAME'=>strtoupper($profileName), - ); - - $this->NVP = array_merge($this->NVP, $name); - } - - - /** - * @uses Sets the Profile Start Date for recurring payments. - * @access Public - * @param String $profileStartDate - Beginning date for the recurring billing cycle used to calculate when payments should be made. Use tomorrow's date or a date in the future. Format: MMDDYYYY. - * @return None. - * @example $PayFlow->setProfileStartDate('01072011'); - */ - public function setProfileStartDate($profileStartDate = '') { - if($profileStartDate == '') { - $profileStartDate = date('mdY', strtotime("+1 day"));; - } - $date = array( - 'START'=>strtoupper($profileStartDate), - ); - - $this->NVP = array_merge($this->NVP, $date); - } - - - /** - * @uses Sets the Profile Pay Period for recurring payments. - * @access Public - * @param String $profilePayPeriod - Specifies how often the payment occurs. Available values: including all capital letters. - * WEEK: Weekly - Every week on the same day of the week as the first payment. - * BIWK: Every Two Weeks - Every other week on the same day of the week as the first payment. - * SMMO: Twice Every Month - The 1st and 15th of the month. Results in 24 payments per year. SMMO can start on 1st to 15th of the month, second payment 15 days later or on the last day of the month. - * FRWK: Every Four Weeks - Every 28 days from the previous payment date beginning with the first payment date. Results in 13 payments per year. - * MONT: Monthly - Every month on the same date as the first payment. Results in 12 payments per year. - * QTER: Quarterly - Every three months on the same date as the first payment. - * SMYR: Twice Every Year - Every six months on the same date as the first payment. - * YEAR: Yearly - Every 12 months on the same date as the first payment. - * @return None. - * @example $PayFlow->setProfileStartDate('MONT'); - */ - public function setProfilePayPeriod($profilePayPeriod = 'MONT') { - $period = array( - 'PAYPERIOD'=>strtoupper($profilePayPeriod), - ); - - $this->NVP = array_merge($this->NVP, $period); - } - - - /** - * @uses Sets the Profile Term for recurring payments. - * @access Public - * @param String $profileTerm - Number of payments to be made over the life of the agreement. A value of 0 means that payments should continue until the profile is deactivated. - * @return None. - * @example $PayFlow->setProfileTerm(0); - */ - public function setProfileTerm($profileTerm = 0) { - $term = array( - 'TERM'=>strtoupper($profileTerm), - ); - - $this->NVP = array_merge($this->NVP, $term); - } - - - /** - * @uses Sets the Amount of the transaction. Up to 15 digits with a decimal point (no dollar symbol) - * @access Public - * @param String/Integer/Float - $amount - 150.00. - * @param Boolean - $wholeAmt - True to remove decimal valuesfalse, to keep it. - * @return None. - * @example $PayFlow->setAmount(150.00); - */ - public function setAmount($amount = 0, $wholeAmt) { - $amt = array( - 'AMT'=>$this->cleanAmt($amount, $wholeAmt), - ); - - $this->NVP = array_merge($this->NVP, $amt); - } - - - /** - * @uses Sets the Customer's Credit Card Number. Between 13 and 16 digits without spaces. - * @access Public - * @param String $number - The Credit Card Number. Dashes will be striped. - * @return None. - * @example $PayFlow->setCCNumber('1234-1234-1234-1234'); - */ - public function setCCNumber($number = '') { - $cc = array( - 'ACCT'=>$this->cleanCCNumber($number), - ); - - $this->NVP = array_merge($this->NVP, $cc); - } - - - /** - * @uses Sets the Customer's Credit Card Expiration Date. MMYY - * @access Public - * @param String $expiration - The Customer's Credit Card Expiration Date - * @return None. - * @example $PayFlow->setExpiration('0312'); - */ - public function setExpiration($expiration = '0000') { - $exp = array( - 'EXPDATE'=>$this->cleanExpDate($expiration), - ); - - $this->NVP = array_merge($this->NVP, $exp); - } - - - /** - * @uses Sets the Customer's card code. The three- or four-digit number on the back of a credit card (on the front for American Express). - * @access Public - * @param String $cvv - The Customer's Credit Card Security Code - * @return None. - * @example $PayFlow->setCVV('0000'); - */ - public function setCVV($cvv = '') { - $security = array( - 'CVV2'=>$cvv, - ); - - $this->NVP = array_merge($this->NVP, $security); - } - - - /** - * @uses Sets the Customer's Credit Card Name. Up to 50 characters - * @access Public - * @param String $cardName - The First Name associated with the Customer's Billing Address. - * @return None. - * @example $PayFlow->setCreditCardName('Richard'); - */ - public function setCreditCardName($cardName = '') { - $name = array( - 'NAME'=>$this->truncateChars($cardName, 50), - ); - - $this->NVP = array_merge($this->NVP, $name); - } - - - /** - * @uses Sets the First Name associated with the Customer's Billing Address. Up to 30 characters (no symbols) - * @access Public - * @param String $firstName - The First Name associated with the Customer's Billing Address. - * @return None. - * @example $PayFlow->setCustomerFirstName('Richard'); - */ - public function setCustomerFirstName($firstName = '') { - $first = array( - 'FIRSTNAME'=>$this->truncateChars($firstName, 30), - ); - - $this->NVP = array_merge($this->NVP, $first); - } - - - /** - * @uses Sets the Last Name associated with the Customer's Billing Address. Up to 30 characters (no symbols) - * @access Public - * @param String $lastName - The Last Name associated with the Customer's Billing Address. - * @return None. - * @example $PayFlow->setCustomerLastName('Castera'); - */ - public function setCustomerLastName($lastName = '') { - $last = array( - 'LASTNAME'=>$this->truncateChars($lastName, 30), - ); - - $this->NVP = array_merge($this->NVP, $last); - } - - - /** - * @uses Sets the Customer's Billing address. Up to 30 characters (no symbols) - * @access Public - * @param String $customerAddress - The Customer's Billing address. - * @return None. - * @example $PayFlow->setCustomerAddress('589 8th Ave. Suite 10'); - */ - public function setCustomerAddress($customerAddress = '') { - $address = array( - 'STREET'=>$this->truncateChars($customerAddress, 30), - ); - - $this->NVP = array_merge($this->NVP, $address); - } - - - /** - * @uses Sets the Customer's Billing City. Up to 20 characters (no symbols) - * @access Public - * @param String $customerCity - The Customer's Billing City. - * @return None. - * @example $PayFlow->setCustomerCity('New York'); - */ - public function setCustomerCity($customerCity = '') { - $city = array( - 'CITY'=>$this->truncateChars($customerCity, 20), - ); - - $this->NVP = array_merge($this->NVP, $city); - } - - - /** - * @uses Sets the Customer's Billing State. Up to 2 characters (no symbols) a valid two-character state code. - * @access Public - * @param String $customerState - The Customer's Billing State. - * @return None. - * @example $PayFlow->setCustomerState('NY'); - */ - public function setCustomerState($customerState = '') { - $state = array( - 'STATE'=>$this->truncateChars($customerState, 2), - ); - - $this->NVP = array_merge($this->NVP, $state); - } - - - /** - * @uses Sets the Customer's Billing Zip. Up to 9 characters (no symbols). - * @access Public - * @param String $customerZip - The Customer's Billing Zip. - * @return None. - * @example $PayFlow->setCustomerZip('10018'); - */ - public function setCustomerZip($customerZip = '') { - $zip = array( - 'ZIP'=>$this->truncateChars($customerZip, 9), - ); - - $this->NVP = array_merge($this->NVP, $zip); - } - - - /** - * @uses Sets the Customer's Billing Country. Up to 4 characters (no symbols). - * @access Public - * @param String $customerCountry - The Customer's Billing Country. - * @return None. - * @example $PayFlow->setCustomerCountry('US'); - */ - public function setCustomerCountry($customerCountry = '') { - $country = array( - 'COUNTRY'=>$this->truncateChars($customerCountry, 4), - ); - - $this->NVP = array_merge($this->NVP, $country); - } - - - /** - * @uses Sets the Customer's Billing Phone. Up to 20 digits (no letters) Ex. 123-123-1234 - Dashes will be stripped. - * @access Public - * @param String $customerPhone - The Customer's Billing Phone. - * @return None. - * @example $PayFlow->setCustomerPhone('212-123-4567'); - */ - public function setCustomerPhone($customerPhone = '000-000-0000') { - $phone = array( - 'PHONENUM'=>$this->truncateChars($this->cleanPhoneNumber($customerPhone), 20), - ); - - $this->NVP = array_merge($this->NVP, $phone); - } - - - /** - * @uses Sets the Customer's Email Address. Up to 60 characters. - * @access Public - * @param String $customerEmail - The Customer's Email Address. - * @return None. - * @example $PayFlow->setCustomerEmail('richard.castera@gmail.com'); - */ - public function setCustomerEmail($customerEmail = '') { - $email = array( - 'EMAIl'=>$this->truncateChars($customerEmail, 60), - ); - - $this->NVP = array_merge($this->NVP, $email); - } - - - /** - * @uses Sets the Payment Description. This is just a commment regarding the transaction for your reference. - * @access Public - * @param String $description - The Payment description. - * @return None. - * @example $PayFlow->setPaymentComment('Purchased product number 34324'); - */ - public function setPaymentComment($description = '') { - $desc = array( - 'COMMENT1'=>$this->truncateChars($description, 128), - ); - - $this->NVP = array_merge($this->NVP, $desc); - } - - - /** - * @uses Sets the Payment Description. This is just a commment regarding the transaction for your reference. - * @access Public - * @param String $description - The Payment description. - * @return None. - * @example $PayFlow->setPaymentComment2('Purchased product number 34324'); - */ - public function setPaymentComment2($description = '') { - $desc = array( - 'COMMENT2'=>$this->truncateChars($description, 128), - ); - - $this->NVP = array_merge($this->NVP, $desc); - } - - - /** - * @uses Sets a Merchant-defined field to submit to Paypal. - * @access Public - * @param String $name - The name of the custom field. - * @param String $value - The value of the custom field. - * @return None. - * @example $PayFlow->setCustomField('KEY', 'VALUE'); - */ - public function setCustomField($name = '', $value = '') { - $custom = array( - $name=>(string)$value, + + + /** + * @uses Your merchant login ID that you created when you registered for the account. + * @access Private + * @var String + */ + private $vendor = ''; + + + /** + * @uses The ID provided to you by the authorized PayPal Reseller who registered you for the Payflow SDK. + * @access Private + * @var String + */ + private $partner = ''; + + + /** + * @uses This value is the ID of the user authorized to process transactions. + * @access Private + * @var String + */ + private $user = ''; + + + /** + * @uses The password that you defined while registering for the account. + * @access Private + * @var String + */ + private $password = ''; + + + /** + * @uses The environment - (test or live). + * @access Private + * @var String + */ + private $environment = ''; + + + /** + * @uses The type of billing transaction - (single or recurring). + * @access Private + * @var String + */ + private $billingType = ''; + + + /** + * @uses Contains the URLS for submitting a transaction. + * @access Private + * @var array + */ + private $gatewayURL = array ( + 'live'=>'https://payflowpro.paypal.com', + 'test'=>'https://pilot-payflowpro.paypal.com', ); - - $this->NVP = array_merge($this->NVP, $custom); - } - - - /** - * @uses This get the NVP's that will be sent to Paypal. - * @access Private - * @param None. - * @return String - A string of NVP's. - * @example $this->getNVP(); - */ - private function getNVP() { - $post = ''; - foreach($this->NVP as $key=>$value) { - $post .= "$key=" . $value . "&"; - } - return (string)rtrim($post, "& "); - } - - - /** - * @uses Sends the request to Paypal for processing. - * @access Public - * @param None. - * @return Boolean - True if the transaction was successful False, if not. - * @example $PayFlow->processTransaction(); - */ - public function processTransaction() { - // Uses the CURL library for php to establish a connection, - // submit the post, and record the response. - if(function_exists('curl_init') && extension_loaded('curl')) { - $request = curl_init($this->getEnvironment()); // Initiate curl object - curl_setopt($request, CURLOPT_HTTPHEADER, $this->getHeaders($this->NVP)); - curl_setopt($request, CURLOPT_HEADER, 1); // Set to 0 to eliminate header info from response - curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1) - curl_setopt($request, CURLOPT_TIMEOUT, 45); // times out after 45 secs - curl_setopt($request, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done - curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // Uncomment this line if you get no gateway response. - curl_setopt($request, CURLOPT_POST, 1); //data sent as POST - curl_setopt($request, CURLOPT_POSTFIELDS, $this->getNVP()); // Use HTTP POST to send the data - $postResponse = curl_exec($request); // Execute curl post and store results in $post_response - - // Additional options may be required depending upon your server configuration - // you can find documentation on curl options at http://www.php.net/curl_setopt - curl_close($request); // close curl object - - // Get the response. - $this->response = $postResponse; - - $this->response = $this->parseResults($this->response); - - if(isset($this->response['RESULT']) && $this->response['RESULT'] == 0) { - return TRUE; - } - else { - return FALSE; - } - } - else { - return FALSE; - } - } - - - /** - * @uses Generates the headers we need to send to Payflow. - * @access Private - * @param Array - $params - The NVP value pairs. - * @return Array - Header information for cURL. - * @example $this->getHeaders($params); - */ - private function getHeaders($params){ - $headers[] = "Content-Type: text/namevalue"; - $headers[] = "X-VPS-Timeout: 30"; - $headers[] = "X-VPS-VIT-Client-Certification-Id: 33baf5893fc2123d8b191d2d011b7fdc"; // This header requirement will be removed - $headers[] = "X-VPS-Request-ID: " . $this->getRequestId($params); - return $headers; - } - - - /** - * @uses Generates a unique request id with the credit card number, amount, and timestamp. - * @access Private - * @param Array - $params - The NVP value pairs. - * @return String - Unique id. - * @example $this->getRequestId($params); - */ - private function getRequestId($params){ - if(isset($params['ACCT'])) { - $requestId = md5($params['ACCT'] . $params['AMT'] . date('YmdGis') . "1"); - return $requestId; - } - else { - return md5(time()); - } - } - - - /** - * @uses Gets the response from Paypal. - * @access Public - * @param None. - * @return Array/String - Returns an array of Paypal's response or empty string if not return. - * @example $PayFlow->getResponse(); - */ - public function getResponse() { - if($this->response) { - return $this->response; - } - else { - return ''; - } - } - - - /** - * @uses Parses the response from Paypal. - * @access Private - * @param Array - $result - The NVP result from the transaction. - * @return Array/String - Returns an array of Paypal's response or empty string if not return. - * @example $PayFlow->getResponse(); - */ - private function parseResults($result) { - if(empty($result)) { - return ''; - } - - $response = array(); - $result = strstr($result, 'RESULT'); - $value = explode('&', $result); - foreach($value as $token) { - $key = explode('=', $token); - $response[$key[0]] = $key[1]; - } - return $response; - } - - - /** - * @uses Formats the monetary amount sent to Paypal. - * @access Private - * @param String/Integer/Float $amount - The amount to clean. - * @param Boolean $wholeAmt - True to remove cents false, to keep it. - * @return Integer/Float - Returns the monetary amount formatted based on the $wholeAmt parameter. - * @example $this->cleanAmt(); - */ - private function cleanAmt($amount = 0, $wholeAmt = FALSE) { - if($wholeAmt) { - $amount = preg_replace('/[^0-9.]/', '', trim($amount)); - return (int)$amount; - } - else { - $amount = preg_replace('/[^0-9.]/', '', trim($amount)); - return (float)$amount; - } - } - - - /** - * @uses Removes all characters from the credit card number except for numbers. - * @access Private - * @param String $cc - The crdeit card number. - * @return String - Returns the credit card number with only numeric characters. - * @example $this->cleanCCNumber('5412-2232-2323-3443'); - */ - private function cleanCCNumber($cc = '') { - $cc = preg_replace('/[^0-9]/', '', trim($cc)); - return (string)$cc; - } - - - /** - * @uses Removes all characters from the telephone number except for numbers and dashes. - * @access Private - * @param String $phone - The phone number. - * @return String - Returns the phone number with dashes. - * @example $this->cleanPhoneNumber('718-232-2323'); - */ - private function cleanPhoneNumber($phone = '') { - $phone = preg_replace('/[^0-9]/', '', trim($phone)); - return (string)$phone; - } - - - /** - * @uses Removes all characters from the Expiration date except for numbers, slashes and dashes. - * @access Private - * @param String $exp - The expiration date. - * @return String - Returns the expiration date formatted for Paypal. - * @example $this->cleanExpDate('05/10'); - */ - private function cleanExpDate($exp = '') { - $exp = preg_replace('/[^0-9]/', '', trim($exp)); - return (string)$exp; - } - - - /** - * @uses Used to truncate values. - * @access Private - * @param String $string - The string to truncate. - * @param Integer $limit - The amount to truncate. - * @return Returns the string truncated. - * @example $this->truncateChars('Richard Castera', 10); - */ - private function truncateChars($string = '', $limit = 0) { - for($i = 0; $i <= $limit AND $i < strlen($string); $i++){ - $output .= $string[$i]; - } - return (string)trim($output); - } - - - /** - * @uses Used to debug values that will be sent to Paypal. - * @access Public - * @param String $type - Valid values are 'array' or 'string'. - * @return This returns either and array of the NVP's or a string based on the parameter chosen. - * @example $PayFlow->debugNVP('array'); - */ - public function debugNVP($type = 'array') { - if($type == 'array') { - return $this->NVP; - } - else { - return $this->getNVP(); - } - } + + + /** + * @uses Contains the keys for submitting a transaction to PayPal. + * @access Private + * @var array + */ + private $NVP = array(); + + + /** + * @uses Contains an array of values returned from processing the transaction. + * @access Private + * @var array + */ + private $response = ''; + + + + + + /** + * @uses Constructor - User paramters to provide the merchant authentication required for access to the payment gateway. + * @access Public + * @param String $vendor - Your merchant login ID that you created when you registered for the account. + * @param String $partner - The ID provided to you by the authorized PayPal Reseller who registered you for the Payflow SDK. + * @param String $user - If you set up one or more additional users on the account, this value is the ID of the user authorized to process transactions. If, however, you have not set up additional users on the account, USER has the same value as VENDOR. + * @param String $password - The password that you defined while registering for the account. + * @param String $billingType - Type of billing transaction this will be 'single' or 'recurring'. + * @example $PayFlow = new PayFlow('VENDER', 'PARTNER', 'USER', 'PASSWORD', 'single'); + */ + public function __construct($vendor = '', $partner = '', $user = '', $password = '', $billingType = 'single') { + $this->vendor = $this->truncateChars($vendor, 64); + $this->partner = $this->truncateChars($partner, 64); + $this->user = $this->truncateChars($user, 64); + $this->password = $this->truncateChars($password, 32); + $this->billingType = $billingType; + + // Setup some default values. + $this->setupDefaults(); + } + + + /** + * @uses Destructor. + * @access Public + * @param None. + * @example unset($obj); + */ + public function __destruct() { + unset($this); + } + + + /** + * @uses Sets up default transaction information. + * @access Private + * @param None. + * @example $this->setupDefaults(); + */ + private function setupDefaults() { + $defaults = array( + 'VENDOR'=>$this->vendor, + 'PARTNER'=>$this->partner, + 'USER'=>$this->user, + 'PWD'=>$this->password, + 'CUSTIP'=>$_SERVER['REMOTE_ADDR'], + 'VERBOSITY'=>'MEDIUM', + ); + + $this->NVP = array_merge($this->NVP, $defaults); + } + + + /** + * @uses Sets the Environment of the transaction. + * @access Public + * @param String $environment - Available values: ('test', 'live'). + * @example $PayFlow->setEnvironment('test'); + */ + public function setEnvironment($environment = 'test') { + if(strtolower($environment) == 'test') { + $this->environment = $this->gatewayURL['test']; + } + else { + $this->environment = $this->gatewayURL['live']; + } + } + + + /** + * @uses Returns the Environment of the transaction. + * @access Public + * @param None. + * @return String - The environment set. + * @example $PayFlow->getEnvironment(); + */ + public function getEnvironment() { + return $this->environment; + } + + + /** + * @uses Sets the type of transaction. + * @access Public + * @param String $transactionType - Available values: S = Sale transaction, R = Recurring, C = Credit, A = Authorization, D = Delayed Capture, V = Void, F = Voice Authorization, I = Inquiry, N = Duplicate transaction + * @example $PayFlow->setTransactionType('S'); + */ + public function setTransactionType($transactionType = 'S') { + $type = array( + 'TRXTYPE'=>strtoupper($transactionType), + ); + + $this->NVP = array_merge($this->NVP, $type); + } + + + /** + * @uses Sets the Payment Method. + * @access Public + * @param String $paymentMethod - Available values: A = Automated clearinghouse, C = Credit card, D = Pinless debit, K = Telecheck, P = PayPal. + * @example $PayFlow->setPaymentMethod('C'); + */ + public function setPaymentMethod($paymentMethod = 'C') { + $method = array( + 'TENDER'=>strtoupper($paymentMethod), + ); + + $this->NVP = array_merge($this->NVP, $method); + } + + + /** + * @uses Sets the Payment Currency. + * @access Public + * @param String $paymentCurrency - Available values: 'USD', 'EUR', 'GBP', 'CAD', 'JPY', 'AUD'. + * @example $PayFlow->setPaymentCurrency('USD'); + */ + public function setPaymentCurrency($paymentCurrency = 'USD') { + $currency = array( + 'CURRENCY'=>strtoupper($paymentCurrency), + ); + + $this->NVP = array_merge($this->NVP, $currency); + } + + + /** + * @uses Sets the Profile Action for recurring payments. + * @access Public + * @param String $profileAction - Available values: A = Add, M = Modify, R = Reactivate, C = Cancel, I = Inquiry, P = Payment. + * @example $PayFlow->setProfileAction('A'); + */ + public function setProfileAction($profileAction = 'A') { + $action = array( + 'ACTION'=>strtoupper($profileAction), + ); + + $this->NVP = array_merge($this->NVP, $action); + } + + + /** + * @uses Sets the Profile name for recurring payments. + * @access Public + * @param String $profileName - Non-unique Name for the profile (user-specified). Can be used to search for a profile. + * @example $PayFlow->setProfileName('RegularSubscription'); + */ + public function setProfileName($profileName = 'RecurringTransaction') { + $name = array( + 'PROFILENAME'=>strtoupper($profileName), + ); + + $this->NVP = array_merge($this->NVP, $name); + } + + + /** + * @uses Sets the Profile Start Date for recurring payments. + * @access Public + * @param String $profileStartDate - Beginning date for the recurring billing cycle used to calculate when payments should be made. Use tomorrow's date or a date in the future. Format: MMDDYYYY. + * @example $PayFlow->setProfileStartDate('01072011'); + */ + public function setProfileStartDate($profileStartDate = '') { + if($profileStartDate == '') { + $profileStartDate = date('mdY', strtotime("+1 day"));; + } + $date = array( + 'START'=>strtoupper($profileStartDate), + ); + + $this->NVP = array_merge($this->NVP, $date); + } + + + /** + * @uses Sets the Profile Pay Period for recurring payments. + * @access Public + * @param String $profilePayPeriod - Specifies how often the payment occurs. Available values: including all capital letters. + * WEEK: Weekly - Every week on the same day of the week as the first payment. + * BIWK: Every Two Weeks - Every other week on the same day of the week as the first payment. + * SMMO: Twice Every Month - The 1st and 15th of the month. Results in 24 payments per year. SMMO can start on 1st to 15th of the month, second payment 15 days later or on the last day of the month. + * FRWK: Every Four Weeks - Every 28 days from the previous payment date beginning with the first payment date. Results in 13 payments per year. + * MONT: Monthly - Every month on the same date as the first payment. Results in 12 payments per year. + * QTER: Quarterly - Every three months on the same date as the first payment. + * SMYR: Twice Every Year - Every six months on the same date as the first payment. + * YEAR: Yearly - Every 12 months on the same date as the first payment. + * @example $PayFlow->setProfileStartDate('MONT'); + */ + public function setProfilePayPeriod($profilePayPeriod = 'MONT') { + $period = array( + 'PAYPERIOD'=>strtoupper($profilePayPeriod), + ); + + $this->NVP = array_merge($this->NVP, $period); + } + + + /** + * @uses Sets the Profile Term for recurring payments. + * @access Public + * @param String|int $profileTerm - Number of payments to be made over the life of the agreement. A value of 0 means that payments should continue until the profile is deactivated. + * @example $PayFlow->setProfileTerm(0); + */ + public function setProfileTerm($profileTerm = 0) { + $term = array( + 'TERM'=>strtoupper($profileTerm), + ); + + $this->NVP = array_merge($this->NVP, $term); + } + + + /** + * @uses Sets the Amount of the transaction. Up to 15 digits with a decimal point (no dollar symbol) + * @access Public + * @param string|int|float $amount - 150.00. + * @param Boolean - $wholeAmt - True to remove decimal valuesfalse, to keep it. + * @example $PayFlow->setAmount(150.00); + */ + public function setAmount($amount = 0, $wholeAmt) { + $amt = array( + 'AMT'=>$this->cleanAmt($amount, $wholeAmt), + ); + + $this->NVP = array_merge($this->NVP, $amt); + } + + + /** + * @uses Sets the Customer's Credit Card Number. Between 13 and 16 digits without spaces. + * @access Public + * @param String $number - The Credit Card Number. Dashes will be striped. + * @example $PayFlow->setCCNumber('1234-1234-1234-1234'); + */ + public function setCCNumber($number = '') { + $cc = array( + 'ACCT'=>$this->cleanCCNumber($number), + ); + + $this->NVP = array_merge($this->NVP, $cc); + } + + + /** + * @uses Sets the Customer's Credit Card Expiration Date. MMYY + * @access Public + * @param String $expiration - The Customer's Credit Card Expiration Date + * @example $PayFlow->setExpiration('0312'); + */ + public function setExpiration($expiration = '0000') { + $exp = array( + 'EXPDATE'=>$this->cleanExpDate($expiration), + ); + + $this->NVP = array_merge($this->NVP, $exp); + } + + + /** + * @uses Sets the Customer's card code. The three- or four-digit number on the back of a credit card (on the front for American Express). + * @access Public + * @param String $cvv - The Customer's Credit Card Security Code + * @example $PayFlow->setCVV('0000'); + */ + public function setCVV($cvv = '') { + $security = array( + 'CVV2'=>$cvv, + ); + + $this->NVP = array_merge($this->NVP, $security); + } + + + /** + * @uses Sets the Customer's Credit Card Name. Up to 50 characters + * @access Public + * @param String $cardName - The First Name associated with the Customer's Billing Address. + * @example $PayFlow->setCreditCardName('Richard'); + */ + public function setCreditCardName($cardName = '') { + $name = array( + 'NAME'=>$this->truncateChars($cardName, 50), + ); + + $this->NVP = array_merge($this->NVP, $name); + } + + + /** + * @uses Sets the First Name associated with the Customer's Billing Address. Up to 30 characters (no symbols) + * @access Public + * @param String $firstName - The First Name associated with the Customer's Billing Address. + * @example $PayFlow->setCustomerFirstName('Richard'); + */ + public function setCustomerFirstName($firstName = '') { + $first = array( + 'FIRSTNAME'=>$this->truncateChars($firstName, 30), + ); + + $this->NVP = array_merge($this->NVP, $first); + } + + + /** + * @uses Sets the Last Name associated with the Customer's Billing Address. Up to 30 characters (no symbols) + * @access Public + * @param String $lastName - The Last Name associated with the Customer's Billing Address. + * @example $PayFlow->setCustomerLastName('Castera'); + */ + public function setCustomerLastName($lastName = '') { + $last = array( + 'LASTNAME'=>$this->truncateChars($lastName, 30), + ); + + $this->NVP = array_merge($this->NVP, $last); + } + + + /** + * @uses Sets the Customer's Billing address. Up to 30 characters (no symbols) + * @access Public + * @param String $customerAddress - The Customer's Billing address. + * @example $PayFlow->setCustomerAddress('589 8th Ave. Suite 10'); + */ + public function setCustomerAddress($customerAddress = '') { + $address = array( + 'STREET'=>$this->truncateChars($customerAddress, 30), + ); + + $this->NVP = array_merge($this->NVP, $address); + } + + + /** + * @uses Sets the Customer's Billing City. Up to 20 characters (no symbols) + * @access Public + * @param String $customerCity - The Customer's Billing City. + * @example $PayFlow->setCustomerCity('New York'); + */ + public function setCustomerCity($customerCity = '') { + $city = array( + 'CITY'=>$this->truncateChars($customerCity, 20), + ); + + $this->NVP = array_merge($this->NVP, $city); + } + + + /** + * @uses Sets the Customer's Billing State. Up to 2 characters (no symbols) a valid two-character state code. + * @access Public + * @param String $customerState - The Customer's Billing State. + * @example $PayFlow->setCustomerState('NY'); + */ + public function setCustomerState($customerState = '') { + $state = array( + 'STATE'=>$this->truncateChars($customerState, 2), + ); + + $this->NVP = array_merge($this->NVP, $state); + } + + + /** + * @uses Sets the Customer's Billing Zip. Up to 9 characters (no symbols). + * @access Public + * @param String $customerZip - The Customer's Billing Zip. + * @example $PayFlow->setCustomerZip('10018'); + */ + public function setCustomerZip($customerZip = '') { + $zip = array( + 'ZIP'=>$this->truncateChars($customerZip, 9), + ); + + $this->NVP = array_merge($this->NVP, $zip); + } + + + /** + * @uses Sets the Customer's Billing Country. Up to 4 characters (no symbols). + * @access Public + * @param String $customerCountry - The Customer's Billing Country. + * @example $PayFlow->setCustomerCountry('US'); + */ + public function setCustomerCountry($customerCountry = '') { + $country = array( + 'COUNTRY'=>$this->truncateChars($customerCountry, 4), + ); + + $this->NVP = array_merge($this->NVP, $country); + } + + + /** + * @uses Sets the Customer's Billing Phone. Up to 20 digits (no letters) Ex. 123-123-1234 - Dashes will be stripped. + * @access Public + * @param String $customerPhone - The Customer's Billing Phone. + * @example $PayFlow->setCustomerPhone('212-123-4567'); + */ + public function setCustomerPhone($customerPhone = '000-000-0000') { + $phone = array( + 'PHONENUM'=>$this->truncateChars($this->cleanPhoneNumber($customerPhone), 20), + ); + + $this->NVP = array_merge($this->NVP, $phone); + } + + + /** + * @uses Sets the Customer's Email Address. Up to 60 characters. + * @access Public + * @param String $customerEmail - The Customer's Email Address. + * @example $PayFlow->setCustomerEmail('richard.castera@gmail.com'); + */ + public function setCustomerEmail($customerEmail = '') { + $email = array( + 'EMAIl'=>$this->truncateChars($customerEmail, 60), + ); + + $this->NVP = array_merge($this->NVP, $email); + } + + + /** + * @uses Sets the Payment Description. This is just a commment regarding the transaction for your reference. + * @access Public + * @param String $description - The Payment description. + * @example $PayFlow->setPaymentComment('Purchased product number 34324'); + */ + public function setPaymentComment($description = '') { + $desc = array( + 'COMMENT1'=>$this->truncateChars($description, 128), + ); + + $this->NVP = array_merge($this->NVP, $desc); + } + + + /** + * @uses Sets the Payment Description. This is just a commment regarding the transaction for your reference. + * @access Public + * @param String $description - The Payment description. + * @example $PayFlow->setPaymentComment2('Purchased product number 34324'); + */ + public function setPaymentComment2($description = '') { + $desc = array( + 'COMMENT2'=>$this->truncateChars($description, 128), + ); + + $this->NVP = array_merge($this->NVP, $desc); + } + + + /** + * @uses Sets a Merchant-defined field to submit to Paypal. + * @access Public + * @param String $name - The name of the custom field. + * @param String $value - The value of the custom field. + * @example $PayFlow->setCustomField('KEY', 'VALUE'); + */ + public function setCustomField($name = '', $value = '') { + $custom = array( + $name=>(string)$value, + ); + + $this->NVP = array_merge($this->NVP, $custom); + } + + + /** + * @uses This get the NVP's that will be sent to Paypal. + * @access Private + * @param None. + * @return String - A string of NVP's. + * @example $this->getNVP(); + */ + private function getNVP() { + $post = ''; + foreach($this->NVP as $key=>$value) { + $post .= "$key=" . $value . "&"; + } + return (string)rtrim($post, "& "); + } + + + /** + * @uses Sends the request to Paypal for processing. + * @access Public + * @param None. + * @return Boolean - True if the transaction was successful False, if not. + * @example $PayFlow->processTransaction(); + */ + public function processTransaction() { + // Uses the CURL library for php to establish a connection, + // submit the post, and record the response. + if(function_exists('curl_init') && extension_loaded('curl')) { + $request = curl_init($this->getEnvironment()); // Initiate curl object + curl_setopt($request, CURLOPT_HTTPHEADER, $this->getHeaders($this->NVP)); + curl_setopt($request, CURLOPT_HEADER, 1); // Set to 0 to eliminate header info from response + curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1) + curl_setopt($request, CURLOPT_TIMEOUT, 45); // times out after 45 secs + curl_setopt($request, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done + curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // Uncomment this line if you get no gateway response. + curl_setopt($request, CURLOPT_POST, 1); //data sent as POST + curl_setopt($request, CURLOPT_POSTFIELDS, $this->getNVP()); // Use HTTP POST to send the data + $postResponse = curl_exec($request); // Execute curl post and store results in $post_response + + // Additional options may be required depending upon your server configuration + // you can find documentation on curl options at http://www.php.net|curl_setopt + curl_close($request); // close curl object + + // Get the response. + $this->response = $postResponse; + + $this->response = $this->parseResults($this->response); + + if(isset($this->response['RESULT']) && $this->response['RESULT'] == 0) { + return TRUE; + } + else { + return FALSE; + } + } + else { + return FALSE; + } + } + + + /** + * @uses Generates the headers we need to send to Payflow. + * @access Private + * @param array - $params - The NVP value pairs. + * @return array - Header information for cURL. + * @example $this->getHeaders($params); + */ + private function getHeaders($params){ + $headers[] = "Content-Type: text/namevalue"; + $headers[] = "X-VPS-Timeout: 30"; + $headers[] = "X-VPS-VIT-Client-Certification-Id: 33baf5893fc2123d8b191d2d011b7fdc"; // This header requirement will be removed + $headers[] = "X-VPS-Request-ID: " . $this->getRequestId($params); + return $headers; + } + + + /** + * @uses Generates a unique request id with the credit card number, amount, and timestamp. + * @access Private + * @param array - $params - The NVP value pairs. + * @return String - Unique id. + * @example $this->getRequestId($params); + */ + private function getRequestId($params){ + if(isset($params['ACCT'])) { + $requestId = md5($params['ACCT'] . $params['AMT'] . date('YmdGis') . "1"); + return $requestId; + } + else { + return md5(time()); + } + } + + + /** + * @uses Gets the response from Paypal. + * @access Public + * @param None. + * @return array|String - Returns an array of Paypal's response or empty string if not return. + * @example $PayFlow->getResponse(); + */ + public function getResponse() { + if($this->response) { + return $this->response; + } + else { + return ''; + } + } + + + /** + * @uses Parses the response from Paypal. + * @access Private + * @param array - $result - The NVP result from the transaction. + * @return array|String - Returns an array of Paypal's response or empty string if not return. + * @example $PayFlow->getResponse(); + */ + private function parseResults($result) { + if(empty($result)) { + return ''; + } + + $response = array(); + $result = strstr($result, 'RESULT'); + $value = explode('&', $result); + foreach($value as $token) { + $key = explode('=', $token); + $response[$key[0]] = $key[1]; + } + return $response; + } + + + /** + * @uses Formats the monetary amount sent to Paypal. + * @access Private + * @param String|Integer|Float $amount - The amount to clean. + * @param Boolean $wholeAmt - True to remove cents false, to keep it. + * @return Integer|Float - Returns the monetary amount formatted based on the $wholeAmt parameter. + * @example $this->cleanAmt(); + */ + private function cleanAmt($amount = 0, $wholeAmt = FALSE) { + if($wholeAmt) { + $amount = preg_replace('/[^0-9.]/', '', trim($amount)); + return (int)$amount; + } + else { + $amount = preg_replace('/[^0-9.]/', '', trim($amount)); + return (float)$amount; + } + } + + + /** + * @uses Removes all characters from the credit card number except for numbers. + * @access Private + * @param String $cc - The crdeit card number. + * @return String - Returns the credit card number with only numeric characters. + * @example $this->cleanCCNumber('5412-2232-2323-3443'); + */ + private function cleanCCNumber($cc = '') { + $cc = preg_replace('/[^0-9]/', '', trim($cc)); + return (string)$cc; + } + + + /** + * @uses Removes all characters from the telephone number except for numbers and dashes. + * @access Private + * @param String $phone - The phone number. + * @return String - Returns the phone number with dashes. + * @example $this->cleanPhoneNumber('718-232-2323'); + */ + private function cleanPhoneNumber($phone = '') { + $phone = preg_replace('/[^0-9]/', '', trim($phone)); + return (string)$phone; + } + + + /** + * @uses Removes all characters from the Expiration date except for numbers, slashes and dashes. + * @access Private + * @param String $exp - The expiration date. + * @return String - Returns the expiration date formatted for Paypal. + * @example $this->cleanExpDate('05|10'); + */ + private function cleanExpDate($exp = '') { + $exp = preg_replace('/[^0-9]/', '', trim($exp)); + return (string)$exp; + } + + + /** + * @uses Used to truncate values. + * @access Private + * @param String $string - The string to truncate. + * @param Integer $limit - The amount to truncate. + * @return string Returns the string truncated. + * @example $this->truncateChars('Richard Castera', 10); + */ + private function truncateChars($string = '', $limit = 0) { + $output = ''; + for($i = 0; $i <= $limit AND $i < strlen($string); $i++){ + $output .= $string[$i]; + } + return (string)trim($output); + } + + + /** + * @uses Used to debug values that will be sent to Paypal. + * @access Public + * @param String $type - Valid values are 'array' or 'string'. + * @return string|array This returns either and array of the NVP's or a string based on the parameter chosen. + * @example $PayFlow->debugNVP('array'); + */ + public function debugNVP($type = 'array') { + if($type == 'array') { + return $this->NVP; + } + else { + return $this->getNVP(); + } + } } -?> \ No newline at end of file From efc9dbd8badb6b370479e491a3e7a81108860f98 Mon Sep 17 00:00:00 2001 From: nwech Date: Thu, 2 Mar 2017 16:16:41 -0600 Subject: [PATCH 2/5] Use substr(). No need to reinvent the wheel --- Class.PayFlow.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Class.PayFlow.php b/Class.PayFlow.php index 7ff15d2..373c6b8 100644 --- a/Class.PayFlow.php +++ b/Class.PayFlow.php @@ -763,11 +763,7 @@ private function cleanExpDate($exp = '') { * @example $this->truncateChars('Richard Castera', 10); */ private function truncateChars($string = '', $limit = 0) { - $output = ''; - for($i = 0; $i <= $limit AND $i < strlen($string); $i++){ - $output .= $string[$i]; - } - return (string)trim($output); + return (string)trim(substr($string, 0, $limit)); } From 3f80b6050b3b9b5f46370e0bbaf01db443d7276e Mon Sep 17 00:00:00 2001 From: nwech Date: Thu, 2 Mar 2017 16:18:09 -0600 Subject: [PATCH 3/5] Trim before truncating --- Class.PayFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Class.PayFlow.php b/Class.PayFlow.php index 373c6b8..e429a22 100644 --- a/Class.PayFlow.php +++ b/Class.PayFlow.php @@ -763,7 +763,7 @@ private function cleanExpDate($exp = '') { * @example $this->truncateChars('Richard Castera', 10); */ private function truncateChars($string = '', $limit = 0) { - return (string)trim(substr($string, 0, $limit)); + return (string )substr(trim($string), 0, $limit); } From 221e196e1445bad1cb992ce2a2e8656cf47ebc1f Mon Sep 17 00:00:00 2001 From: nwech Date: Thu, 2 Mar 2017 16:24:18 -0600 Subject: [PATCH 4/5] Clean up the phpdoc a bit --- Class.PayFlow.php | 112 ++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 59 deletions(-) diff --git a/Class.PayFlow.php b/Class.PayFlow.php index e429a22..30351ca 100644 --- a/Class.PayFlow.php +++ b/Class.PayFlow.php @@ -1,6 +1,6 @@ setupDefaults(); */ private function setupDefaults() { @@ -146,7 +144,7 @@ private function setupDefaults() { /** - * @uses Sets the Environment of the transaction. + * Sets the Environment of the transaction. * @access Public * @param String $environment - Available values: ('test', 'live'). * @example $PayFlow->setEnvironment('test'); @@ -162,9 +160,8 @@ public function setEnvironment($environment = 'test') { /** - * @uses Returns the Environment of the transaction. + * Returns the Environment of the transaction. * @access Public - * @param None. * @return String - The environment set. * @example $PayFlow->getEnvironment(); */ @@ -174,7 +171,7 @@ public function getEnvironment() { /** - * @uses Sets the type of transaction. + * Sets the type of transaction. * @access Public * @param String $transactionType - Available values: S = Sale transaction, R = Recurring, C = Credit, A = Authorization, D = Delayed Capture, V = Void, F = Voice Authorization, I = Inquiry, N = Duplicate transaction * @example $PayFlow->setTransactionType('S'); @@ -189,7 +186,7 @@ public function setTransactionType($transactionType = 'S') { /** - * @uses Sets the Payment Method. + * Sets the Payment Method. * @access Public * @param String $paymentMethod - Available values: A = Automated clearinghouse, C = Credit card, D = Pinless debit, K = Telecheck, P = PayPal. * @example $PayFlow->setPaymentMethod('C'); @@ -204,7 +201,7 @@ public function setPaymentMethod($paymentMethod = 'C') { /** - * @uses Sets the Payment Currency. + * Sets the Payment Currency. * @access Public * @param String $paymentCurrency - Available values: 'USD', 'EUR', 'GBP', 'CAD', 'JPY', 'AUD'. * @example $PayFlow->setPaymentCurrency('USD'); @@ -219,7 +216,7 @@ public function setPaymentCurrency($paymentCurrency = 'USD') { /** - * @uses Sets the Profile Action for recurring payments. + * Sets the Profile Action for recurring payments. * @access Public * @param String $profileAction - Available values: A = Add, M = Modify, R = Reactivate, C = Cancel, I = Inquiry, P = Payment. * @example $PayFlow->setProfileAction('A'); @@ -234,7 +231,7 @@ public function setProfileAction($profileAction = 'A') { /** - * @uses Sets the Profile name for recurring payments. + * Sets the Profile name for recurring payments. * @access Public * @param String $profileName - Non-unique Name for the profile (user-specified). Can be used to search for a profile. * @example $PayFlow->setProfileName('RegularSubscription'); @@ -249,7 +246,7 @@ public function setProfileName($profileName = 'RecurringTransaction') { /** - * @uses Sets the Profile Start Date for recurring payments. + * Sets the Profile Start Date for recurring payments. * @access Public * @param String $profileStartDate - Beginning date for the recurring billing cycle used to calculate when payments should be made. Use tomorrow's date or a date in the future. Format: MMDDYYYY. * @example $PayFlow->setProfileStartDate('01072011'); @@ -267,7 +264,7 @@ public function setProfileStartDate($profileStartDate = '') { /** - * @uses Sets the Profile Pay Period for recurring payments. + * Sets the Profile Pay Period for recurring payments. * @access Public * @param String $profilePayPeriod - Specifies how often the payment occurs. Available values: including all capital letters. * WEEK: Weekly - Every week on the same day of the week as the first payment. @@ -290,7 +287,7 @@ public function setProfilePayPeriod($profilePayPeriod = 'MONT') { /** - * @uses Sets the Profile Term for recurring payments. + * Sets the Profile Term for recurring payments. * @access Public * @param String|int $profileTerm - Number of payments to be made over the life of the agreement. A value of 0 means that payments should continue until the profile is deactivated. * @example $PayFlow->setProfileTerm(0); @@ -305,7 +302,7 @@ public function setProfileTerm($profileTerm = 0) { /** - * @uses Sets the Amount of the transaction. Up to 15 digits with a decimal point (no dollar symbol) + * Sets the Amount of the transaction. Up to 15 digits with a decimal point (no dollar symbol) * @access Public * @param string|int|float $amount - 150.00. * @param Boolean - $wholeAmt - True to remove decimal valuesfalse, to keep it. @@ -321,7 +318,7 @@ public function setAmount($amount = 0, $wholeAmt) { /** - * @uses Sets the Customer's Credit Card Number. Between 13 and 16 digits without spaces. + * Sets the Customer's Credit Card Number. Between 13 and 16 digits without spaces. * @access Public * @param String $number - The Credit Card Number. Dashes will be striped. * @example $PayFlow->setCCNumber('1234-1234-1234-1234'); @@ -336,7 +333,7 @@ public function setCCNumber($number = '') { /** - * @uses Sets the Customer's Credit Card Expiration Date. MMYY + * Sets the Customer's Credit Card Expiration Date. MMYY * @access Public * @param String $expiration - The Customer's Credit Card Expiration Date * @example $PayFlow->setExpiration('0312'); @@ -351,7 +348,7 @@ public function setExpiration($expiration = '0000') { /** - * @uses Sets the Customer's card code. The three- or four-digit number on the back of a credit card (on the front for American Express). + * Sets the Customer's card code. The three- or four-digit number on the back of a credit card (on the front for American Express). * @access Public * @param String $cvv - The Customer's Credit Card Security Code * @example $PayFlow->setCVV('0000'); @@ -366,7 +363,7 @@ public function setCVV($cvv = '') { /** - * @uses Sets the Customer's Credit Card Name. Up to 50 characters + * Sets the Customer's Credit Card Name. Up to 50 characters * @access Public * @param String $cardName - The First Name associated with the Customer's Billing Address. * @example $PayFlow->setCreditCardName('Richard'); @@ -381,7 +378,7 @@ public function setCreditCardName($cardName = '') { /** - * @uses Sets the First Name associated with the Customer's Billing Address. Up to 30 characters (no symbols) + * Sets the First Name associated with the Customer's Billing Address. Up to 30 characters (no symbols) * @access Public * @param String $firstName - The First Name associated with the Customer's Billing Address. * @example $PayFlow->setCustomerFirstName('Richard'); @@ -396,7 +393,7 @@ public function setCustomerFirstName($firstName = '') { /** - * @uses Sets the Last Name associated with the Customer's Billing Address. Up to 30 characters (no symbols) + * Sets the Last Name associated with the Customer's Billing Address. Up to 30 characters (no symbols) * @access Public * @param String $lastName - The Last Name associated with the Customer's Billing Address. * @example $PayFlow->setCustomerLastName('Castera'); @@ -411,7 +408,7 @@ public function setCustomerLastName($lastName = '') { /** - * @uses Sets the Customer's Billing address. Up to 30 characters (no symbols) + * Sets the Customer's Billing address. Up to 30 characters (no symbols) * @access Public * @param String $customerAddress - The Customer's Billing address. * @example $PayFlow->setCustomerAddress('589 8th Ave. Suite 10'); @@ -426,7 +423,7 @@ public function setCustomerAddress($customerAddress = '') { /** - * @uses Sets the Customer's Billing City. Up to 20 characters (no symbols) + * Sets the Customer's Billing City. Up to 20 characters (no symbols) * @access Public * @param String $customerCity - The Customer's Billing City. * @example $PayFlow->setCustomerCity('New York'); @@ -441,7 +438,7 @@ public function setCustomerCity($customerCity = '') { /** - * @uses Sets the Customer's Billing State. Up to 2 characters (no symbols) a valid two-character state code. + * Sets the Customer's Billing State. Up to 2 characters (no symbols) a valid two-character state code. * @access Public * @param String $customerState - The Customer's Billing State. * @example $PayFlow->setCustomerState('NY'); @@ -456,7 +453,7 @@ public function setCustomerState($customerState = '') { /** - * @uses Sets the Customer's Billing Zip. Up to 9 characters (no symbols). + * Sets the Customer's Billing Zip. Up to 9 characters (no symbols). * @access Public * @param String $customerZip - The Customer's Billing Zip. * @example $PayFlow->setCustomerZip('10018'); @@ -471,7 +468,7 @@ public function setCustomerZip($customerZip = '') { /** - * @uses Sets the Customer's Billing Country. Up to 4 characters (no symbols). + * Sets the Customer's Billing Country. Up to 4 characters (no symbols). * @access Public * @param String $customerCountry - The Customer's Billing Country. * @example $PayFlow->setCustomerCountry('US'); @@ -486,7 +483,7 @@ public function setCustomerCountry($customerCountry = '') { /** - * @uses Sets the Customer's Billing Phone. Up to 20 digits (no letters) Ex. 123-123-1234 - Dashes will be stripped. + * Sets the Customer's Billing Phone. Up to 20 digits (no letters) Ex. 123-123-1234 - Dashes will be stripped. * @access Public * @param String $customerPhone - The Customer's Billing Phone. * @example $PayFlow->setCustomerPhone('212-123-4567'); @@ -501,7 +498,7 @@ public function setCustomerPhone($customerPhone = '000-000-0000') { /** - * @uses Sets the Customer's Email Address. Up to 60 characters. + * Sets the Customer's Email Address. Up to 60 characters. * @access Public * @param String $customerEmail - The Customer's Email Address. * @example $PayFlow->setCustomerEmail('richard.castera@gmail.com'); @@ -516,7 +513,7 @@ public function setCustomerEmail($customerEmail = '') { /** - * @uses Sets the Payment Description. This is just a commment regarding the transaction for your reference. + * Sets the Payment Description. This is just a commment regarding the transaction for your reference. * @access Public * @param String $description - The Payment description. * @example $PayFlow->setPaymentComment('Purchased product number 34324'); @@ -531,7 +528,7 @@ public function setPaymentComment($description = '') { /** - * @uses Sets the Payment Description. This is just a commment regarding the transaction for your reference. + * Sets the Payment Description. This is just a commment regarding the transaction for your reference. * @access Public * @param String $description - The Payment description. * @example $PayFlow->setPaymentComment2('Purchased product number 34324'); @@ -546,7 +543,7 @@ public function setPaymentComment2($description = '') { /** - * @uses Sets a Merchant-defined field to submit to Paypal. + * Sets a Merchant-defined field to submit to Paypal. * @access Public * @param String $name - The name of the custom field. * @param String $value - The value of the custom field. @@ -562,9 +559,8 @@ public function setCustomField($name = '', $value = '') { /** - * @uses This get the NVP's that will be sent to Paypal. + * This get the NVP's that will be sent to Paypal. * @access Private - * @param None. * @return String - A string of NVP's. * @example $this->getNVP(); */ @@ -578,9 +574,8 @@ private function getNVP() { /** - * @uses Sends the request to Paypal for processing. + * Sends the request to Paypal for processing. * @access Public - * @param None. * @return Boolean - True if the transaction was successful False, if not. * @example $PayFlow->processTransaction(); */ @@ -622,7 +617,7 @@ public function processTransaction() { /** - * @uses Generates the headers we need to send to Payflow. + * Generates the headers we need to send to Payflow. * @access Private * @param array - $params - The NVP value pairs. * @return array - Header information for cURL. @@ -638,7 +633,7 @@ private function getHeaders($params){ /** - * @uses Generates a unique request id with the credit card number, amount, and timestamp. + * Generates a unique request id with the credit card number, amount, and timestamp. * @access Private * @param array - $params - The NVP value pairs. * @return String - Unique id. @@ -656,9 +651,8 @@ private function getRequestId($params){ /** - * @uses Gets the response from Paypal. + * Gets the response from Paypal. * @access Public - * @param None. * @return array|String - Returns an array of Paypal's response or empty string if not return. * @example $PayFlow->getResponse(); */ @@ -673,7 +667,7 @@ public function getResponse() { /** - * @uses Parses the response from Paypal. + * Parses the response from Paypal. * @access Private * @param array - $result - The NVP result from the transaction. * @return array|String - Returns an array of Paypal's response or empty string if not return. @@ -696,7 +690,7 @@ private function parseResults($result) { /** - * @uses Formats the monetary amount sent to Paypal. + * Formats the monetary amount sent to Paypal. * @access Private * @param String|Integer|Float $amount - The amount to clean. * @param Boolean $wholeAmt - True to remove cents false, to keep it. @@ -716,7 +710,7 @@ private function cleanAmt($amount = 0, $wholeAmt = FALSE) { /** - * @uses Removes all characters from the credit card number except for numbers. + * Removes all characters from the credit card number except for numbers. * @access Private * @param String $cc - The crdeit card number. * @return String - Returns the credit card number with only numeric characters. @@ -729,7 +723,7 @@ private function cleanCCNumber($cc = '') { /** - * @uses Removes all characters from the telephone number except for numbers and dashes. + * Removes all characters from the telephone number except for numbers and dashes. * @access Private * @param String $phone - The phone number. * @return String - Returns the phone number with dashes. @@ -742,7 +736,7 @@ private function cleanPhoneNumber($phone = '') { /** - * @uses Removes all characters from the Expiration date except for numbers, slashes and dashes. + * Removes all characters from the Expiration date except for numbers, slashes and dashes. * @access Private * @param String $exp - The expiration date. * @return String - Returns the expiration date formatted for Paypal. @@ -755,7 +749,7 @@ private function cleanExpDate($exp = '') { /** - * @uses Used to truncate values. + * Used to truncate values. * @access Private * @param String $string - The string to truncate. * @param Integer $limit - The amount to truncate. @@ -763,12 +757,12 @@ private function cleanExpDate($exp = '') { * @example $this->truncateChars('Richard Castera', 10); */ private function truncateChars($string = '', $limit = 0) { - return (string )substr(trim($string), 0, $limit); + return (string) substr(trim($string), 0, $limit); } /** - * @uses Used to debug values that will be sent to Paypal. + * Used to debug values that will be sent to Paypal. * @access Public * @param String $type - Valid values are 'array' or 'string'. * @return string|array This returns either and array of the NVP's or a string based on the parameter chosen. From 9949084f0348486c377c97bf1b9aaae3a6186a74 Mon Sep 17 00:00:00 2001 From: nwech Date: Thu, 2 Mar 2017 16:36:30 -0600 Subject: [PATCH 5/5] Trim before and after truncating --- Class.PayFlow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Class.PayFlow.php b/Class.PayFlow.php index 30351ca..74e8e97 100644 --- a/Class.PayFlow.php +++ b/Class.PayFlow.php @@ -757,7 +757,7 @@ private function cleanExpDate($exp = '') { * @example $this->truncateChars('Richard Castera', 10); */ private function truncateChars($string = '', $limit = 0) { - return (string) substr(trim($string), 0, $limit); + return trim(substr(trim($string), 0, $limit)); }