PageRenderTime 96ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/Payment/Process2/Result/LinkPoint.php

https://github.com/pear/Payment_Process2
PHP | 188 lines | 91 code | 22 blank | 75 comment | 3 complexity | 5b078ada8aca92b58d4c5ca5ca10f0f0 MD5 | raw file
  1. <?php
  2. require_once 'Payment/Process2/Result.php';
  3. require_once 'Payment/Process2/Result/Driver.php';
  4. /**
  5. * Payment_Process2_Result_LinkPoint
  6. *
  7. * LinkPoint result class
  8. *
  9. * @author Joe Stump <joe@joestump.net>
  10. * @package Payment_Process2
  11. */
  12. class Payment_Process2_Result_LinkPoint extends Payment_Process2_Result implements Payment_Process2_Result_Driver
  13. {
  14. var $_statusCodeMap = array('APPROVED' => Payment_Process2::RESULT_APPROVED,
  15. 'DECLINED' => Payment_Process2::RESULT_DECLINED,
  16. 'FRAUD' => Payment_Process2::RESULT_FRAUD);
  17. /**
  18. * LinkPoint status codes
  19. *
  20. * This array holds many of the common response codes. There are over 200
  21. * response codes - so check the LinkPoint manual if you get a status
  22. * code that does not match (see "Response Reason Codes & Response
  23. * Reason Text" in the AIM manual).
  24. *
  25. * @see getStatusText()
  26. * @access private
  27. */
  28. var $_statusCodeMessages = array(
  29. 'APPROVED' => 'This transaction has been approved.',
  30. 'DECLINED' => 'This transaction has been declined.',
  31. 'FRAUD' => 'This transaction has been determined to be fraud.');
  32. var $_avsCodeMap = array(
  33. 'YY' => Payment_Process2::AVS_MATCH,
  34. 'YN' => Payment_Process2::AVS_MISMATCH,
  35. 'YX' => Payment_Process2::AVS_ERROR,
  36. 'NY' => Payment_Process2::AVS_MISMATCH,
  37. 'XY' => Payment_Process2::AVS_MISMATCH,
  38. 'NN' => Payment_Process2::AVS_MISMATCH,
  39. 'NX' => Payment_Process2::AVS_MISMATCH,
  40. 'XN' => Payment_Process2::AVS_MISMATCH,
  41. 'XX' => Payment_Process2::AVS_ERROR
  42. );
  43. var $_avsCodeMessages = array(
  44. 'YY' => 'Address matches, zip code matches',
  45. 'YN' => 'Address matches, zip code does not match',
  46. 'YX' => 'Address matches, zip code comparison not available',
  47. 'NY' => 'Address does not match, zip code matches',
  48. 'XY' => 'Address comparison not available, zip code matches',
  49. 'NN' => 'Address comparison does not match, zip code does not match',
  50. 'NX' => 'Address does not match, zip code comparison not available',
  51. 'XN' => 'Address comparison not available, zip code does not match',
  52. 'XX' => 'Address comparison not available, zip code comparison not available'
  53. );
  54. var $_cvvCodeMap = array('M' => Payment_Process2::CVV_MATCH,
  55. 'N' => Payment_Process2::CVV_MISMATCH,
  56. 'P' => Payment_Process2::CVV_ERROR,
  57. 'S' => Payment_Process2::CVV_ERROR,
  58. 'U' => Payment_Process2::CVV_ERROR,
  59. 'X' => Payment_Process2::CVV_ERROR
  60. );
  61. var $_cvvCodeMessages = array(
  62. 'M' => 'Card Code Match',
  63. 'N' => 'Card code does not match',
  64. 'P' => 'Not processed',
  65. 'S' => 'Merchant has indicated that the card code is not present on the card',
  66. 'U' => 'Issuer is not certified and/or has not proivded encryption keys',
  67. 'X' => 'No response from the credit card association was received'
  68. );
  69. /**
  70. * parse
  71. *
  72. * @author Joe Stump <joe@joestump.net>
  73. * @access public
  74. * @return void
  75. */
  76. function parse()
  77. {
  78. $fieldMap = array('r_approved' => 'code',
  79. 'r_error' => 'message',
  80. 'r_code' => 'approvalCode',
  81. 'r_ordernum' => 'transactionId'
  82. );
  83. $xml = new Payment_Process2_LinkPoint_XML_Parser();
  84. $xml->parseString('<response>'.$this->_rawResponse.'</response>');
  85. if (is_array($xml->response) && count($xml->response)) {
  86. $this->avsCode = substr($xml->response['r_avs'],0,2);
  87. $this->cvvCode = substr($xml->response['r_avs'],2,1);
  88. $this->customerId = $this->_request->customerId;
  89. $this->invoiceNumber = $this->_request->invoiceNumber;
  90. foreach ($fieldMap as $key => $val) {
  91. $this->$val = (array_key_exists($key, $xml->response))
  92. ? $xml->response[$key]
  93. : null;
  94. }
  95. // switch to DECLINED since a duplicate isn't *really* fraud
  96. if (preg_match('/duplicate/i',$this->message)) {
  97. $this->messageCode = 'DECLINED';
  98. }
  99. }
  100. }
  101. }
  102. require_once 'XML/Parser.php';
  103. /**
  104. * Payment_Process2_LinkPoint_XML_Parser
  105. *
  106. * XML Parser for the LinkPoint response
  107. *
  108. * @todo Split out to own class
  109. * @author Joe Stump <joe@joestump.net>
  110. * @package Payment_Process2
  111. */
  112. class Payment_Process2_LinkPoint_XML_Parser extends XML_Parser
  113. {
  114. /**
  115. * $response
  116. *
  117. * @var array $response Raw response as an array
  118. * @access public
  119. */
  120. var $response = array();
  121. /**
  122. * $log
  123. *
  124. * @var string $tag Current tag
  125. * @access private
  126. */
  127. var $tag = null;
  128. /**
  129. * startHandler
  130. *
  131. * @author Joe Stump <joe@joestump.net>
  132. * @access public
  133. * @param resource $xp XML processor handler
  134. * @param string $elem Name of XML entity
  135. * @return void
  136. */
  137. function startHandler($xp, $elem, $attribs)
  138. {
  139. $this->tag = $elem;
  140. }
  141. /**
  142. * endHandler
  143. *
  144. * @author Joe Stump <joe@joestump.net>
  145. * @access public
  146. * @param resource $xp XML processor handler
  147. * @param string $elem Name of XML entity
  148. * @return void
  149. */
  150. function endHandler($xp, $elem)
  151. {
  152. }
  153. /**
  154. * defaultHandler
  155. *
  156. * @author Joe Stump <joe@joestump.net>
  157. * @access public
  158. * @param resource $xp XML processor handler
  159. * @param string $data
  160. * @return void
  161. */
  162. function defaultHandler($xp,$data)
  163. {
  164. $this->response[strtolower($this->tag)] = $data;
  165. }
  166. }