├── TODO.md
├── src
├── config
│ └── config.php
└── Rasim
│ └── Payu
│ ├── Facades
│ └── Payu.php
│ ├── Payu.php
│ ├── PayuServiceProvider.php
│ └── Classes
│ ├── PayuProduct.php
│ ├── PayuAddress.php
│ └── Payulu.php
├── .travis.yml
├── composer.json
├── phpunit.xml
└── README.md
/TODO.md:
--------------------------------------------------------------------------------
1 | TODOlist
2 | ========================
3 |
4 | - Payu URL Config Adjustment
5 | - Rename Function Names
6 |
--------------------------------------------------------------------------------
/src/config/config.php:
--------------------------------------------------------------------------------
1 | "OPU_TEST",
7 | // SECRET KEY
8 | 'secretKey' => "SECRET_KEY"
9 |
10 | );
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 5.3
5 | - 5.4
6 | - 5.5
7 | - 5.6
8 | - hhvm
9 |
10 | before_script:
11 | - composer self-update
12 | - composer install --prefer-source --no-interaction --dev
13 |
14 | script: phpunit
15 |
--------------------------------------------------------------------------------
/src/Rasim/Payu/Facades/Payu.php:
--------------------------------------------------------------------------------
1 | =5.4.0",
13 | "illuminate/support": "4.2.*"
14 | },
15 | "autoload": {
16 | "psr-0": {
17 | "Rasim\\Payu\\": "src/"
18 | }
19 | },
20 | "minimum-stability": "stable"
21 | }
22 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 | ./tests/
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Rasim/Payu/Payu.php:
--------------------------------------------------------------------------------
1 | payuAddress = new PayuAddress;
22 | $this->payulu = new Payulu(\Config::get('payu::merchantId'),\Config::get('payu::secretKey'));
23 |
24 | }
25 |
26 | public function payulu()
27 | {
28 |
29 | return $this->payulu;
30 |
31 | }
32 |
33 | public function payuAddress()
34 | {
35 |
36 | return $this->payuAddress;
37 |
38 | }
39 |
40 | public function payuProduct($pname,$pcode,$pinfo,$price,$priceType,$quantity,$tax)
41 | {
42 |
43 | return $this->payuProduct = new PayuProduct($pname,$pcode,$pinfo,$price,$priceType,$quantity,$tax);
44 |
45 | }
46 |
47 | }
--------------------------------------------------------------------------------
/src/Rasim/Payu/PayuServiceProvider.php:
--------------------------------------------------------------------------------
1 | package('rasim/payu');
22 |
23 | }
24 |
25 | public function register()
26 | {
27 | //register edelim
28 | $this->app['payu'] = $this->app->share(function($app)
29 | {
30 | return new Payu($app->make("Rasim\Payu\Classes\PayuProduct"),
31 | $app->make("Rasim\Payu\Classes\PayuAddress"),
32 | $app->make("Rasim\Payu\Classes\Payulu"));
33 | });
34 |
35 | }
36 |
37 |
38 | /**
39 | * Get the services provided by the provider.
40 | *
41 | * @return array
42 | */
43 | public function provides()
44 | {
45 | return array();
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | Laravel Payu Api
3 | =========
4 |
5 |
6 | [](https://packagist.org/packages/rasim/payu)
7 |
8 |
9 | Installation
10 | ----
11 |
12 | * In composer.json;
13 |
14 | ```json
15 | "rasim/payu": "dev-master"
16 | ```
17 |
18 | * In app.php
19 |
20 | ```php
21 | 'Rasim\Payu\PayuServiceProvider',
22 | ```
23 |
24 | * and for aliases
25 |
26 | ```php
27 | 'Payu' => 'Rasim\Payu\Facades\Payu',
28 | ```
29 | * Set Config
30 |
31 | ```shell
32 | php artisan config:publish rasim/payu
33 | ```
34 |
35 | Usage
36 | ----
37 |
38 | * Codes
39 |
40 | ```php
41 | // Product Generator
42 | $pname = "Product name";
43 | $pcode = "Product code";
44 | $pinfo = "Product info";
45 | $price = "9.99";
46 | $priceType = "GROSS";
47 | $quantity = "1";
48 | $tax = "18";
49 | $product = Payu::payuProduct($pname,$pcode,$pinfo,$price,$priceType,$quantity,$tax);
50 |
51 | Payu::payulu()->setOrderRef("6112457");
52 | Payu::payulu()->addProduct($product);
53 |
54 | // Address Generator
55 | Payu::payuAddress()->setFirstName('John Adam');
56 | Payu::payuAddress()->setLastName('Doe');
57 | Payu::payuAddress()->setEmail('john.doe@johndoe.com');
58 | Payu::payuAddress()->setCity("Mecidiyeköy"); //Ilce/Semt
59 | Payu::payuAddress()->setState("Istanbul"); //Sehir
60 | Payu::payuAddress()->setCountryCode("TR");
61 |
62 | // Address Definition
63 | Payu::payulu()->setBillingAddress(Payu::payuAddress());
64 | Payu::payulu()->setDestinationAddress(Payu::payuAddress());
65 | Payu::payulu()->setDeliveryAddress(Payu::payuAddress());
66 |
67 | // General Setting
68 | Payu::payulu()->setPaymentCurrency("TRY");
69 | Payu::payulu()->setInstalments("2,3,10,12");
70 | Payu::payulu()->setOrderShipping("");
71 | Payu::payulu()->setBackRef("");
72 | Payu::payulu()->setOrderTimeout("");
73 | Payu::payulu()->setTimeoutUrl("");
74 |
75 | Payu::payulu()->setButtonName('Make Payment');
76 |
77 | // Creating Payment Button
78 | Payu::payulu()->renderPaymentForm();
79 | ```
80 |
81 | ```php
82 | // Payu IPN
83 | echo Payu::payulu()->ipnRequest();
84 | ```
85 |
--------------------------------------------------------------------------------
/src/Rasim/Payu/Classes/PayuProduct.php:
--------------------------------------------------------------------------------
1 | setName($productName);
39 | $this->setCode($productCode);
40 | $this->setInfo($productInfo);
41 | $this->setPrice($productPrice);
42 | $this->setPriceType($productPriceType);
43 | $this->setQuantity($productQuantity);
44 | $this->setTax($productTax);
45 |
46 |
47 | }
48 |
49 | public function addCustomField($fieldName, $fieldValue)
50 | {
51 | if (!$fieldName) {
52 | return 0;
53 | }
54 | $this->customFields[$fieldName] = $fieldValue;
55 |
56 | }
57 |
58 | public function setName($productName)
59 | {
60 | $this->productName = $productName;
61 |
62 | }
63 |
64 | public function setCode($setCode)
65 | {
66 | $this->productCode = $setCode;
67 |
68 | }
69 |
70 | public function setInfo($productInfo)
71 | {
72 | $this->productInfo = $productInfo;
73 |
74 | }
75 |
76 | public function setPrice($productPrice)
77 | {
78 | $this->productPrice = $productPrice;
79 |
80 | }
81 |
82 | public function setPriceType($productPriceType)
83 | {
84 | $this->productPriceType = $productPriceType;
85 |
86 | }
87 |
88 | public function setQuantity($productQuantity)
89 | {
90 | $this->productQuantity = $productQuantity;
91 |
92 | }
93 |
94 | public function setTax($productVat)
95 | {
96 | $this->productVat = $productVat;
97 |
98 | }
99 | }
--------------------------------------------------------------------------------
/src/Rasim/Payu/Classes/PayuAddress.php:
--------------------------------------------------------------------------------
1 | setFirstName($firstName);
41 |
42 | if (!empty($lastName))
43 | $this->setLastName($lastName);
44 |
45 | if (!empty($ciSerial))
46 | $this->setCiSerial($ciSerial);
47 |
48 | if (!empty($ciNumber))
49 | $this->setCiNumber($ciNumber);
50 |
51 | if (!empty($ciIssuer))
52 | $this->setCiIssuer($ciIssuer);
53 |
54 | if (!empty($cnp))
55 | $this->setCnp($cnp);
56 |
57 | if (!empty($company))
58 | $this->setCompany($company);
59 |
60 | if (!empty($fiscalCode))
61 | $this->setFiscalCode($fiscalCode);
62 |
63 | if (!empty($regNumber))
64 | $this->setRegNumber($regNumber);
65 |
66 | if (!empty($bank))
67 | $this->setBank($bank);
68 |
69 | if (!empty($bankAccount))
70 | $this->setBankAccount($bankAccount);
71 |
72 | if (!empty($email))
73 | $this->setEmail($email);
74 |
75 | if (!empty($phone))
76 | $this->setPhone($phone);
77 |
78 | if (!empty($fax))
79 | $this->setFax($fax);
80 |
81 | if (!empty($address))
82 | $this->setAddress($address);
83 |
84 | if (!empty($address2))
85 | $this->setAddress2($address2);
86 |
87 | if (!empty($zipCode))
88 | $this->setZipCode($zipCode);
89 |
90 | if (!empty($city))
91 | $this->setCity($city);
92 |
93 | if (!empty($state))
94 | $this->setState($state);
95 |
96 | if (!empty($countryCode))
97 | $this->setCountryCode($countryCode);
98 |
99 |
100 | }
101 |
102 | public function setFirstName($firstName) {
103 | $this->firstName = $firstName;
104 |
105 | }
106 |
107 | public function setLastName($lastName) {
108 | $this->lastName = $lastName;
109 |
110 | }
111 |
112 | public function setCiSerial($ciSerial) {
113 | $this->ciSerial = $ciSerial;
114 |
115 | }
116 |
117 | public function setCiNumber($ciNumber) {
118 | $this->ciNumber = $ciNumber;
119 |
120 | }
121 |
122 | public function setCiIssuer($ciIssuer) {
123 | $this->ciIssuer = $ciIssuer;
124 |
125 | }
126 |
127 | public function setCnp($cnp) {
128 | $this->cnp = $cnp;
129 |
130 | }
131 |
132 | public function setCompany($company) {
133 | $this->company = $company;
134 |
135 | }
136 |
137 | public function setFiscalCode($fiscalCode) {
138 | $this->fiscalCode = $fiscalCode;
139 |
140 | }
141 |
142 | public function setRegNumber($regNumber) {
143 | $this->regNumber = $regNumber;
144 |
145 | }
146 |
147 | public function setBank($bank) {
148 | $this->bank = $bank;
149 |
150 | }
151 |
152 | public function setBankAccount($bankAccount) {
153 | $this->bankAccount = $bankAccount;
154 |
155 | }
156 |
157 | public function setEmail($email) {
158 | $this->email = $email;
159 |
160 | }
161 |
162 | public function setPhone($phone) {
163 | $this->phone = $phone;
164 |
165 | }
166 |
167 | public function setFax($fax) {
168 | $this->fax = $fax;
169 |
170 | }
171 |
172 | public function setAddress($address) {
173 | $this->address = $address;
174 |
175 | }
176 |
177 | public function setAddress2($address2) {
178 | $this->address2 = $address2;
179 |
180 | }
181 |
182 | public function setZipCode($zipCode) {
183 | $this->zipCode = $zipCode;
184 |
185 | }
186 |
187 | public function setCity($City) {
188 | $this->city = $City;
189 |
190 | }
191 |
192 | public function setState($State) {
193 | $this->state = $State;
194 |
195 | }
196 |
197 | public function setCountryCode($CountryCode) {
198 | $this->countryCode = $CountryCode;
199 |
200 | }
201 | }
--------------------------------------------------------------------------------
/src/Rasim/Payu/Classes/Payulu.php:
--------------------------------------------------------------------------------
1 | _merchantId = $merchantId; // store the merchant id
55 | $this->_secretKey = $secretKey; // store the secretkey
56 | if (empty($merchantId) && empty($secretKey)) {
57 | return 0;
58 | }
59 |
60 | }
61 |
62 | public function setDeliveryAddress(PayuAddress $currentAddress) {
63 | if ($currentAddress) {
64 | $this->_deliveryAddress = $currentAddress;
65 |
66 | }
67 | return 0;
68 | }
69 |
70 | public function setBillingAddress(PayuAddress $currentAddress)
71 | {
72 | $this->_billingAddress = $currentAddress;
73 | }
74 |
75 | public function setDestinationAddress(PayuAddress $currentAddress)
76 | {
77 | $this->_destinationAddress = $currentAddress;
78 | }
79 |
80 | public function addProduct(PayuProduct $currentProduct)
81 | {
82 | if ($currentProduct) {
83 | $this->_allProducts[] = $currentProduct; // add the current product
84 |
85 | }
86 | return 0;
87 | }
88 |
89 | public function renderPaymentInputs()
90 | {
91 | $this->_setOrderDate();
92 | $this->_makeHashString();
93 | $this->_makeHash();
94 | $this->_makeFields();
95 | }
96 |
97 | public function renderPaymentForm($autoSubmit=FALSE)
98 | {
99 | $this->_setOrderDate();
100 |
101 |
102 | $this->_makeHashString();
103 |
104 | $time = time();
105 | error_log("---Payment page sampledan gelen loglar---".$time,0);
106 | error_log($this->_hashString,0);
107 |
108 | $this->_makeHash();
109 | $this->_makeFields();
110 | $this->_makeForm($autoSubmit);
111 |
112 | return $this->_htmlCode;
113 | }
114 |
115 | private function _makeFields()
116 | {
117 | $this->_htmlFormCode .= $this->_addInput('MERCHANT', $this->_merchantId);
118 | $this->_htmlFormCode .= $this->_addInput('ORDER_HASH', $this->_HASH);
119 |
120 | $this->_htmlFormCode .= $this->_addInput('BACK_REF', $this->_BackRef);
121 |
122 | $this->_htmlFormCode .= $this->_addInput('LANGUAGE', $this->_Language);
123 | $this->_htmlFormCode .= $this->_addInput('ORDER_REF', $this->_OrderRef);
124 | $this->_htmlFormCode .= $this->_addInput('INSTALLMENT_OPTIONS', $this->_Instalment);
125 | $this->_htmlFormCode .= $this->_addInput('ORDER_DATE', $this->_OrderDate);
126 |
127 |
128 | $this->_htmlFormCode .= $this->_addInput('DESTINATION_CITY', $this->_destinationAddress->city);
129 | $this->_htmlFormCode .= $this->_addInput('DESTINATION_STATE', (empty($this->_destinationAddress->state) ? "" : $this->_destinationAddress->state));
130 | $this->_htmlFormCode .= $this->_addInput('DESTINATION_COUNTRY', $this->_destinationAddress->countryCode);
131 |
132 | $this->_htmlFormCode .= $this->_addInput('ORDER_SHIPPING', $this->_OrderShipping);
133 |
134 | $this->_htmlFormCode .= $this->_addInput('BILL_FNAME', $this->_billingAddress->firstName);
135 | $this->_htmlFormCode .= $this->_addInput('BILL_LNAME', $this->_billingAddress->lastName);
136 | $this->_htmlFormCode .= $this->_addInput('BILL_CISERIAL', $this->_billingAddress->ciSerial);
137 | $this->_htmlFormCode .= $this->_addInput('BILL_CNP', $this->_billingAddress->cnp);
138 | $this->_htmlFormCode .= $this->_addInput('BILL_COMPANY', $this->_billingAddress->company);
139 | $this->_htmlFormCode .= $this->_addInput('BILL_FISCALCODE', $this->_billingAddress->fiscalCode);
140 | $this->_htmlFormCode .= $this->_addInput('BILL_REGNUMBER', $this->_billingAddress->regNumber);
141 | $this->_htmlFormCode .= $this->_addInput('BILL_BANK', $this->_billingAddress->bank);
142 | $this->_htmlFormCode .= $this->_addInput('BILL_BANKACCOUNT', $this->_billingAddress->bankAccount);
143 | $this->_htmlFormCode .= $this->_addInput('BILL_EMAIL', $this->_billingAddress->email);
144 | $this->_htmlFormCode .= $this->_addInput('BILL_PHONE', $this->_billingAddress->phone);
145 | $this->_htmlFormCode .= $this->_addInput('BILL_FAX', $this->_billingAddress->fax);
146 | $this->_htmlFormCode .= $this->_addInput('BILL_ADDRESS', $this->_billingAddress->address);
147 | $this->_htmlFormCode .= $this->_addInput('BILL_ADDRESS2', $this->_billingAddress->address2);
148 | $this->_htmlFormCode .= $this->_addInput('BILL_ZIPCODE', $this->_billingAddress->zipCode);
149 | $this->_htmlFormCode .= $this->_addInput('BILL_CITY', $this->_billingAddress->city);
150 | $this->_htmlFormCode .= $this->_addInput('BILL_STATE', $this->_billingAddress->state);
151 | $this->_htmlFormCode .= $this->_addInput('BILL_COUNTRYCODE', $this->_billingAddress->countryCode);
152 |
153 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_FNAME', $this->_deliveryAddress->firstName);
154 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_LNAME', $this->_deliveryAddress->lastName);
155 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_CISERIAL', $this->_deliveryAddress->ciSerial);
156 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_CNP', $this->_deliveryAddress->cnp);
157 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_COMPANY', $this->_deliveryAddress->company);
158 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_FISCALCODE', $this->_deliveryAddress->fiscalCode);
159 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_REGNUMBER', $this->_deliveryAddress->regNumber);
160 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_BANK', $this->_deliveryAddress->bank);
161 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_BANKACCOUNT', $this->_deliveryAddress->bankAccount);
162 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_EMAIL', $this->_deliveryAddress->email);
163 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_PHONE', $this->_deliveryAddress->phone);
164 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_FAX', $this->_deliveryAddress->fax);
165 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_ADDRESS', $this->_deliveryAddress->address);
166 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_ADDRESS2', $this->_deliveryAddress->address2);
167 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_ZIPCODE', $this->_deliveryAddress->zipCode);
168 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_CITY', $this->_deliveryAddress->city);
169 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_STATE', $this->_deliveryAddress->state);
170 | $this->_htmlFormCode .= $this->_addInput('DELIVERY_COUNTRYCODE', $this->_deliveryAddress->countryCode);
171 |
172 |
173 |
174 | $this->_htmlFormCode .= $this->_addInput('DISCOUNT', $this->_Discount);
175 | $this->_htmlFormCode .= $this->_addInput('PAY_METHOD', $this->_PayMethod);
176 |
177 | $productIterator = 0;
178 | foreach ($this->_tempProds as $prodCode => $product)
179 | {
180 | $this->_htmlFormCode .=$this->_addInput('ORDER_PNAME[' . $productIterator . ']', $product['prodName']);
181 | $this->_htmlFormCode .=$this->_addInput('ORDER_PCODE[' . $productIterator . ']', $prodCode);
182 | $this->_htmlFormCode .=$this->_addInput('ORDER_PINFO[' . $productIterator . ']', (empty($product['prodInfo']) ? '' : $product['prodInfo']));
183 | $this->_htmlFormCode .=$this->_addInput('ORDER_PRICE[' . $productIterator . ']', $product['prodPrice']);
184 | $this->_htmlFormCode .=$this->_addInput('ORDER_QTY[' . $productIterator . ']', $product['prodQuantity']);
185 | $this->_htmlFormCode .=$this->_addInput('ORDER_VAT[' . $productIterator . ']', $product['prodVat']);
186 | $this->_htmlFormCode .=$this->_addInput('ORDER_PRICE_TYPE[' . $productIterator . ']', $product['prodPriceType']);
187 | $this->_htmlFormCode .=$this->_addInput('LU_COMPLEX_PDISCOUNT_PERC[' . $productIterator . ']',
188 | (empty($product['discount']) ? '' : $product['discount']));
189 |
190 | foreach ($product['customFields'] as $customFieldName => $customFieldValue)
191 | {
192 | $this->_htmlFormCode .=$this->_addInput('ORDER_PCUSTOMFIELD[' . $productIterator . '][' . $customFieldName . ']', $customFieldValue);
193 | }
194 | $productIterator++;
195 | }
196 |
197 | $this->_htmlFormCode .= $this->_addInput('PRICES_CURRENCY', $this->_PriceCurrency);
198 | $this->_htmlFormCode .= $this->_addInput('CURRENCY', $this->_Currency);
199 | $this->_htmlFormCode .= $this->_addInput('DEBUG', "TRUE");
200 | $this->_htmlFormCode .= $this->_addInput('TESTORDER', $this->_TestMode);
201 | $this->_htmlFormCode .= $this->_addInput('AUTOMODE', "1");
202 | $this->_htmlFormCode .= $this->_addInput('ORDER_TIMEOUT', $this->_OrderTimeout);
203 | $this->_htmlFormCode .= $this->_addInput('TIMEOUT_URL', $this->_OrderTimeoutUrl);
204 |
205 | foreach ($this->_customFields as $customFieldName => $customFieldValue)
206 | {
207 | $this->_htmlFormCode .=$this->_addInput(strtoupper($customFieldName), $customFieldValue);
208 | }
209 |
210 | }
211 |
212 | private function _makeForm($autoSubmit=FALSE)
213 | {
214 | $this->_htmlCode .= '
' . "\n";
215 | $this->_htmlCode .=$this->_htmlFormCode;
216 | if ($autoSubmit === FALSE) {
217 | $this->_htmlCode .='' . "\n";
218 | }
219 | $this->_htmlCode .= '';
220 |
221 | if ($autoSubmit === TRUE) {
222 | $this->_htmlCode .= "
223 |
226 | ";
227 | }
228 |
229 | }
230 |
231 | private function _addHashValue($string, $name='')
232 | {
233 | return strlen($string).$string;
234 | }
235 |
236 | private function _makeHashString()
237 | {
238 |
239 | $finalPriveType = '';
240 |
241 | $this->_hashString = $this->_addHashValue($this->_merchantId, 'MerchantId');
242 | $this->_hashString .= $this->_addHashValue($this->_OrderRef, 'OrderRef');
243 | $this->_hashString .= $this->_addHashValue($this->_OrderDate, 'OrderDate');
244 |
245 | foreach ($this->_allProducts as $product) {
246 | $tempProd['prodName'] = $product->productName;
247 | $tempProd['prodInfo'] = $product->productInfo;
248 | $tempProd['prodPrice'] = $product->productPrice;
249 | $tempProd['prodQuantity'] = $product->productQuantity;
250 | $tempProd['prodVat'] = $product->productVat;
251 | $tempProd['prodPriceType'] = $product->productPriceType;
252 | $tempProd['customFields'] = $product->customFields;
253 | $tempProd['discount'] = $product->Discount;
254 |
255 | if (!empty($tempProds[$product->productCode]['prodQuantity'])) {
256 | if ($tempProds[$product->productCode]['prodPrice'] != $product->productPrice) {
257 | $tempProds[$product->productCode] = $tempProd;
258 | } else {
259 | $tempProds[$product->productCode]['prodQuantity']+=$product->productQuantity;
260 | }
261 | } else {
262 | $tempProds[$product->productCode] = $tempProd;
263 | }
264 | }
265 |
266 | $prodNames = '';
267 | $prodInfo = '';
268 | $prodPrice = '';
269 | $prodQuantity = '';
270 | $prodVat = '';
271 | $prodCodes = '';
272 | $finalPriveType = '';
273 | $finalPercDiscount = '';
274 |
275 | $iterator = 0;
276 | foreach ($tempProds as $prodCode => $product) {
277 | $prodNames .= $this->_addHashValue($product['prodName'], 'ProductName[' . $iterator . ']');
278 | $prodInfo .= $this->_addHashValue((empty($product['prodInfo']) ? '' : $product['prodInfo']), 'ProductInfo[' . $iterator . ']');
279 | $prodPrice .= $this->_addHashValue($product['prodPrice'], 'ProductPrice[' . $iterator . ']');
280 | $prodQuantity .= $this->_addHashValue($product['prodQuantity'], 'ProductQuality[' . $iterator . ']');
281 | $prodVat .= $this->_addHashValue($product['prodVat'], 'ProductVat[' . $iterator . ']');
282 | $prodCodes .= $this->_addHashValue($prodCode, 'ProductCode[' . $iterator . ']');
283 | $finalPriveType .= $this->_addHashValue((empty($product['prodPriceType']) ? '' : $product['prodPriceType']), 'ProductPriceType[' . $iterator . ']');
284 | $finalPercDiscount .= $this->_addHashValue((empty($product['discount']) ? '' : $product['discount']), 'ProductPercDiscount[' . $iterator . ']');
285 | $iterator++;
286 | }
287 |
288 | $this->_hashString .=$prodNames;
289 | $this->_hashString .=$prodCodes;
290 | $this->_hashString .=$prodInfo;
291 | $this->_hashString .=$prodPrice;
292 | $this->_hashString .=$prodQuantity;
293 | $this->_hashString .=$prodVat;
294 | $this->_tempProds = $tempProds;
295 |
296 | $this->_hashString .= $this->_addHashValue(($this->checkEmptyVar($this->_OrderShipping) ? '' : $this->_OrderShipping), 'OrderShipping');
297 | $this->_hashString .= $this->_addHashValue(($this->checkEmptyVar($this->_PriceCurrency) ? '' : $this->_PriceCurrency), 'PriceCurrency');
298 | $this->_hashString .= $this->_addHashValue((empty($this->_Discount) ? '' : $this->_Discount), 'Discount');
299 | $this->_hashString .= $this->_addHashValue((empty($this->_destinationAddress->city) ? '' : $this->_destinationAddress->city), 'DestinationCity');
300 | $this->_hashString .= $this->_addHashValue((empty($this->_destinationAddress->state) ? '' : $this->_destinationAddress->state), 'DestinationState');
301 | $this->_hashString .= $this->_addHashValue((empty($this->_destinationAddress->countryCode) ? '' : $this->_destinationAddress->countryCode),
302 | 'DestinationCountryCode');
303 | $this->_hashString .= $this->_addHashValue((empty($this->_PayMethod) ? '' : $this->_PayMethod), 'PayMethod');
304 | $this->_hashString .= $finalPriveType;
305 | $this->_hashString .= $finalPercDiscount;
306 | $this->_hashString .= $this->_addHashValue((empty($this->_Instalment) ? '' : $this->_Instalment), 'Instalment');
307 |
308 | $this->_htmlHashString = $this->_hashString;
309 | $this->_hashString = strip_tags($this->_hashString);
310 |
311 |
312 | }
313 |
314 | private function checkEmptyVar($string)
315 | {
316 | return (strlen(trim($string)) == 0);
317 | }
318 |
319 | private function _makeHash()
320 | {
321 | //echo $this->_hashString."
\n";
322 |
323 | $this->_HASH = self::generateHmac($this->_secretKey, $this->_hashString);
324 | }
325 |
326 | public function setAutoMode()
327 | {
328 | $this->_AutoMode = 1;
329 |
330 | }
331 |
332 |
333 | public function setOrderShipping($val)
334 | {
335 | if (!empty($val) && ($val < 0 || !is_numeric($val))) {
336 | }
337 | $this->_OrderShipping = $val;
338 |
339 | }
340 |
341 | public function setTestMode()
342 | {
343 | $this->_TestMode = TRUE;
344 |
345 | }
346 |
347 | public function setGlobalDiscount($discount)
348 | {
349 | $this->_Discount = $discount;
350 |
351 | }
352 |
353 | public function setInstalments($Instalment)
354 | {
355 | $this->_Instalment = $Instalment;
356 |
357 | }
358 |
359 | public function setLanguage($lang)
360 | {
361 | $this->_Language = $lang;
362 |
363 | }
364 |
365 | public function setOrderRef($refno)
366 | {
367 | $this->_OrderRef = $refno;
368 |
369 | }
370 |
371 | private function _setOrderDate()
372 | {
373 | $this->_OrderDate = date('Y-m-d H:i:s', time());
374 |
375 | }
376 |
377 | public function setPayMethod($payMethod) {
378 | $this->_PayMethod = $payMethod;
379 |
380 | }
381 |
382 | public function setPaymentCurrency($currency) {
383 | $this->_PriceCurrency = $currency;
384 |
385 | }
386 |
387 | public function setCurrency($currency) {
388 | $this->_Currency = $currency;
389 |
390 | }
391 |
392 | public function setOrderTimeout($timeout) {
393 | $this->_OrderTimeout = $timeout;
394 |
395 | }
396 |
397 | public function setTimeoutUrl($url) {
398 | $this->_OrderTimeoutUrl = $url;
399 |
400 | }
401 |
402 | public function setBackRef($url) {
403 | $this->_BackRef = $url;
404 |
405 | }
406 |
407 | public function setTrace() {
408 | $this->_Debug = 1;
409 |
410 | }
411 |
412 | public function addCustomField($fieldName, $fieldValue) {
413 | if (!$fieldName) {
414 | return 0;
415 | }
416 | $this->_customFields[$fieldName] = $fieldValue;
417 |
418 | }
419 |
420 | public function setDebug($debugLevel) {
421 | $this->_debugLevel = $debugLevel;
422 |
423 | }
424 |
425 | public function setQueryUrl($url) {
426 | $this->_luQueryUrl = $url;
427 |
428 | }
429 |
430 | public function setButtonName($val) {
431 | $this->_btnName = $val;
432 |
433 | }
434 |
435 |
436 | private function _addInput($string, $value)
437 | {
438 | return '' . "\n";
439 | }
440 |
441 | public static function generateHmac($key, $data)
442 | {
443 | $b = 64; // byte length for md5
444 | if (strlen($key) > $b) {
445 | $key = pack("H*", md5($key));
446 | }
447 | $key = str_pad($key, $b, chr(0x00));
448 | $ipad = str_pad('', $b, chr(0x36));
449 | $opad = str_pad('', $b, chr(0x5c));
450 | $k_ipad = $key ^ $ipad;
451 | $k_opad = $key ^ $opad;
452 | return md5($k_opad . pack("H*", md5($k_ipad . $data)));
453 | }
454 |
455 | public function ipnRequest()
456 | {
457 | $ipnPid = isset($_POST['IPN_PID']) ? $_POST['IPN_PID'] : '';
458 | $ipnName = isset($_POST['IPN_PNAME']) ? $_POST['IPN_PNAME'] : '';
459 | $ipnDate = isset($_POST['IPN_DATE']) ? $_POST['IPN_DATE'] : '';
460 | $date = date('YmdHis');
461 | $hash =
462 | strlen($ipnPid[0]) . $ipnPid[0] .
463 | strlen($ipnName[0]) . $ipnName[0] .
464 | strlen($ipnDate) . $ipnDate .
465 | strlen($date) . $date;
466 | $hash = hash_hmac('md5', $hash, $this->_secretKey);
467 | $result = '' . $date . '|' . $hash . '';
468 | return $result;
469 | }
470 |
471 | }
472 |
--------------------------------------------------------------------------------