Payment_Process
[ class tree: Payment_Process ] [ index: Payment_Process ] [ all elements ]

Source for file LinkPoint.php

Documentation is available at LinkPoint.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Joe Stump <joe@joestump.net>                                |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: LinkPoint.php,v 1.11 2005/08/11 00:18:52 jstump Exp $
  20.  
  21. require_once('Payment/Process.php');
  22. require_once('Payment/Process/Common.php');
  23. require_once('Net/Curl.php');
  24. require_once('XML/Parser.php');
  25.  
  26. $GLOBALS['_Payment_Process_LinkPoint'= array(
  27.     PAYMENT_PROCESS_ACTION_NORMAL   => 'SALE',
  28.     PAYMENT_PROCESS_ACTION_AUTHONLY => 'PREAUTH',
  29.     PAYMENT_PROCESS_ACTION_POSTAUTH => 'POSTAUTH'
  30. );
  31.  
  32. /**
  33.  * Payment_Process_LinkPoint
  34.  *
  35.  * This is a processor for LinkPoint's merchant payment gateway.
  36.  * (http://www.linkpoint.net/)
  37.  *
  38.  * *** WARNING ***
  39.  * This is BETA code, and has not been fully tested. It is not recommended
  40.  * that you use it in a production envorinment without further testing.
  41.  *
  42.  * @package Payment_Process
  43.  * @author Joe Stump <joe@joestump.net>
  44.  * @version @version@
  45.  */
  46. class Payment_Process_LinkPoint extends Payment_Process_Common
  47. {
  48.     /**
  49.      * Front-end -> back-end field map.
  50.      *
  51.      * This array contains the mapping from front-end fields (defined in
  52.      * the Payment_Process class) to the field names DPILink requires.
  53.      *
  54.      * @see _prepare()
  55.      * @access private
  56.      */
  57.     var $_fieldMap = array(
  58.         // Required
  59.         'login'         => 'configfile',
  60.         'action'        => 'ordertype',
  61.         'invoiceNumber' => 'oid',
  62.         'customerId'    => 'x_cust_id',
  63.         'amount'        => 'chargetotal',
  64.         'name'          => '',
  65.         'zip'           => 'zip',
  66.         // Optional
  67.         'company'       => 'company',
  68.         'address'       => 'address1',
  69.         'city'          => 'city',
  70.         'state'         => 'state',
  71.         'country'       => 'country',
  72.         'phone'         => 'phone',
  73.         'email'         => 'email',
  74.         'ip'            => 'ip',
  75.     );
  76.  
  77.     /**
  78.     * $_typeFieldMap
  79.     *
  80.     * @author Joe Stump <joe@joestump.net>
  81.     * @access protected
  82.     */
  83.     var $_typeFieldMap = array(
  84.  
  85.            'CreditCard' => array(
  86.  
  87.                     'cardNumber' => 'cardnumber',
  88.                     'cvv'        => 'cvm',
  89.                     'expDate'    => 'expDate'
  90.  
  91.            ),
  92.  
  93.            'eCheck' => array(
  94.  
  95.                     'routingCode'   => 'routing',
  96.                     'accountNumber' => 'account',
  97.                     'type'          => 'type',
  98.                     'bankName'      => 'bank',
  99.                     'name'          => 'name',
  100.                     'driversLicense'      => 'dl',
  101.                     'driversLicenseState' => 'dlstate'
  102.  
  103.            )
  104.     );
  105.  
  106.     /**
  107.      * Default options for this processor.
  108.      *
  109.      * @see Payment_Process::setOptions()
  110.      * @access private
  111.      */
  112.     var $_defaultOptions = array(
  113.          'host'   => 'secure.linkpt.net',
  114.          'port'   => '1129',
  115.          'result' => 'LIVE'
  116.     );
  117.  
  118.     /**
  119.      * Has the transaction been processed?
  120.      *
  121.      * @type boolean
  122.      * @access private
  123.      */
  124.     var $_processed = false;
  125.  
  126.     /**
  127.      * The response body sent back from the gateway.
  128.      *
  129.      * @access private
  130.      */
  131.     var $_responseBody '';
  132.  
  133.     /**
  134.      * Constructor.
  135.      *
  136.      * @param  array  $options  Class options to set.
  137.      * @see Payment_Process::setOptions()
  138.      * @return void 
  139.      */
  140.     function __construct($options = false)
  141.     {
  142.         parent::__construct($options);
  143.         $this->_driver 'LinkPoint';
  144.     }
  145.  
  146.     function Payment_Process_LinkPoint($options = false)
  147.     {
  148.         $this->__construct($options);
  149.     }
  150.  
  151.     /**
  152.      * Process the transaction.
  153.      *
  154.      * @return mixed Payment_Process_Result on success, PEAR_Error on failure
  155.      */
  156.     function &process()
  157.     {
  158.         if (!strlen($this->_options['keyfile']||
  159.             !file_exists($this->_options['keyfile'])) {
  160.             return PEAR::raiseError('Invalid key file');
  161.         }
  162.  
  163.         // Sanity check
  164.         $result $this->validate();
  165.         if (PEAR::isError($result)) {
  166.             return $result;
  167.         }
  168.  
  169.         // Prepare the data
  170.         $result $this->_prepare();
  171.         if (PEAR::isError($result)) {
  172.             return $result;
  173.         }
  174.  
  175.         // Don't die partway through
  176.         PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  177.  
  178.  
  179.         $xml $this->_prepareQueryString();
  180.         if (PEAR::isError($xml)) {
  181.             return $xml;
  182.         }
  183.  
  184.         $url 'https://'.$this->_options['host'].':'.$this->_options['port'].
  185.                '/LSGSXML';
  186.  
  187.         $curl new Net_Curl($url);
  188.         if (PEAR::isError($curl)) {
  189.             PEAR::popErrorHandling();
  190.             return $curl;
  191.         }
  192.  
  193.         $curl->type = 'POST';
  194.         $curl->fields = $xml;
  195.         $curl->sslCert = $this->_options['keyfile'];
  196.         $curl->userAgent = 'PEAR Payment_Process_LinkPoint 0.1';
  197.  
  198.         $result &$curl->execute();
  199.         if (PEAR::isError($result)) {
  200.             PEAR::popErrorHandling();
  201.             return $result;
  202.         else {
  203.             $curl->close();
  204.         }
  205.  
  206.  
  207.         $this->_responseBody trim($result);
  208.         $this->_processed = true;
  209.  
  210.         // Restore error handling
  211.         PEAR::popErrorHandling();
  212.  
  213.         $response &Payment_Process_Result::factory($this->_driver,
  214.                                                      $this->_responseBody,
  215.                                                      &$this);
  216.  
  217.         if (!PEAR::isError($response)) {
  218.             $response->parse();
  219.         }
  220.  
  221.         return $response;
  222.  
  223.     }
  224.  
  225.     /**
  226.      * Prepare the POST query string.
  227.      *
  228.      * @access private
  229.      * @return string The query string
  230.      */
  231.     function _prepareQueryString()
  232.     {
  233.  
  234.         $data array_merge($this->_options,$this->_data);
  235.  
  236.         $xml  '<!-- Payment_Process order -->'."\n";
  237.         $xml .= '<order>'."\n";
  238.         $xml .= '<merchantinfo>'."\n";
  239.         $xml .= '  <configfile>'.$data['configfile'].'</configfile>'."\n";
  240.         $xml .= '  <keyfile>'.$data['keyfile'].'</keyfile>'."\n";
  241.         $xml .= '  <host>'.$data['authorizeUri'].'</host>'."\n";
  242.         $xml .= '  <appname>PEAR Payment_Process</appname>'."\n";
  243.         $xml .= '</merchantinfo>'."\n";
  244.         $xml .= '<orderoptions>'."\n";
  245.         $xml .= '  <ordertype>'.$data['ordertype'].'</ordertype>'."\n";
  246.         $xml .= '  <result>'.$data['result'].'</result>'."\n";
  247.         $xml .= '</orderoptions>'."\n";
  248.         $xml .= '<payment>'."\n";
  249.         $xml .= '  <subtotal>'.$data['chargetotal'].'</subtotal>'."\n";
  250.         $xml .= '  <tax>0.00</tax>'."\n";
  251.         $xml .= '  <shipping>0.00</shipping>'."\n";
  252.         $xml .= '  <chargetotal>'.$data['chargetotal'].'</chargetotal>'."\n";
  253.         $xml .= '</payment>'."\n";
  254.  
  255.         // Set payment method to eCheck if our payment type is eCheck.
  256.         // Default is Credit Card.
  257.         $data['x_method''CC';
  258.         switch ($this->_payment->getType())
  259.         {
  260.             case 'eCheck':
  261.                 return PEAR::raiseError('eCheck not currently supported',
  262.                                         PAYMENT_PROCESS_ERROR_NOTIMPLEMENTED);
  263.  
  264.                 $xml .= '<telecheck>'."\n";
  265.                 $xml .= '  <routing></routing>'."\n";
  266.                 $xml .= '  <account></account>'."\n";
  267.                 $xml .= '  <checknumber></checknumber>'."\n";
  268.                 $xml .= '  <bankname></bankname>'."\n";
  269.                 $xml .= '  <bankstate></bankstate>'."\n";
  270.                 $xml .= '  <dl></dl>'."\n";
  271.                 $xml .= '  <dlstate></dlstate>'."\n";
  272.                 $xml .= '  <accounttype>pc|ps|bc|bs</accounttype>'."\n";
  273.                 $xml .= '<telecheck>'."\n";
  274.                 break;
  275.             case 'CreditCard':
  276.                 $xml .= '<creditcard>'."\n";
  277.                 $xml .= '  <cardnumber>'.$data['cardnumber'].'</cardnumber>'."\n";
  278.                 list($month,$yearexplode('/',$data['expDate']);
  279.                 if (strlen($year== 4{
  280.                     $year substr($year,2);
  281.                 }
  282.  
  283.                 $month sprintf('%02d',$month);
  284.  
  285.                 $xml .= '  <cardexpmonth>'.$month.'</cardexpmonth>'."\n";
  286.                 $xml .= '  <cardexpyear>'.$year.'</cardexpyear>'."\n";
  287.                 if (strlen($data['cvm'])) {
  288.                     $xml .= '  <cvmvalue>'.$data['cvm'].'</cvmvalue>'."\n";
  289.                     $xml .= '  <cvmindicator>provided</cvmindicator>'."\n";
  290.                 }
  291.                 $xml .= '</creditcard>'."\n";
  292.         }
  293.  
  294.         if (isset($this->_payment->firstName&&
  295.             isset($this->_payment->lastName)) {
  296.             $xml .= '<billing>'."\n";
  297.             $xml .= '  <userid>'.$this->_payment->customerId.'</userid>'."\n";
  298.             $xml .= '  <name>'.$this->_payment->firstName.' '.$this->_payment->lastName.'</name>'."\n";
  299.             $xml .= '  <company>'.$this->_payment->company.'</company>'."\n";
  300.             $xml .= '  <address1>'.$this->_payment->address.'</address1>'."\n";
  301.             $xml .= '  <city>'.$this->_payment->city.'</city>'."\n";
  302.             $xml .= '  <state>'.$this->_payment->state.'</state>'."\n";
  303.             $xml .= '  <zip>'.$this->_payment->zip.'</zip>'."\n";
  304.             $xml .= '  <country>'.$this->_payment->country.'</country>'."\n";
  305.             $xml .= '  <phone>'.$this->_payment->phone.'</phone>'."\n";
  306.             $xml .= '  <email>'.$this->_payment->email.'</email>'."\n";
  307.             $xml .= '  <addrnum>'.$this->_payment->address.'</addrnum>'."\n";
  308.             $xml .= '</billing>'."\n";
  309.         }
  310.  
  311.         $xml .= '</order>'."\n";
  312.  
  313.         return $xml;
  314.     }
  315. }
  316.  
  317. {
  318.  
  319.     var $_statusCodeMap = array('APPROVED' => PAYMENT_PROCESS_RESULT_APPROVED,
  320.                                 'DECLINED' => PAYMENT_PROCESS_RESULT_DECLINED,
  321.                                 'FRAUD' => PAYMENT_PROCESS_RESULT_FRAUD);
  322.  
  323.     /**
  324.      * LinkPoint status codes
  325.      *
  326.      * This array holds many of the common response codes. There are over 200
  327.      * response codes - so check the LinkPoint manual if you get a status
  328.      * code that does not match (see "Response Reason Codes & Response
  329.      * Reason Text" in the AIM manual).
  330.      *
  331.      * @see getStatusText()
  332.      * @access private
  333.      */
  334.     var $_statusCodeMessages = array(
  335.         'APPROVED' => 'This transaction has been approved.',
  336.         'DECLINED' => 'This transaction has been declined.',
  337.         'FRAUD' => 'This transaction has been determined to be fraud.');
  338.  
  339.     var $_avsCodeMap = array(
  340.         'YY' => PAYMENT_PROCESS_AVS_MATCH,
  341.         'YN' => PAYMENT_PROCESS_AVS_MISMATCH,
  342.         'YX' => PAYMENT_PROCESS_AVS_ERROR,
  343.         'NY' => PAYMENT_PROCESS_AVS_MISMATCH,
  344.         'XY' => PAYMENT_PROCESS_AVS_MISMATCH,
  345.         'NN' => PAYMENT_PROCESS_AVS_MISMATCH,
  346.         'NX' => PAYMENT_PROCESS_AVS_MISMATCH,
  347.         'XN' => PAYMENT_PROCESS_AVS_MISMATCH,
  348.         'XX' => PAYMENT_PROCESS_AVS_ERROR
  349.     );
  350.  
  351.     var $_avsCodeMessages = array(
  352.         'YY' => 'Address matches, zip code matches',
  353.         'YN' => 'Address matches, zip code does not match',
  354.         'YX' => 'Address matches, zip code comparison not available',
  355.         'NY' => 'Address does not match, zip code matches',
  356.         'XY' => 'Address comparison not available, zip code matches',
  357.         'NN' => 'Address comparison does not match, zip code does not match',
  358.         'NX' => 'Address does not match, zip code comparison not available',
  359.         'XN' => 'Address comparison not available, zip code does not match',
  360.         'XX' => 'Address comparison not available, zip code comparison not available'
  361.     );
  362.  
  363.     var $_cvvCodeMap = array('M' => PAYMENT_PROCESS_CVV_MATCH,
  364.                              'N' => PAYMENT_PROCESS_CVV_MISMATCH,
  365.                              'P' => PAYMENT_PROCESS_CVV_ERROR,
  366.                              'S' => PAYMENT_PROCESS_CVV_ERROR,
  367.                              'U' => PAYMENT_PROCESS_CVV_ERROR,
  368.                              'X' => PAYMENT_PROCESS_CVV_ERROR
  369.     );
  370.  
  371.     var $_cvvCodeMessages = array(
  372.         'M' => 'Card Code Match',
  373.         'N' => 'Card code does not match',
  374.         'P' => 'Not processed',
  375.         'S' => 'Merchant has indicated that the card code is not present on the card',
  376.         'U' => 'Issuer is not certified and/or has not proivded encryption keys',
  377.         'X' => 'No response from the credit card association was received'
  378.     );
  379.  
  380.     var $_fieldMap = array('r_approved'  => 'code',
  381.                            'r_error'  => 'message',
  382.                            'r_code'  => 'approvalCode',
  383.                            'r_ordernum'  => 'transactionId'
  384.     );
  385.  
  386.     function Payment_Process_Response_LinkPoint($rawResponse)
  387.     {
  388.         $this->Payment_Process_Response($rawResponse);
  389.     }
  390.  
  391.     /**
  392.     * parse
  393.     *
  394.     * @author Joe Stump <joe@joestump.net>
  395.     * @access public
  396.     * @return void 
  397.     */
  398.     function parse()
  399.     {
  400.         $xml new Payment_Processor_LinkPoint_XML_Parser();
  401.         $xml->parseString('<response>'.$this->_rawResponse.'</response>');
  402.         if (is_array($xml->response&& count($xml->response)) {
  403.             $this->avsCode = substr($xml->response['r_avs'],0,2);
  404.             $this->cvvCode = substr($xml->response['r_avs'],2,1);
  405.             $this->customerId = $this->_request->customerId;
  406.             $this->invoiceNumber = $this->_request->invoiceNumber;
  407.             $this->_mapFields($xml->response);
  408.  
  409.             // switch to DECLINED since a duplicate isn't *really* fraud
  410.             if(eregi('duplicate',$this->message)) {
  411.                 $this->messageCode = 'DECLINED';
  412.             }
  413.         }
  414.     }
  415. }
  416.  
  417. /**
  418.  * Payment_Processor_LinkPoint_XML_Parser
  419.  *
  420.  * XML Parser for the LinkPoint response
  421.  *
  422.  * @author Joe Stump <joe@joestump.net>
  423.  * @package Payment_Process
  424.  */
  425. class Payment_Processor_LinkPoint_XML_Parser extends XML_Parser
  426. {
  427.     var $response = array();
  428.     var $tag = null;
  429.  
  430.     {
  431.         $this->XML_Parser();
  432.     }
  433.  
  434.     function startHandler($xp$elem&$attribs)
  435.     {
  436.         $this->tag = $elem;
  437.     }
  438.  
  439.     function endHandler($xp$elem)
  440.     {
  441.  
  442.     }
  443.  
  444.     function defaultHandler($xp,$data)
  445.     {
  446.         $this->response[strtolower($this->tag)$data;
  447.     }
  448. }
  449.  
  450. ?>

Documentation generated on Mon, 11 Mar 2019 14:15:59 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.