Example #1
0
 public function recurringOthers($oldOrder, $newOrder)
 {
     $rc = new Varien_Object();
     $orderId = $oldOrder->getId();
     $newOrder->setIsRecurring(1);
     $trn = Mage::getModel('sagepaysuite2/sagepaysuite_transaction')->loadByParent($orderId);
     $amount = $newOrder->getPayment()->getAmountOrdered();
     try {
         $paymentApi = Mage::getModel('sagepaysuite/api_payment');
         $auth = new Varien_Object();
         $paymentApi->setMcode($paymentApi->realIntegrationCode($trn->getIntegration()));
         $repeat = $paymentApi->repeat($trn, $amount);
         if ($repeat['Status'] == 'OK') {
             $repeatTransaction = clone $trn;
             $repeatTransaction->setId(null)->setOrderId($newOrder->getId())->setReleased(null)->setStatus($repeat['Status'])->setStatusDetail($repeat['StatusDetail'])->setVpsTxId($repeat['VPSTxId'])->setTxAuthNo($repeat['TxAuthNo'])->setSecurityKey($repeat['SecurityKey'])->setIntegration($trn->getIntegration())->setVendorTxCode($repeat['_requestvendor_'])->setVpsProtocol($trn->getVpsProtocol())->setVendorname($trn->getVendorname())->setMode($trn->getMode())->setTxType(strtoupper($repeat['_requesttxtype_']))->setTrnCurrency($trn->getTrnCurrency())->setTrndate($this->getDate())->save();
             $auth = Mage::getModel('sagepaysuite2/sagepaysuite_action')->load($repeat['_requestvendor_'], 'vendor_tx_code');
             $newOrder->getPayment()->setLastTransId($repeat['VPSTxId']);
         } else {
             $rc->setPaymentDetails("ERROR: Could not repeat payment.");
             $rc->setPaymentOK(false);
         }
         if ($auth->getId()) {
             //$rc->setPaymentDetails($auth->getStatusDetail());
             $rc->setPaymentOK(true);
         } else {
             $rc->setPaymentDetails("ERROR: Could not load authorisation.");
             $rc->setPaymentOK(false);
         }
     } catch (Exception $e) {
         $rc->setPaymentDetails($e->getMessage());
         $rc->setPaymentOK(false);
         Mage::logException($e);
     }
     return $rc;
 }