/** * Paypal has sent a notification. * * @return bool */ public function notify() { $response = $this->_sendResponse(); if (!$response) { return false; } if (empty($this->_request->data)) { return false; } $this->_request->data = Arrayor::camelizeIndex($this->_request->data); extract($this->_request->data); parse_str($custom, $custom); if (is_string($response) && strcmp($response, 'VERIFIED') == 0) { if ($paymentStatus == "Completed") { if (!$this->_isTransactionNew($txnId)) { Log::error(__('The txn {0} has already been used.', $txnId), 'paypal'); return false; } if (!$this->_isEmailValid($receiverEmail)) { Log::error(__('The Email {0} is not the same as the config Email {0}.', $receiverEmail, Configure::read('Paypal.mail')), 'paypal'); return false; } if (!$this->_isPriceValid($custom, $mcGross, $tax, $discount)) { Log::error(__('The price does not match with the offer price.'), 'paypal'); return false; } if (!$this->_isCurrencyValid($custom, $mcCurrency)) { Log::error(__('The currency offer does not match with the Paypal currency.'), 'paypal'); return false; } if (!$this->_isDiscountValid($custom, $mcGross, $tax, $discount)) { Log::error(__('The discount offer does not match with the Paypal discount.'), 'paypal'); return false; } //We update the end subscription date of the user. $user = $this->_updateUser($custom); if (!$user) { Log::error(__('Error to update the user.'), 'paypal'); return false; } $custom['discount_id'] = isset($custom['discount_id']) ? $custom['discount_id'] : null; //We save the transaction. $this->_insertTransaction($custom, $mcGross, $tax, $txnId, $firstName . ' ' . $lastName, $addressCountry, $addressCity, $addressStreet); //We save the premium Badge. $badges = $this->_unlockBadges($user); if (!$badges) { return false; } return true; } else { // Statut de paiement: Echec Log::error(__('Status Payment invalid : {0}', $paymentStatus), 'paypal'); return false; } } elseif (is_string($response) && strcmp($response, "INVALID") == 0) { Log::error(__('Response INVALID.'), 'paypal'); return false; } }
/** * test camelizeIndex * * @return void */ public function testCamelizeIndex() { $expected = ['keyIndex' => 1]; $this->assertEquals(Arrayor::camelizeIndex(['key index' => 1]), $expected); $this->assertEquals(Arrayor::camelizeIndex(['key index' => 1]), $expected); $this->assertEquals(Arrayor::camelizeIndex(['key_index' => 1]), $expected); $this->assertFalse(Arrayor::camelizeIndex(null)); $this->assertFalse(Arrayor::camelizeIndex(false)); $this->assertFalse(Arrayor::camelizeIndex('key index')); }