GFPaystationPostbackResult

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

Defined (1)

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

/class.GFPaystationPostbackResult.php  
  1. class GFPaystationPostbackResult { 
  2.  
  3. public $errorCode; // <ec> - there is also the <PaystationErrorCode> tag, but is the same value so don't have 2 properties of this class. 
  4. public $errorMessage; // <em> - also there is <PaystationErrorMessage> tag, but is the same so don;t create 2 properies of the class. 
  5. public $transactionId; // <ti> - there is also the <TransactionID> and <PaystationTransactionID>, but don;t want multiple properites in the class. 
  6. public $cardType; // <ct> - Is also <cardtype>, but again don't need duplicate properties. 
  7. public $merchantRef; // <merchant_ref> - is also <MerchantReference>, but is the same so don't include 2 properties. 
  8. public $testMode; // <tm> - is also <TransactionMode>, again is same so we don't create 2 properties. 
  9. public $merchantSession; // <MerchantSession> 
  10. public $userAcquirerMerchantId; // <UserAcquirerMerchantID> 
  11. public $purchaseAmount; // <PurchaseAmount> 
  12. public $locale; // <Locale> 
  13. public $returnReceiptNumber; // <ReturnReceiptNumber> 
  14. public $shoppingTransactionNumber; // <ShoppingTransactionNumber> 
  15. public $acqResponseCode; // <AcqResponseCode> 
  16. public $qsiResponseCode; // <QSIResponseCode> 
  17. public $cscResultCode; // <CSCResultCode> 
  18. public $avsResultCode; // <AVSResultCode> 
  19. public $transactionTime; // <TransactionTime> 
  20. public $batchNumber; // <BatchNumber> 
  21. public $authorizeId; // <AuthorizeID> 
  22. public $username; // <Username> 
  23. public $requestIP; // <RequestIP> 
  24. public $requestUserAgent; // <RequestUserAgent> 
  25. public $requestHttpReferrer; // <RequestHttpReferrer> 
  26. public $paymentRequestTime; // <PaymentRequestTime> 
  27. public $digitalOrderTime; // <DigitalOrderTime> 
  28. public $digitalReceiptTime; // <DigitalReceiptTime> 
  29. public $authentication = array('authType' => null, 'authStatus' => null, 'authSecurityLevel' => null, 'authHashToken' => null,  
  30. 'auth3dsId' => null, 'auth3dsElectronicCommerceIndicator' => null, 'auth3dsEnrolled' => null, 'auth3dsStatus' => null); 
  31.  
  32. public $isValid; 
  33.  
  34. // ==================================================================================================================================== 
  35. /** 
  36. * The constructor takes the response and then extracts the info and populates the properties of the class. 
  37. * @param string $postback; 
  38. */ 
  39. // ==================================================================================================================================== 
  40. public function __construct($postback) { 
  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. // ---------------------------------- 
  48. // Call function to parse the xml. 
  49. $xml = simplexml_load_string($postback); 
  50.  
  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. // Check some of the things we know should be in the XML are there as an extra test it is valid. 
  60. if ((isset($xml->ti)) && (isset($xml->MerchantSession)) && (isset($xml->merchant_ref))) { 
  61.  
  62. // ---------------------------------- 
  63. // Now set the properies of this class to the xml items. 
  64. // We need to cast the items to the correct datatypes otherwise code using these later on can error or warn because the item is a simple XML element. 
  65. $this->errorCode = (int) $xml->ec; 
  66. $this->errorMessage = (string) $xml->em; 
  67. $this->transactionId = (string) $xml->ti; 
  68. $this->cardType = (string) $xml->ct; 
  69. $this->merchantRef = (string) $xml->merchant_ref; 
  70. $this->testMode = (string) $xml->tm; 
  71. $this->merchantSession = (string) $xml->MerchantSession; 
  72. $this->userAcquirerMerchantId = (string) $xml->UserAcquirerMerchantID; 
  73. $this->purchaseAmount = (int) $xml->PurchaseAmount; // Remember this will be cents, so int. Divide by 100 to get dollars and cents. 
  74. $this->locale = (string) $xml->Locale; 
  75. $this->returnReceiptNumber = (string) $xml->ReturnReceiptNumber; 
  76. $this->shoppingTransactionNumber = (int) $xml->ShoppingTransactionNumber; 
  77. $this->acqResponseCode = (string) $xml->AcqResponseCode; 
  78. $this->qsiResponseCode = (string) $xml->QSIResponseCode; 
  79. $this->cscResultCode = (string) $xml->CSCResultCode; 
  80. $this->avsResultCode = (string) $xml->AVSResultCode; 
  81. $this->transactionTime = (string) $xml->TransactionTime; 
  82. $this->batchNumber = (int) $xml->BatchNumber; 
  83. $this->authorizeId = (string) $xml->AuthorizeID; 
  84. $this->username = (string) $xml->Username; 
  85. $this->requestIP = (string) $xml->RequestIP; 
  86. $this->requestUserAgent = (string) $xml->RequestUserAgent; 
  87. $this->requestHttpReferrer = (string) $xml->RequestHttpReferrer; 
  88. $this->paymentRequestTime = (string) $xml->PaymentRequestTime; 
  89. $this->digitalOrderTime = (string) $xml->DigitalOrderTime; 
  90. $this->digitalReceiptTime = (string) $xml->DigitalReceiptTime; 
  91.  
  92. // This is an array of sub items. 
  93. $this->authentication = array('authType' => (string) $xml->Authentication->auth_Type,  
  94. 'authStatus' => (string) $xml->Authentication->auth_Status,  
  95. 'authSecurityLevel' => (string) $xml->Authentication->auth_SecurityLevel,  
  96. 'authHashToken' => (string) $xml->Authentication->auth_HashToken,  
  97. 'auth3dsId' => (string) $xml->Authentication->auth_3DSID,  
  98. 'auth3dsElectronicCommerceIndicator' => (string) $xml->Authentication->auth_3DSElectronicCommerceIndicator,  
  99. 'auth3dsEnrolled' => (string) $xml->Authentication->auth_3DSEnrolled,  
  100. 'auth3dsStatus' => (string) $xml->Authentication->auth_3DSStatus); 
  101.  
  102. $this->isValid = true; 
  103. else { 
  104.  
  105. $this->isValid = false; 
  106.  
  107. // ---------------------------------- 
  108. // Restore old libxml settings 
  109. libxml_disable_entity_loader($oldDisableEntityLoader); 
  110. libxml_use_internal_errors($oldUseInternalErrors); 
  111. catch (Exception $e) { 
  112. // Restore old libxml settings 
  113. libxml_disable_entity_loader($oldDisableEntityLoader); 
  114. libxml_use_internal_errors($oldUseInternalErrors); 
  115.  
  116. throw new GFPaystationException('Error parsing Paystation result request: ' . $e->getMessage());