| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Omnipay\AcquiroPay\Message; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Omnipay\Common\Message\AbstractRequest; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Purchase Request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @method Response send() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class PurchaseRequest extends AuthorizeRequest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * Get phone. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 | 18 |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 18 |  |     public function getPhone() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         return $this->getParameter('phone'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * Set phone. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 4 |  |      * @return static|AbstractRequest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 4 |  |     public function setPhone($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         return $this->setParameter('phone', $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * Get custom field 2. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 10 |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 10 |  |     public function getCf2() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         return $this->getParameter('cf2'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * Set custom field 2. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 4 |  |      * @return static|AbstractRequest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 4 |  |     public function setCf2($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return $this->setParameter('cf2', $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * Get custom field 3. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 10 |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 10 |  |     public function getCf3() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         return $this->getParameter('cf3'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * Set custom field 3. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 4 |  |      * @return static|AbstractRequest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 4 |  |     public function setCf3($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         return $this->setParameter('cf3', $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * Get callback URL. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 10 |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 10 |  |     public function getCallbackUrl() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         return $this->getParameter('callbackUrl'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * Set callback URL. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 4 |  |      * @return static|AbstractRequest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 4 |  |     public function setCallbackUrl($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         return $this->setParameter('callbackUrl', $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * Get apple reference. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 | 10 |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |     public function getAppleReference() | 
            
                                                                        
                            
            
                                    
            
            
                | 108 | 10 |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 109 | 2 |  |         return $this->getParameter('appleReference'); | 
            
                                                                        
                            
            
                                    
            
            
                | 110 | 2 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 2 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 | 2 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 | 2 |  |      * Set apple reference. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 2 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * @param string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 2 |  |      * @return static|AbstractRequest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     public function setAppleReference($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 2 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 2 |  |         return $this->setParameter('appleReference', $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 | 2 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 | 2 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 | 2 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 | 2 |  |      * Get the raw data array for this message. The format of this varies from gateway to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 | 2 |  |      * gateway, but will usually be either an associative array, or a SimpleXMLElement. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 | 2 |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 | 2 |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 | 2 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 2 |  |     public function getData() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 | 8 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 | 8 |  |         if ($this->getAppleReference() !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 8 |  |             $this->validate('amount', 'appleReference'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 8 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 8 |  |             $data = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |                 'opcode' => 4, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 8 |  |                 'product_id' => $this->getProductId(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |                 'apple_token' => urlencode(base64_encode(json_encode($this->getAppleReference()))), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 | 8 |  |                 'token' => $this->getRequestToken(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 | 8 |  |         } elseif ($this->getCardReference() !== null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             $this->validate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |                 'amount', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 8 |  |                 'card', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 | 8 |  |                 'cardReference', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 8 |  |                 'transactionId', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 | 8 |  |                 'clientIp', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 | 8 |  |                 'returnUrl' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 | 8 |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 | 8 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 | 8 |  |             $data = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 | 8 |  |                 'opcode' => 21, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 | 8 |  |                 'product_id' => $this->getProductId(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 | 8 |  |                 'payment_id' => $this->getCardReference(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 | 8 |  |                 'amount' => $this->getAmount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 8 |  |                 'cf' => $this->getTransactionId(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |                 'ip_address' => $this->getClientIp(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |                 'cvv' => $this->getCard()->getCvv(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 | 10 |  |                 'pp_identity' => 'card', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 | 4 |  |                 'token' => $this->getRequestToken(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 | 4 |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 | 10 |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 | 4 |  |             $this->validate( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 | 4 |  |                 'amount', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 | 10 |  |                 'card', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 | 4 |  |                 'transactionId', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 | 4 |  |                 'clientIp', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 | 10 |  |                 'returnUrl' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 | 4 |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 | 4 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |             $card = $this->getCard(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 | 10 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |             $card->validate(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |             $data = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |                 'opcode' => 0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |                 'product_id' => $this->getProductId(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |                 'amount' => $this->getAmount(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |                 'cf' => $this->getTransactionId(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 | 18 |  |                 'ip_address' => $this->getClientIp(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |                 'pan' => $card->getNumber(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 | 18 |  |                 'cardholder' => $card->getName(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |                 'exp_month' => $card->getExpiryMonth(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |                 'exp_year' => $card->getExpiryYear(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 | 2 |  |                 'cvv' => $card->getCvv(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |                 'pp_identity' => 'card', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |                 'token' => $this->getRequestToken(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         if ($this->getPhone()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |             $data['phone'] = $this->getPhone(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         if ($this->getCf2()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |             $data['cf2'] = $this->getCf2(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         if ($this->getCf3()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |             $data['cf3'] = $this->getCf3(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         if ($this->getCallbackUrl()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |             $data['cb_url'] = $this->getCallbackUrl(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         return $data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |      * Get a request token. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |     public function getRequestToken() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |         return md5($this->getMerchantId() . $this->getProductId() . $this->getAmount() . $this->getTransactionId() . $this->getPhone() . $this->getSecretWord()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 215 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 216 |  |  |  | 
            
                        
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: