当前位置: 首页>>代码示例>>PHP>>正文


PHP Transaction::getNewInstance方法代码示例

本文整理汇总了PHP中Transaction::getNewInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Transaction::getNewInstance方法的具体用法?PHP Transaction::getNewInstance怎么用?PHP Transaction::getNewInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transaction的用法示例。


在下文中一共展示了Transaction::getNewInstance方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testTransactionCurrencyConverting

 function testTransactionCurrencyConverting()
 {
     $eur = Currency::getNewInstance('EUR');
     $eur->rate->set('3.4528');
     $eur->save();
     $this->products[0]->setPrice($this->usd, '9.99');
     $this->order->addProduct($this->products[0], 1);
     $this->order->save();
     $this->order->changeCurrency($this->usd);
     //$this->order->finalize();
     ActiveRecord::clearPool();
     $order = CustomerOrder::getInstanceByID($this->order->getID(), true);
     $order->loadAll();
     $details = new LiveCartTransaction($order, $eur);
     ActiveRecord::clearPool();
     $order = CustomerOrder::getInstanceByID($this->order->getID(), true);
     $order->loadAll();
     $this->assertEquals($details->amount->get(), '2.89');
     $result = new TransactionResult();
     $result->amount->set($details->amount->get());
     $result->currency->set($details->currency->get());
     $transaction = Transaction::getNewInstance($order, $result);
     $transaction->type->set(Transaction::TYPE_SALE);
     $this->assertEquals($transaction->amount->get(), '9.99');
     $this->assertEquals($transaction->realAmount->get(), '2.89');
     $transaction->save();
     $this->assertFalse((bool) $order->isFinalized->get());
     $order->finalize();
     $this->assertTrue((bool) $order->isFinalized->get());
     $this->assertEquals($order->getPaidAmount(), '9.99');
     $this->assertEquals($order->totalAmount->get(), '9.99');
     $this->assertTrue((bool) $order->isPaid->get());
 }
开发者ID:saiber,项目名称:livecart,代码行数:33,代码来源:TransactionTest.php

示例2: testPaymentMethod

 public function testPaymentMethod()
 {
     ActiveRecordModel::getApplication()->getConfig()->setRuntime('INVENTORY_TRACKING', 'DISABLE');
     $this->product1->isEnabled->set(true);
     $this->product1->save();
     $this->order->addProduct($this->product1, 1);
     $this->order->save();
     ActiveRecord::clearPool();
     $this->order = CustomerOrder::getInstanceById($this->order->getID(), true);
     $this->order->loadAll();
     $this->assertEquals(1, $this->order->getShoppingCartItemCount());
     $condition = DiscountCondition::getNewInstance();
     $condition->isEnabled->set(true);
     $condition->conditionClass->set('RuleConditionPaymentMethodIs');
     $condition->addValue('TESTING');
     $condition->save();
     $this->assertEquals(0, count($this->order->getDiscountConditions(true)));
     $this->order->setPaymentMethod('TESTING');
     $this->assertEquals(1, count($this->order->getDiscountConditions(true)));
     $this->order->setPaymentMethod('AnotherOne');
     $this->assertEquals(0, count($this->order->getDiscountConditions(true)));
     // test finalized order
     ClassLoader::import('library.payment.TransactionResult');
     $transResult = new TransactionResult();
     $transResult->setTransactionType(TransactionResult::TYPE_SALE);
     $transResult->amount->set(10000);
     $transResult->currency->set('USD');
     $transaction = Transaction::getNewInstance($this->order, $transResult);
     $transaction->method->set('TESTING');
     $transaction->save();
     $this->order->finalize();
     ActiveRecord::clearPool();
     $reloaded = CustomerOrder::getInstanceById($this->order->getID(), true);
     $reloaded->loadAll();
     $this->assertTrue($reloaded->isExistingRecord());
     $this->assertEquals(1, $reloaded->getShoppingCartItemCount());
     $this->assertEquals(1, count($reloaded->getDiscountConditions(true)));
     $condition->removeValue('TESTING');
     $condition->addValue('Whatever');
     $condition->save();
     $this->assertEquals(0, count($reloaded->getDiscountConditions(true)));
 }
开发者ID:saiber,项目名称:livecart,代码行数:42,代码来源:DiscountConditionTest.php

示例3: registerPayment

 protected function registerPayment(TransactionResult $result, TransactionPayment $handler)
 {
     // transaction already registered?
     if (Transaction::getInstance($this->order, $result->gatewayTransactionID->get())) {
         $this->session->set('completedOrderID', $this->order->getID());
         return new ActionRedirectResponse('checkout', 'completed');
     }
     $transaction = Transaction::getNewInstance($this->order, $result);
     $transaction->setHandler($handler);
     $transaction->save();
     $this->order->setPaidStatus();
     if ($this->order->isPaid->get()) {
         $this->order->save();
     }
     return $this->finalizeOrder();
 }
开发者ID:saiber,项目名称:livecart,代码行数:16,代码来源:CheckoutController.php

示例4: testPayment

 function testPayment()
 {
     $this->order->addProduct($this->products[0], 1);
     $this->order->addProduct($this->products[1], 1);
     $this->order->save();
     $this->order->finalize();
     $result = new TransactionResult();
     $result->amount->set($this->order->totalAmount->get());
     $result->currency->set($this->order->currency->get()->getID());
     $result->gatewayTransactionID->set('TESTTRANSACTION');
     $result->setTransactionType(TransactionResult::TYPE_SALE);
     $transaction = Transaction::getNewInstance($this->order, $result);
     $transaction->save();
     $this->assertEqual($this->order->totalAmount->get(), $this->order->capturedAmount->get());
 }
开发者ID:saiber,项目名称:livecart,代码行数:15,代码来源:OrderTest.php

示例5: create

 public function create()
 {
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     $request = $this->application->getRequest();
     $orderID = $request->get('orderID');
     $currencyID = $request->get('currencyID');
     $amount = $request->get('amount');
     $method = $request->get('method');
     $gatewayTransactionID = $request->get('gatewayTransactionID');
     if (intval($orderID) <= 0) {
         throw new Exception('Order ID is required');
     }
     if (!isset($currencyID) || !isset($method) || !isset($gatewayTransactionID)) {
         throw new Exception('Complete required fields : currencyID, method, gatewayTransactionID');
     }
     $transaction_result = new TransactionResult();
     $transaction_result->currency->set($currencyID);
     // = $currencyID;
     $transaction_result->amount->set($amount);
     //= $amount;
     $transaction_result->gatewayTransactionID->set($gatewayTransactionID);
     // = $gatewayTransactionID;
     $transaction_result->setTransactionType(TransactionResult::TYPE_SALE);
     $order = CustomerOrder::getInstanceById($orderID);
     $order->loadAll();
     $order_array = $order->toArray();
     $user = User::getInstanceByID($order_array['userID']);
     $user->load();
     $order->user->set($user);
     if ($current_transaction = Transaction::getInstance($order, $gatewayTransactionID)) {
         $current_transaction->method->set($method);
         $current_transaction->save();
     } else {
         $new_transaction = Transaction::getNewInstance($order, $transaction_result);
         $new_transaction->method->set($method);
         $new_transaction->save();
         if (!$this->finalizeOrder($order, $user)) {
             // Create new order for current user
             $new_order = CustomerOrder::getNewInstance($user);
             $new_order->beginTransaction();
             $new_order->save();
             $new_order->commit();
         }
     }
     $parser = $this->getParser();
     $apiFieldNames = $parser->getApiFieldNames();
     $f = new ARSelectFilter();
     $f->mergeCondition(new EqualsCond(new ARFieldHandle('Transaction', 'orderID'), $orderID));
     $transactions = ActiveRecordModel::getRecordSetArray('Transaction', $f);
     $response = new LiveCartSimpleXMLElement('<response datetime="' . date('c') . '"></response>');
     if (false && count($transactions) == 0) {
         throw new Exception('Transactions not found');
     }
     while ($transaction = array_shift($transactions)) {
         $transaction_response = $response->addChild('transaction');
         foreach ($transaction as $k => $v) {
             if (in_array($k, $apiFieldNames)) {
                 $transaction_response->addChild($k, htmlentities($v));
             }
         }
     }
     return new SimpleXMLResponse($response);
 }
开发者ID:saiber,项目名称:www,代码行数:63,代码来源:TransactionApi.php

示例6: processCreditCard

 /**
  * @role update
  */
 public function processCreditCard()
 {
     $order = CustomerOrder::getInstanceById($this->request->get('id'));
     if (!$this->buildCreditCardValidator()->isValid()) {
         return new ActionRedirectResponse('backend.payment', 'ccForm', array('id' => $order->getID()));
     }
     // set up transaction details
     $transaction = new LiveCartTransaction($order, $order->currency->get());
     $transaction->amount->set($this->request->get('amount'));
     // process payment
     $handler = $this->application->getCreditCardHandler($transaction);
     if ($this->request->isValueSet('ccType')) {
         $handler->setCardType($this->request->get('ccType'));
     }
     $handler->setCardData($this->request->get('ccNum'), $this->request->get('ccExpiryMonth'), $this->request->get('ccExpiryYear'), $this->request->get('ccCVV'));
     if ($this->config->get('CC_AUTHONLY')) {
         $result = $handler->authorize();
     } else {
         $result = $handler->authorizeAndCapture();
     }
     if ($result instanceof TransactionResult) {
         $order->isPaid->set(true);
         $transaction = Transaction::getNewInstance($order, $result);
         $transaction->setHandler($handler);
         $transaction->comment->set($this->request->get('comment'));
         $transaction->save();
         if ($order->totalAmount->get() <= $order->capturedAmount->get()) {
             $order->isPaid->set(true);
             $order->save();
         }
         $this->request->set('id', $transaction->getID());
         return $this->getTransactionUpdateResponse();
     } elseif ($result instanceof TransactionError) {
         return new JSONResponse(false, 'failure', $this->translate('_err_processing_cc'));
     } else {
         throw new Exception('Unknown transaction result type: ' . get_class($result));
     }
 }
开发者ID:saiber,项目名称:www,代码行数:41,代码来源:PaymentController.php


注:本文中的Transaction::getNewInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。