GFPaystationPaymentResponse

The Gravity Forms Paystation (3 party hosted) GFPaystationPaymentResponse class.

Defined (1)

The class is defined in the following location(s).

/class.GFPaystationPayment.php  
  1. class GFPaystationPaymentResponse { 
  2.  
  3. // Declare properites for all the other bits which can come back via the xml, even though we don't care about much of them. 
  4. public $errorCode; // <ec> - there is also the <PaystationErrorCode> tag, but is the same value so don't have 2 properties of this class. 
  5. public $errorMessage; // <em> - also there is <PaystationErrorMessage> tag, but is the same so don;t create 2 properies of the class. 
  6. public $transactionId; // <ti> - there is also the <TransactionID> and <PaystationTransactionID>, but don;t want multiple properites in the class. 
  7. public $cardType; // <ct> - Is also <cardtype>, but again don't need duplicate properties. 
  8. public $merchantRef; // <merchant_ref> - is also <MerchantReference>, but is the same so don't include 2 properties. 
  9. public $testMode; // <tm> - is also <TransactionMode>, again is same so we don't create 2 properties. 
  10. public $merchantSession; // <MerchantSession> 
  11. public $userAcquirerMerchantId; // <UserAcquirerMerchantID> 
  12. public $purchaseAmount; // <PurchaseAmount> 
  13. public $locale; // <Locale> 
  14. public $returnReceiptNumber; // <ReturnReceiptNumber> 
  15. public $shoppingTransactionNumber; // <ShoppingTransactionNumber> 
  16. public $acqResponseCode; // <AcqResponseCode> 
  17. public $qsiResponseCode; // <QSIResponseCode> 
  18. public $cscResultCode; // <CSCResultCode> 
  19. public $avsResultCode; // <AVSResultCode> 
  20. public $transactionTime; // <TransactionTime> 
  21. public $batchNumber; // <BatchNumber> 
  22. public $authorizeId; // <AuthorizeID> 
  23. public $username; // <Username> 
  24. public $requestIP; // <RequestIP> 
  25. public $requestUserAgent; // <RequestUserAgent> 
  26. public $requestHttpReferrer; // <RequestHttpReferrer> 
  27. public $paymentRequestTime; // <PaymentRequestTime> 
  28. public $digitalOrder; // <DigitalOrder> // Note this only appears in the request result and we redirect the browser to this. 
  29. public $digitalOrderTime; // <DigitalOrderTime> 
  30. public $digitalReceiptTime; // <DigitalReceiptTime> 
  31.  
  32.  
  33. // ==================================================================================================================================== 
  34. /** 
  35. * load Paystation response as XML string 
  36. * @param string $responseXML will be xml - yes but this will be the inital response, not the postback. 
  37. * @throws GFPaystationException 
  38. */ 
  39. // ==================================================================================================================================== 
  40. public function loadResponseXML($responseXML) { 
  41.  
  42. try { 
  43. // prevent XML injection attacks, and handle errors without warnings 
  44. $oldDisableEntityLoader = libxml_disable_entity_loader(TRUE); 
  45. $oldUseInternalErrors = libxml_use_internal_errors(TRUE); 
  46.  
  47. // Create xml object, false will be returend if there was a pasing error. 
  48. $xml = simplexml_load_string($responseXML); 
  49.  
  50. // So if parse failed then build an error message. 
  51. if ($xml === false) { 
  52. $errmsg = ''; 
  53.  
  54. foreach (libxml_get_errors() as $error) { 
  55. $errmsg .= $error->message; 
  56.  
  57. throw new Exception($errmsg); 
  58.  
  59.  
  60. // If the error code is zero then there was no error, the transaction was sucessful. 
  61. if ($xml->ec === 0) 
  62. $this->success = true; 
  63. else 
  64. $this->success = false; 
  65.  
  66. // Also set the paymentURL to the digital order url.  
  67. $this->digitalOrder = (string) $xml->DigitalOrder; 
  68.  
  69. // ---------------------------------- 
  70. // Now set the other properies of this class to the xml items. 
  71. // We really only use the transactionId and the error message in the plugin. 
  72. $this->errorCode = (int) $xml->ec; 
  73. $this->errorMessage = $xml->em; 
  74. $this->transactionId = $xml->ti; 
  75. $this->cardType = $xml->ct; 
  76. $this->merchantRef = $xml->merchant_ref; 
  77. $this->testMode = $xml->tm; 
  78. $this->merchantSession = $xml->MerchantSession; 
  79. $this->userAcquirerMerchantId = $xml->UserAcquirerMerchantID; 
  80. $this->purchaseAmount = (int) $xml->PurchaseAmount; // Remember the paystation gateway deals with cents so this is an integer (divide by 100 to get float of dollars and cents). 
  81. $this->locale = $xml->Locale; 
  82. $this->returnReceiptNumber = $xml->ReturnReceiptNumber; 
  83. $this->shoppingTransactionNumber = $xml->ShoppingTransactionNumber; 
  84. $this->acqResponseCode = $xml->AcqResponseCode; 
  85. $this->qsiResponseCode = $xml->QSIResponseCode; 
  86. $this->cscResultCode = $xml->CSCResultCode; 
  87. $this->avsResultCode = $xml->AVSResultCode; 
  88. $this->transactionTime = $xml->TransactionTime; 
  89. $this->batchNumber = $xml->BatchNumber; 
  90. $this->authorizeId = $xml->AuthorizeID; 
  91. $this->username = $xml->Username; 
  92. $this->requestIP = $xml->RequestIP; 
  93. $this->requestUserAgent = $xml->RequestUserAgent; 
  94. $this->requestHttpReferrer = $xml->RequestHttpReferrer; 
  95. $this->paymentRequestTime = $xml->PaymentRequestTime; 
  96. $this->digitalOrderTime = $xml->DigitalOrderTime; 
  97. $this->digitalReceiptTime = $xml->DigitalReceiptTime; 
  98.  
  99. // restore old libxml settings 
  100. libxml_disable_entity_loader($oldDisableEntityLoader); 
  101. libxml_use_internal_errors($oldUseInternalErrors); 
  102. catch (Exception $e) { 
  103. // restore old libxml settings 
  104. libxml_disable_entity_loader($oldDisableEntityLoader); 
  105. libxml_use_internal_errors($oldUseInternalErrors); 
  106.  
  107. throw new GFPaystationException('Error parsing Paystation gateway response: ' . $e->getMessage());