| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * eCoin driver for Omnipay PHP payment library | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @link      https://github.com/hiqdev/omnipay-ecoin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @package   omnipay-ecoin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @license   MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Omnipay\eCoin\Message; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Omnipay\Common\Exception\InvalidResponseException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Omnipay\Common\Message\AbstractResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * eCoin Complete Purchase Response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | class CompletePurchaseResponse extends AbstractResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 | 3 |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function __construct(CompletePurchaseRequest $request, $data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 3 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 3 |  |         $this->request = $request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->data    = $data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 3 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 1 |  |         if ($this->getHash() !== $this->calculateHash()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             throw new InvalidResponseException('Invalid hash'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 2 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * Whether the payment is successful. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 1 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function isSuccessful() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * Whether the payment is test. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * XXX TODO. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 1 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     public function getTestMode() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return (bool) $this->data['TEST_VAR_TO_BE_SET']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 54 | 1 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     public function getTransactionId() | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 1 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         return $this->data['ECM_INV_NO']; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 1 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public function getTransactionReference() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         return $this->data['ECM_TRANS_ID']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 1 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     public function getAmount() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         return $this->data['ECM_ITEM_COST']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * Returns the currency. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 1 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     public function getCurrency() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         return 'USD'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * Returns the payer ID. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 | 1 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public function getPayer() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return $this->data['ECM_PAYER_ID']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * Returns the payment date. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 1 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     public function getTime() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         return date('c', $this->data['ECM_TRANS_DATE']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * Get hash from request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 3 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     public function getHash() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 3 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         return $this->data['ECM_HASH']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * Calculate hash to validate incoming confirmation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 3 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     public function calculateHash() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 3 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 3 |  |         $str =  $this->data['ECM_TRANS_ID'] . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 3 |  |                 $this->data['ECM_TRANS_DATE'] . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 3 |  |                 $this->request->getPurse() . | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 | 3 |  |                 $this->data['ECM_PAYER_ID'] . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 3 |  |                 $this->data['ECM_ITEM_COST'] . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 | 3 |  |                 $this->data['ECM_QTY'] . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |                 $this->request->getSecret(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 3 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         return md5($str); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 132 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 133 |  |  |  | 
            
                        
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: