Пример #1
0
 /**
  * Do Recharge the difference request.
  * Returns false on failure or redirects admin back to the order page
  * the necessary actions with the backend transaction are taken in the
  * Callback request processing
  *
  * @param \XLite\Model\Order $order Order which is recharged
  * @param \XLite\Model\Payment\Transaction $parentCardTransaction Trandaction with saved card
  * @param float $amount Amount to recharge
  *
  * @return boolean
  */
 public function doRecharge(\XLite\Model\Order $order, \XLite\Model\Payment\Transaction $parentCardTransaction, $amount)
 {
     $newTransaction = new \XLite\Model\Payment\Transaction();
     $newTransaction->setPaymentMethod($this->getSavedCardsPaymentMethod());
     $newTransaction->setStatus(\XLite\Model\Payment\Transaction::STATUS_INPROGRESS);
     $newTransaction->setDataCell('is_recharge', 'Y', null, 'C');
     $newTransaction->setValue($amount);
     $order->addPaymentTransactions($newTransaction);
     $newTransaction->setOrder($order);
     foreach ($this->paymentSettingsToSave as $field) {
         $key = 'xpc_can_do_' . $field;
         if ($parentCardTransaction->getDataCell($key) && $parentCardTransaction->getDataCell($key)->getValue()) {
             $newTransaction->setDataCell($key, $parentCardTransaction->getDataCell($key)->getValue(), null, 'C');
         }
     }
     $this->copyMaskedCard($parentCardTransaction, $newTransaction);
     $recharge = $this->client->requestPaymentRecharge($parentCardTransaction->getDataCell('xpc_txnid')->getValue(), $newTransaction);
     if ($recharge->isSuccess()) {
         $response = $recharge->getResponse();
         if (self::STATUS_AUTH == $response['status'] || self::STATUS_CHARGED == $response['status']) {
             \XLite\Core\TopMessage::getInstance()->addInfo($response['message'] ? $response['message'] : 'Operation successfull');
             if ($response['transaction_id']) {
                 $newTransaction->setDataCell('xpc_txnid', $response['transaction_id'], 'X-Payments transaction ID', 'C');
             }
         } else {
             \XLite\Core\TopMessage::getInstance()->addError($response['error'] ? $response['error'] : 'Operation failed');
             $newTransaction->setStatus(\XLite\Model\Payment\Transaction::STATUS_FAILED);
         }
     } else {
         $message = 'Operation failed';
         if ($recharge->getError()) {
             $message .= '. ' . $recharge->getError();
         }
         \XLite\Core\TopMessage::getInstance()->addError($message);
         $newTransaction->setStatus(\XLite\Model\Payment\Transaction::STATUS_FAILED);
     }
     \XLite\Core\Database::getEM()->flush();
 }
Пример #2
0
 /**
  * Add payment transaction
  * FIXME: move logic into \XLite\Model\Payment\Transaction
  *
  * @param \XLite\Model\Payment\Method $method Payment method
  * @param float                       $value  Value OPTIONAL
  *
  * @return void
  */
 protected function addPaymentTransaction(\XLite\Model\Payment\Method $method, $value = null)
 {
     if (null === $value || 0 >= $value) {
         $value = $this->getOpenTotal();
     } else {
         $value = min($value, $this->getOpenTotal());
     }
     // Do not add 0 or <0 transactions. This is for a "Payment not required" case.
     if ($value > 0) {
         $transaction = new \XLite\Model\Payment\Transaction();
         $transaction->setPaymentMethod($method);
         \XLite\Core\Database::getEM()->persist($method);
         $this->addPaymentTransactions($transaction);
         $transaction->setOrder($this);
         $transaction->setCurrency($this->getCurrency());
         $transaction->setStatus($transaction::STATUS_INITIALIZED);
         $transaction->setValue($value);
         $transaction->setType($method->getProcessor()->getInitialTransactionType($method));
         if ($method->getProcessor()->isTestMode($method)) {
             $transaction->setDataCell('test_mode', true, 'Test mode');
         }
         \XLite\Core\Database::getEM()->persist($transaction);
     }
 }
Пример #3
0
 /**
  * Create a cart with fake item
  *
  * @param \XLite\Model\Profile $profile Customer's profile for whom the cart is created for
  * @param \XLite\Model\Payment\Method $paymentMethod Payment methood
  * @param \XLite\Model\Currency $currency Currency
  * @param $total Cart total
  * @param $itemName Name of the fake item
  * @param $itemSku SKU of the fake item
  *
  * @return \XLite\Model\Cart
  */
 public function createFakeCart(\XLite\Model\Profile $profile, \XLite\Model\Payment\Method $paymentMethod, \XLite\Model\Currency $currency, $total, $itemName, $itemSku)
 {
     $cart = new \XLite\Model\Cart();
     $cart->setTotal($total);
     $cart->setDate(time());
     $cart->setOrderNumber(\XLite\Core\Database::getRepo('XLite\\Model\\Order')->findNextOrderNumber());
     $cart->setProfile($profile);
     $cart->setCurrency($currency);
     $cart->setPaymentMethod($paymentMethod, $total);
     \XLite\Core\Database::getEM()->persist($cart);
     \XLite\Core\Database::getEM()->flush();
     $item = new \XLite\Model\OrderItem();
     $item->setName($itemName);
     $item->setSku($itemSku);
     $item->setPrice($total);
     $item->setAmount(1);
     $item->setTotal($total);
     $item->setXpcFakeItem(true);
     \XLite\Core\Database::getEM()->persist($item);
     \XLite\Core\Database::getEM()->flush();
     $cart->addItem($item);
     if (count($cart->getPaymentTransactions()) == 0) {
         // We cannot use first open transaction later, so we need to create it
         $transaction = new \XLite\Model\Payment\Transaction();
         $transaction->setPaymentMethod($paymentMethod);
         $transaction->setValue($total);
         $cart->addPaymentTransactions($transaction);
         $transaction->setOrder($cart);
     }
     return $cart;
 }