public function __construct(InterfaceDatabaseConnection $databaseConnection, $paypalIPNValidation = true, $paypalIPNCheckGross = true) { $paypalIPNResponse = $_POST; if (!isset($paypalIPNResponse) || empty($paypalIPNResponse)) { exit; } $this->databaseConnection = $databaseConnection; $currentTransaction = $this->_getTransactionInstance()->get($paypalIPNResponse['custom']); $transactionNotification = new TransactionNotification($databaseConnection); $transactionNotification->populateFromArray($paypalIPNResponse); $currentTransaction->logTransactionNotification($transactionNotification); $currentTransaction->save(); $validation = $currentTransaction->getPayPalDestination() . '?cmd=_notify-validate'; foreach ($paypalIPNResponse as $key => $value) { $validation .= '&' . $key . '=' . $value; } if ($paypalIPNValidation) { $paypalResponse = file_get_contents($validation); } else { $paypalResponse = 'VERIFIED'; } if (isset($paypalResponse['test_ipn']) && $paypalResponse['test_ipn'] == 1 && !$currentTransaction->isSandBoxTransaction()) { $this->isOkay = false; return $this->isOkay; } if ($paypalResponse == 'VERIFIED') { if ($paypalIPNResponse['business'] == $currentTransaction->getBusinessPayPalAccount()) { if ($paypalIPNCheckGross) { if ($paypalIPNResponse['mc_gross'] == $currentTransaction->getTotalCost() && $paypalIPNResponse['mc_currency'] == $currentTransaction->getCurrency()) { $this->isOkay = true; } } else { $this->isOkay = true; } } } if ($this->isOkay == true) { $transactionProcessing = $currentTransaction->getProcessingObject(); $transactionProcessing->setIpnResponse($paypalIPNResponse)->process(); } return $this->isOkay; }
/** * Get a transaction by id * @param $transactionId * @return $this */ public function get($transactionId) { parent::get($transactionId); $transactionItems = new TransactionItem($this->getDatabaseConnection()); $this->_items = $transactionItems->getAllByTransactionId($this->id); $transactionListeners = new TransactionListener($this->getDatabaseConnection()); $this->_listeners = $transactionListeners->getAllByTransactionId($this->id); $transactionNotifications = new TransactionNotification($this->getDatabaseConnection()); $this->_notifications = $transactionNotifications->getAllByTransactionId($this->id); return $this; }
/** * @param array $params simply pass $_POST into * @return Hypercharge\TransactionNotification * @throws Hypercharge\Errors\ArgumentError if $params empty or merchant password not set with Config::set() */ static function notification($params) { $tn = new TransactionNotification($params); $passw = Config::getPassword(); if (empty($passw)) { throw new Errors\ArgumentError('password is not configured! See Hypercharge\\Config::set()'); } $tn->verify($passw); return $tn; }
function testGetTransaction() { XmlSerializer::$sort = false; // prepare post, request, response fixtures $postData = $this->schemaNotification('transaction_notification.json'); $channel_token = $postData['channel_token']; $uid = $postData['unique_id']; $requestXml = $this->schemaRequest('reconcile.xml'); $requestXml = preg_replace('/<unique_id>[^<]+<\\/unique_id>/', "<unique_id>{$uid}</unique_id>", $requestXml); $responseXml = $this->schemaResponse('reconcile.xml'); $responseXml = preg_replace('/<unique_id>[^<]+<\\/unique_id>/', "<unique_id>{$uid}</unique_id>", $responseXml); $this->curlMock()->shouldReceive('xmlPost')->with("https://test.hypercharge.net/reconcile/{$channel_token}", $requestXml)->once()->andReturn($responseXml); // actually test the notification $tn = new TransactionNotification($postData); $this->assertTrue($tn->hasTransaction()); $trx = $tn->getTransaction(); $this->assertIsA($trx, 'Hypercharge\\Transaction'); $this->assertTrue($trx->isApproved()); $this->assertEqual($trx->unique_id, $uid); }