本文整理汇总了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());
}
示例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)));
}
示例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();
}
示例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());
}
示例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);
}
示例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));
}
}