| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Omnipay\Redsys\Message; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SimpleXMLElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Omnipay\Common\Message\AbstractResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Redsys Purchase Response | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class WebservicePurchaseResponse extends AbstractResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     public function isSuccessful() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         // check for field existence as well as value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         return !empty($this->data->CODIGO) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |             && $this->data->CODIGO == '0' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |             && !empty($this->data->OPERACION->Ds_Response) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |             && $this->data->OPERACION->Ds_Response == '0000'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         // @todo  && verify signature | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 23 |  |  |     // @todo Other methods required for abstract response | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     public function getTransactionReference() | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         return "WOOT"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     // @todo Switch to just returning the error code (no message supplied in package) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     public function getMessage() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         if ($this->data instanceof SimpleXMLElement) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             $out = $this->data->asXML(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             $out = json_encode($this->data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         return is_string($out) ? $out : 'nope'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     // @todo Pull out signature methods for use in webservice request/response validation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     // public function getRedirectData() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     // { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         // $security = new Security; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         // $redirect_data = array(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         // $redirect_data['Ds_SignatureVersion'] = Security::VERSION; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         // $redirect_data['Ds_MerchantParameters'] = $security->encodeMerchantParameters($this->data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         // $redirect_data['Ds_Signature'] = $security->createSignature( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         //     $redirect_data['Ds_MerchantParameters'], | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         //     $this->data['Ds_Merchant_Order'], | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         //     base64_decode($this->request->getHmacKey()) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         // ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         // return $redirect_data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     // } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 56 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |  | 
            
                        
PHP provides two ways to mark string literals. Either with single quotes
'literal'or with double quotes"literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\') and the backslash (\\). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is ValueIf your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.