Changeset 12620
- Timestamp:
- 11/03/08 22:57:49 (5 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfAuthorizeNetCIMPlugin/lib/sfAuthorizeNetCIM.class.php
r12590 r12620 9 9 */ 10 10 11 class CIMAPIException extends Exception { 11 //FIXME add package.xml dependancys for SimpleXML and CURL 12 //FIXME make debugging hook existing symfony logging/debugging infrastrucure 13 14 class CIMAPIException extends sfException { 15 public function __construct($msg) { 16 parent::__construct($msg, 0); 17 } 18 } 19 20 21 class CIMDirectResponseException extends CIMAPIException { 12 22 public function __construct($msg) { 13 23 parent::__construct($msg); … … 27 37 } 28 38 29 class DeclinedCardException extends CIMAPIException {39 class CIMDeclinedCardException extends CIMAPIException { 30 40 public function __construct($msg) { 31 41 parent::__construct($msg); … … 44 54 45 55 public function addShippingAddressList($sp) { 46 //FIXME validate 56 if( ! isset($pp) || ! $pp instanceof AuthorizeNetCIMCustomerShippingAddress ) { 57 throw(new CIMAPIException("Must pass in a AuthorizeNetCIMCustomerShippingAddress object")); 58 } 47 59 $this->shippingAddressList[] = $sp; 48 60 } 49 61 50 62 public function addCustomerPaymentProfile($pp) { 51 //FIXME validate adding only payment profile objects 63 if( ! isset($pp) || ! $pp instanceof AuthorizeNetCIMCustomerPaymentProfile ) { 64 throw(new CIMAPIException("Must pass in a AuthorizeNetCIMCustomerPaymentProfile object")); 65 } 52 66 $this->paymentProfilesList[] = $pp; 53 67 } … … 55 69 public function __set($key,$val) { 56 70 if( ! isset($this->$key) ) { 57 throw(new Exception("ERROR: Non-existant setter: '$key'"));71 throw(new CIMAPIException("ERROR: Non-existant setter: '$key'")); 58 72 } 59 73 if( isset($val) ) { … … 64 78 public function __get($key) { 65 79 if( ! isset($this->$key) ) { 66 throw(new Exception("ERROR: Non-existant getter: '$key'"));80 throw(new CIMAPIException("ERROR: Non-existant getter: '$key'")); 67 81 } 68 82 return $this->$key; … … 100 114 public function __set($key,$val) { 101 115 if( ! isset($this->$key) ) { 102 throw(new Exception("ERROR: Non-existant setter: '$key'"));116 throw(new CIMAPIException("ERROR: Non-existant setter: '$key'")); 103 117 } 104 118 … … 110 124 public function __get($key) { 111 125 if( ! isset($this->$key) ) { 112 throw(new Exception("ERROR: Non-existant getter: '$key'"));126 throw(new CIMAPIException("ERROR: Non-existant getter: '$key'")); 113 127 } 114 128 return $this->$key; … … 133 147 public function __set($key,$val) { 134 148 if( ! isset($this->$key) ) { 135 throw(new Exception("ERROR: Non-existant setter: '$key'"));149 throw(new CIMAPIException("ERROR: Non-existant setter: '$key'")); 136 150 } 137 151 if( isset($val) ) { … … 142 156 public function __get($key) { 143 157 if( ! isset($this->$key) ) { 144 throw(new Exception("ERROR: Non-existant getter: '$key'"));158 throw(new CIMAPIException("ERROR: Non-existant getter: '$key'")); 145 159 } 146 160 return $this->$key; … … 183 197 public function __set($key,$val) { 184 198 if( ! isset($this->$key) ) { 185 throw(new Exception("ERROR: Non-existant setter: '$key'"));199 throw(new CIMAPIException("ERROR: Non-existant setter: '$key'")); 186 200 } 187 201 if( isset($val) ) { … … 192 206 public function __get($key) { 193 207 if( ! isset($this->$key) ) { 194 throw(new Exception("ERROR: Non-existant getter: '$key'"));208 throw(new CIMAPIException("ERROR: Non-existant getter: '$key'")); 195 209 } 196 210 return $this->$key; … … 243 257 if( ! isset($customerProfileObject) || ! $customerProfileObject) { 244 258 throw(new CIMAPIException("ERROR: Must pass in a customerProfileObject")); 259 } 260 261 $paymentProfilesList = $customerProfileObject->paymentProfilesList; 262 if( count($paymentProfilesList) == 0 ) { 263 throw(new CIMAPIException("The customer profile must have at least one payment profile added to it for authorize.net to accept.")); 245 264 } 246 265 … … 252 271 $content .= " " . $this->makeXML('email', $customerProfileObject->email); 253 272 $content .= " <paymentProfiles>\n"; 254 $paymentProfilesList = $customerProfileObject->paymentProfilesList;255 273 foreach( $paymentProfilesList as $pp ) { 256 274 $content .= $this->getXMLForPaymentProfile($pp); 257 258 275 } 259 276 $content .= " </paymentProfiles>\n"; … … 292 309 //Send XML and get parsed response back 293 310 $parsed = $this->sendXMLAndParseResponse($content); //may throw an exception if somthing went wrong 311 312 $customerPaymentProfileObject->customerPaymentProfileId = $parsed->customerPaymentProfileId; 294 313 } 295 314 … … 396 415 397 416 //Send XML and get parsed response back 398 $parsed = $this->sendXMLAndParseResponse($content, false); //may throw an exception if somthing went wrong 417 $parsed = $this->sendXMLAndParseResponse($content, false ); //may throw an exception if somthing went wrong 418 399 419 if ("Ok" != $parsed->messages->resultCode) { 400 420 if( ! isset($parsed->directResponse) ) { … … 410 430 } 411 431 } 412 413 414 //FIXME parse the CSV data 432 433 415 434 $customerTransactionObject->directResponse = (string) $parsed->directResponse; 416 435 $directResponseFields = explode(',', $customerTransactionObject->directResponse); … … 427 446 $customerTransactionObject->responseReasonText = $directResponseFields[3]; 428 447 429 throw(new DeclinedCardException($errorMessage));448 throw(new CIMDeclinedCardException($errorMessage)); 430 449 431 450 } else if( $directResponseFields[0] == 3 ) { //error … … 686 705 687 706 688 private function sendXMLAndParseResponse($content, $ throwErrorCodeExceptions= true) {707 private function sendXMLAndParseResponse($content, $checkResultCode = true) { 689 708 $this->lastRequestXML = $content; 690 709 $this->lastResponseXML = ''; … … 696 715 $this->debugPrint("response = " . $this->lastResponseXML . "\n"); 697 716 698 $parsed = $this->parseAPIResponse( $this->lastResponseXML, $throwErrorCodeExceptions);//throws exception if somthing went wrong717 $parsed = $this->parseAPIResponse( $this->lastResponseXML, $checkResultCode );//throws exception if somthing went wrong 699 718 $this->lastParsedResponseObject = $parsed; 700 719 … … 717 736 718 737 719 private function parseAPIResponse($response, $ throwErrorCodeExceptions= true ) {738 private function parseAPIResponse($response, $checkResultCode = true ) { 720 739 $matches = array(); 721 740 preg_match('/^.*?(<\?xml.*)$/m', $response, $matches); … … 725 744 #$parsedresponse = simplexml_load_string($response); 726 745 727 if ( "Ok" != $parsedresponse->messages->resultCode) {728 $err = " The operation failed with the following errors:\n";746 if ($checkResultCode && "Ok" != $parsedresponse->messages->resultCode) { 747 $err = "$checkResultCode: The operation failed with the following errors:\n"; 729 748 foreach ($parsedresponse->messages->message as $msg) { 730 749 $err .= "[" . $msg->code . "] " . $msg->text . "\n"; … … 732 751 $err .= "\n"; 733 752 734 if( $throwErrorCodeExceptions ) { 753 754 if( isset($parsedresponse->validationDirectResponse) ) { 755 $directResponseFields = explode(',', (string)$parsedresponse->validationDirectResponse); 756 throw(new CIMDirectResponseException($directResponseFields[3])); 757 758 } else if( isset($parsedresponse->directResponse) ) { 759 $directResponseFields = explode(',', (string)$parsedresponse->directResponse); 760 throw(new CIMDirectResponseException($directResponseFields[3])); 761 762 } else { 763 735 764 throw(new CIMErrorResultCodeException($err)); 736 765 }