public function testSerializeAndUnserialize() { $payment = new Payment(array('customer' => new Customer(array('first_name' => 'Vasya', 'last_name' => 'Pupkin', 'email' => '*****@*****.**')))); $paymentTransaction = new PaymentTransaction(array('status' => PaymentTransaction::STATUS_APPROVED)); $paymentTransaction->addError(new PaynetException('Test exception')); $payment->setStatus(Payment::STATUS_CAPTURE)->addPaymentTransaction($paymentTransaction)->addPaymentTransaction(new PaymentTransaction()); $unserializedPayment = unserialize(serialize($payment)); $paymentTransactions = $unserializedPayment->getPaymentTransactions(); $unserializedTransaction = reset($paymentTransactions); $this->assertEquals(Payment::STATUS_CAPTURE, $unserializedPayment->getStatus()); $this->assertEquals('*****@*****.**', $unserializedPayment->getCustomer()->getEmail()); $this->assertCount(2, $paymentTransactions); $this->assertEquals(PaymentTransaction::STATUS_APPROVED, $unserializedTransaction->getStatus()); $errors = $unserializedTransaction->getErrors(); $this->assertTrue($unserializedTransaction->hasErrors()); $this->assertEquals('Test exception', reset($errors)->getMessage()); }
/** * Transform joomla order to PaynetEasy order * * @param stdClass $joomlaAddress Joomla address * @param string $redirectUrl Url for final payment processing * * @return PaymentTransaction PaynetEasy order */ protected function getPaynetTransaction(stdClass $joomlaAddress, $redirectUrl = null) { $queryConfig = new QueryConfig(); $paynetAddress = new BillingAddress(); $paynetTransaction = new PaymentTransaction(); $paynetPayment = new Payment(); $paynetCustomer = new Customer(); $countryCode = ShopFunctions::getCountryByID($joomlaAddress->virtuemart_country_id, 'country_2_code'); $currencyCode = ShopFunctions::getCurrencyByID($joomlaAddress->order_currency, 'currency_code_3'); $paynetAddress->setCountry($countryCode)->setCity($joomlaAddress->city)->setFirstLine($joomlaAddress->address_1)->setZipCode($joomlaAddress->zip)->setPhone($joomlaAddress->phone_1 ?: '(000) 00-00-00'); if (isset($joomlaAddress->virtuemart_state_id)) { $stateCode = ShopFunctions::getStateByID($joomlaAddress->virtuemart_state_id, 'state_2_code'); $paynetAddress->setState($stateCode); } $paynetCustomer->setEmail($joomlaAddress->email)->setFirstName($joomlaAddress->first_name)->setLastName($joomlaAddress->last_name)->setIpAddress($joomlaAddress->ip_address); $paynetPayment->setClientId($joomlaAddress->order_number)->setDescription($this->getPaynetOrderDescription($joomlaAddress))->setAmount($joomlaAddress->order_total)->setCurrency($currencyCode)->setCustomer($paynetCustomer)->setBillingAddress($paynetAddress); if (isset($joomlaAddress->paynet_order_id)) { $paynetPayment->setPaynetId($joomlaAddress->paynet_order_id); } if (isset($joomlaAddress->payment_status)) { $paynetPayment->setStatus($joomlaAddress->payment_status); } $queryConfig->setEndPoint($this->getConfig('end_point'))->setLogin($this->getConfig('login'))->setSigningKey($this->getConfig('signing_key'))->setGatewayMode($this->getConfig('gateway_mode'))->setGatewayUrlSandbox($this->getConfig('sandbox_gateway'))->setGatewayUrlProduction($this->getConfig('production_gateway')); if (Validator::validateByRule($redirectUrl, Validator::URL, false)) { $queryConfig->setRedirectUrl($redirectUrl)->setCallbackUrl($redirectUrl); } $paynetTransaction->setPayment($paynetPayment)->setQueryConfig($queryConfig); if (isset($joomlaAddress->transaction_status)) { $paynetTransaction->setStatus($joomlaAddress->transaction_status); } return $paynetTransaction; }