예제 #1
0
 /**
  * Capture (confirm) an open transaction ('AUTHORIZED') at svea. We use the
  * ConfirmTransaction class directly because the operation is simple.
  *
  * @param Varien_Object $payment
  * @param float $amount
  * @return $this|void
  * @throws Mage_Payment_Exception
  */
 public function capture(Varien_Object $payment, $amount)
 {
     $sveaOrderId = $payment->getParentTransactionId();
     if (null === $sveaOrderId) {
         // If there is no previous authorization
         $sveaOrderId = $payment->getTransactionId();
     }
     $order = $payment->getOrder();
     $paymentMethodConfig = $this->getSveaStoreConfClass($order->getStoreId());
     $config = new SveaMageConfigProvider($paymentMethodConfig);
     $countryId = $order->getBillingAddress()->getCountryId();
     $confirmTransactionRequest = new Svea\HostedService\ConfirmTransaction($config);
     $confirmTransactionRequest->countryCode = $countryId;
     $confirmTransactionRequest->transactionId = $sveaOrderId;
     $defaultCaptureDate = explode('T', date('c'));
     // [0] contains date part
     $confirmTransactionRequest->captureDate = $defaultCaptureDate[0];
     $response = $confirmTransactionRequest->doRequest();
     if ($response->accepted !== 1) {
         $message = 'Capture failed for transaction ' . $sveaOrderId . ': ' . $response->errormessage . ' (' . $response->resultcode . ')';
         throw new Mage_Payment_Exception($message);
     }
     $result = $this->_flatten($response);
     $payment->setIsTransactionClosed(true)->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $result);
     return $this;
 }
 /** For authorization **/
 public function authorize(Varien_Object $payment, $amount)
 {
     Mage::log('authorize method', null, 'cmss.log');
     #getOrderid
     $order = $payment->getOrder();
     $billing = $order->getBillingAddress();
     #creating request object for stripe
     $request = array('amount' => $amount * 100, 'currency' => strtolower($order->getBaseCurrencyCode()), 'card' => array('number' => $payment->getCcNumber(), 'exp_month' => sprintf('%02d', $payment->getCcExpMonth()), 'exp_year' => $payment->getCcExpYear(), 'cvc' => $payment->getCcCid(), 'name' => $billing->getName(), 'address_line1' => $billing->getStreet(1), 'address_line2' => $billing->getStreet(2), 'address_zip' => $billing->getPostcode(), 'address_state' => $billing->getRegion(), 'address_country' => $billing->getCountry()), 'description' => sprintf('#%s, %s', $order->getIncrementId(), $order->getCustomerEmail()));
     #request to stripe to charge the card
     try {
         //Stripe::setApiKey('sk_test_4SaT1bB6uEuFF5POEUnsSZHJ');
         $response = Stripe_Charge::create($request);
         Mage::log('authorize method' . print_r($response, true), null, 'cmss.log');
         //$fmessage=$response->failure_code;
         if ($response->paid) {
             $result = 1;
         } else {
             $result = false;
         }
     } catch (Exception $e) {
         $this->debugData($e->getMessage());
         Mage::throwException(Mage::helper('paygate')->__($e->getMessage()));
     }
     if ($result === false) {
         $errorCode = 'Invalid Data';
         $errorMsg = $this->_getHelper()->__('Error Processing the request');
     } else {
         Mage::log($result, null, $this->getCode() . '.log');
         //process result here to check status etc as per payment gateway.
         // if invalid status throw exception
         if ($result == 1) {
             //Mage::log('sdsd'.$response->id, null, 'cmss.log');
             $payment->setTransactionId($response->id);
             $payment->setIsTransactionClosed(1);
             $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('key1' => 'value1', 'key2' => 'value2'));
             //
         } else {
             Mage::throwException($errorMsg);
         }
         // Add the comment and save the order
     }
     if ($errorMsg) {
         Mage::throwException($errorMsg);
     }
     $this->capture($payment, $order->getGrandTotal());
     // Create invoice
     $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice(array());
     $invoice->register();
     $invoice->setCanVoidFlag(true);
     $invoice->getOrder()->setIsInProcess(true);
     $invoice->setState(2);
     if (Mage::helper('sales')->canSendNewInvoiceEmail($order->getStoreId())) {
         $invoice->setEmailSent(true);
         $invoice->sendEmail();
     }
     $invoice->save();
     $order->setTotalPaid($order->getBaseGrandTotal());
     $order->addStatusHistoryComment('Captured online amount of R$' . $order->getBaseGrandTotal(), false);
     $order->save();
     //Mage::log($response->id, null, 'mss.log');
     return $this;
 }
 /**
  * Authorize and Capture
  *
  * @param Varien_Object $payment
  * @param float $amount
  *
  * @return Amazon_Payments_Model_PaymentMethod
  */
 public function capture(Varien_Object $payment, $amount)
 {
     $transactionAuth = $payment->lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH);
     $authReferenceId = $transactionAuth->getTxnId();
     $order = $payment->getOrder();
     $result = $this->_getApi($order->getStoreId())->capture($authReferenceId, $authReferenceId, $amount, $order->getBaseCurrencyCode(), $this->_getSoftDescriptor());
     if ($result) {
         $status = $result->getCaptureStatus();
         // Error handling
         switch ($status->getState()) {
             case Amazon_Payments_Model_Api::AUTH_STATUS_PENDING:
                 Mage::getSingleton('adminhtml/session')->addError('The invoice you are trying to create is for an authorization that is more than 7 days old. A capture request has been made. Please try and create this invoice again in 1 hour, allowing time for the capture to process.');
                 // cont'd...
             // cont'd...
             case Amazon_Payments_Model_Api::AUTH_STATUS_DECLINED:
             case Amazon_Payments_Model_Api::AUTH_STATUS_CLOSED:
                 $this->_setErrorCheck();
                 Mage::throwException('Amazon Payments capture error: ' . $status->getReasonCode() . ' - ' . $status->getReasonDescription());
                 break;
             case Amazon_Payments_Model_Api::AUTH_STATUS_COMPLETED:
                 // Already captured.
                 break;
             default:
                 $this->_setErrorCheck();
                 Mage::throwException('Amazon Payments capture error.');
                 break;
         }
         $payment->setTransactionId($result->getAmazonCaptureId());
         $payment->setParentTransactionId($authReferenceId);
         $payment->setIsTransactionClosed(false);
     } else {
         $this->_setErrorCheck();
         Mage::throwException('Unable to capture payment at this time. Please try again later.');
     }
     return $this;
 }
예제 #4
0
 public function capture(Varien_Object $payment, $amount)
 {
     $session = Mage::getSingleton('core/session');
     $logger = Mage::helper('worldpay/logger');
     if ($session->getData('wp_3dscompletionNeeded')) {
         $payment->setIsTransactionClosed(0);
         $payment->setSkipOrderProcessing(true);
         $payment->setStatus(self::STATUS_APPROVED);
         $payment->setAmount($amount);
         $payment->setShouldCloseParentTransaction(1);
         $payment->setAdditionalInformation("worldpayOrderCode", $session->getData('wp_orderCode'));
         $payment->setLastTransId($session->getData('wp_orderCode'));
         $payment->setTransactionId($session->getData('wp_orderCode'));
         $session->setData('wp_3dscompletionNeeded', false);
         return $this;
     }
     $worldpayOrderCode = $payment->getData('last_trans_id');
     if ($worldpayOrderCode) {
         $worldpay = $this->setupWorldpay();
         try {
             $authorizationTransaction = $payment->getAuthorizationTransaction();
             if ($authorizationTransaction) {
                 $payment->setAdditionalInformation("worldpayOrderCode", $authorizationTransaction->getTxnId());
                 $worldpayOrderCode = $authorizationTransaction->getTxnId();
             } else {
                 $worldpayOrderCode = $payment->getAdditionalInformation('worldpayOrderCode');
             }
             $worldpay->captureAuthorisedOrder($worldpayOrderCode, $amount * 100);
             $payment->setShouldCloseParentTransaction(1)->setIsTransactionClosed(1);
             $logger->log('Capture Order: ' . $session->getData('wp_orderCode') . ' success');
         } catch (Exception $e) {
             $logger->log('Capture Order: ' . $session->getData('wp_orderCode') . ' failed with ' . $e->getMessage());
             Mage::throwException('Payment failed, please try again later ' . $e->getMessage());
         }
     } else {
         $payment->setAdditionalInformation('payment_type', 'capture');
         return $this->createOrder($payment, $amount, false);
     }
 }
예제 #5
0
 /**
  * Refund money
  *
  * @param   Varien_Object $payment
  * @param   float $amount
  * @return  Mage_Payment_Model_Abstract
  */
 public function refund(Varien_Object $payment, $amount)
 {
     //parent::refund($payment, $amount);
     $captureTxnId = $payment->getParentTransactionId();
     if ($captureTxnId) {
         $order = $payment->getOrder();
         $request = $this->_getApiRequest();
         $request->setData('transaction_id', $captureTxnId)->setData('amount', $amount)->setData('currency_code', $order->getBaseCurrencyCode())->setData('cc_number', $payment->getCcLast4());
         $canRefundMore = $order->canCreditmemo();
         $allRefunds = (double) $amount + (double) $order->getBaseTotalOnlineRefunded() + (double) $order->getBaseTotalOfflineRefunded();
         $isFullRefund = !$canRefundMore && 0.0001 > (double) $order->getBaseGrandTotal() - $allRefunds;
         $request->setData('is_full_refund', (int) $isFullRefund);
         // whether to close capture transaction
         $invoiceCanRefundMore = $payment->getCreditmemo()->getInvoice()->canRefund();
         $payment->setShouldCloseParentTransaction($invoiceCanRefundMore ? 0 : 1);
         $payment->setIsTransactionClosed(1);
         $api = $this->_getApi()->doRefund($request);
         $this->_importResultToPayment($payment, $api->getResponse());
         return $api->getResponse();
     } else {
         Mage::throwException(Mage::helper('enterprise_pbridge')->__('Impossible to issue a refund transaction, because capture transaction does not exist.'));
     }
 }
예제 #6
0
 /**
  * Void payment abstract method
  *
  * @param Varien_Object $payment
  *
  * @return Mage_Payment_Model_Abstract
  */
 public function void(Varien_Object $payment)
 {
     try {
         // Init the environment
         $this->_getWrapper()->init($payment->getOrder()->getStoreId());
         // Retrieve the transaction ID
         $transactionId = $this->_getWrapper()->getCleanTransactionId($payment->getLastTransId());
         // Load the transaction from Braintree
         $transaction = Braintree_Transaction::find($transactionId);
         // If the transaction hasn't yet settled we can't do partial refunds
         if ($transaction->status !== Braintree_Transaction::AUTHORIZED || $transaction->status !== Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
             Mage::throwException($this->_getHelper()->__('You can only void authorized/submitted for settlement payments, please setup a credit memo if you wish to refund this order.'));
         }
         // Swap between refund and void
         $result = Braintree_Transaction::void($transactionId);
         // If it's a success close the transaction
         if ($result->success) {
             $payment->setIsTransactionClosed(1);
         } else {
             if ($result->errors->deepSize() > 0) {
                 Mage::throwException($this->_getWrapper()->parseErrors($result->errors->deepAll()));
             } else {
                 Mage::throwException('Unknown');
             }
         }
     } catch (Exception $e) {
         Mage::throwException($this->_getHelper()->__('An error occurred whilst trying to void the transaction: ') . $e->getMessage());
     }
     return $this;
 }
예제 #7
0
 public function refund(Varien_Object $payment, $amount)
 {
     if (Mage::getStoreConfig('billmate/settings/activation')) {
         $k = Mage::helper('billmateinvoice')->getBillmate(true, false);
         $invoiceId = $payment->getMethodInstance()->getInfoInstance()->getAdditionalInformation('invoiceid');
         $values = array('number' => $invoiceId);
         $paymentInfo = $k->getPaymentInfo($values);
         if ($paymentInfo['PaymentData']['status'] == 'Paid' || $paymentInfo['PaymentData']['status'] == 'Factoring') {
             $values['partcredit'] = false;
             $result = $k->creditPayment(array('PaymentData' => $values));
             if (isset($result['code'])) {
                 Mage::throwException(utf8_encode($result['message']));
             }
             if (!isset($result['code'])) {
                 $payment->setTransactionId($result['number']);
                 $payment->setIsTransactionClosed(1);
             }
         }
     }
     return $this;
 }
예제 #8
0
파일: Payment.php 프로젝트: rcclaudrey/dev
 /**
  * Authorize or Capture payment
  *
  * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
  * @param float $amount
  * @param bool $capture
  * @return  $this
  */
 private function _authorize(Varien_Object $payment, $amount, $capture)
 {
     $order = $payment->getOrder();
     /* @var $order Mage_Sales_Model_Order */
     $multiToken = false;
     $cardData = null;
     $additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null);
     $secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null;
     $saveCreditCard = !!(bool) $additionalData->getCcSaveFuture();
     $customerId = $additionalData->getCustomerId();
     if ($saveCreditCard) {
         $multiToken = true;
         $cardData = new HpsCreditCard();
         $cardData->number = $payment->getCcLast4();
         $cardData->expYear = $payment->getCcExpYear();
         $cardData->expMonth = $payment->getCcExpMonth();
     }
     $chargeService = $this->_getChargeService();
     $cardHolder = $this->_getCardHolderData($order);
     $details = $this->_getTxnDetailsData($order);
     $cardOrToken = new HpsTokenData();
     $cardOrToken->tokenValue = $secureToken;
     try {
         if ($capture) {
             if ($payment->getCcTransId()) {
                 $response = $chargeService->capture($payment->getCcTransId(), $amount);
             } else {
                 $response = $chargeService->charge($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
             }
         } else {
             $response = $chargeService->authorize($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
         }
         $this->_debugChargeService($chargeService);
         $payment->setStatus(self::STATUS_APPROVED);
         $payment->setAmount($amount);
         $payment->setLastTransId($response->transactionId);
         $payment->setCcTransId($response->transactionId);
         $payment->setTransactionId($response->transactionId);
         $payment->setIsTransactionClosed(0);
         if ($multiToken) {
             $tokenData = $response->tokenData;
             /* @var $tokenData HpsTokenData */
             if ($tokenData->responseCode == '0') {
                 if ($customerId > 0) {
                     Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType, $customerId);
                 } else {
                     Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType);
                 }
             } else {
                 Mage::log('Requested multi token has not been generated for the transaction # ' . $response->transactionId, Zend_Log::WARN);
             }
         }
     } catch (HpsCreditException $e) {
         Mage::logException($e);
         $this->_debugChargeService($chargeService, $e);
         $payment->setStatus(self::STATUS_DECLINED);
         $this->throwUserError($e->getMessage(), $e->resultText, TRUE);
     } catch (HpsException $e) {
         $this->_debugChargeService($chargeService, $e);
         $payment->setStatus(self::STATUS_ERROR);
         $this->throwUserError($e->getMessage(), NULL, TRUE);
     } catch (Exception $e) {
         $this->_debugChargeService($chargeService, $e);
         Mage::logException($e);
         $payment->setStatus(self::STATUS_ERROR);
         $this->throwUserError($e->getMessage());
     }
     return $this;
 }
 /**
  * Voids transaction
  * 
  * @param Varien_Object $payment
  * @return Braintree_Payments_Model_Paymentmethod
  */
 public function void(Varien_Object $payment)
 {
     $transactionIds = array();
     $invoice = Mage::registry('current_invoice');
     $message = false;
     if ($invoice && $invoice->getId() && $invoice->getTransactionId()) {
         $transactionIds[] = Mage::helper('braintree_payments')->clearTransactionId($invoice->getTransactionId());
     } else {
         $collection = Mage::getModel('sales/order_payment_transaction')->getCollection()->addFieldToSelect('txn_id')->addOrderIdFilter($payment->getOrder()->getId())->addTxnTypeFilter(array(Mage_Sales_Model_Order_Payment_Transaction::TYPE_AUTH, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE));
         $fetchedIds = $collection->getColumnValues('txn_id');
         foreach ($fetchedIds as $transactionId) {
             $txnId = Mage::helper('braintree_payments')->clearTransactionId($transactionId);
             if (!in_array($txnId, $transactionIds)) {
                 $transactionIds[] = $txnId;
             }
         }
     }
     foreach ($transactionIds as $transactionId) {
         $transaction = Braintree_Transaction::find($transactionId);
         if ($transaction->status !== Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT && $transaction->status !== Braintree_Transaction::AUTHORIZED) {
             $message = Mage::helper('braintree_payments')->__('Some transactions are already settled or voided and cannot be voided.');
             throw new Mage_Core_Exception($message, self::VOID_ALREADY_SETTLED_EXCEPTION);
         }
         if ($transaction->status === Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
             $message = Mage::helper('braintree_payments')->__('Voided capture.');
         }
     }
     $errors = '';
     foreach ($transactionIds as $transactionId) {
         $this->_debug('void-' . $transactionId);
         $result = Braintree_Transaction::void($transactionId);
         $this->_debug($result);
         if (!$result->success) {
             $errors .= ' ' . Mage::helper('braintree_payments/error')->parseBraintreeError($result);
         } else {
             if ($message) {
                 $payment->setMessage($message);
             }
         }
     }
     if ($errors) {
         Mage::throwException(Mage::helper('braintree_payments')->__('There was an error voiding the transaction.') . $errors);
     } else {
         $match = true;
         foreach ($transactionIds as $transactionId) {
             $collection = Mage::getModel('sales/order_payment_transaction')->getCollection()->addFieldToFilter('parent_txn_id', array('eq' => $transactionId))->addFieldToFilter('txn_type', Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID);
             if ($collection->getSize() < 1) {
                 $match = false;
             }
         }
         if ($match) {
             $payment->setIsTransactionClosed(1);
         }
     }
     return $this;
 }
예제 #10
0
 /**
  * Refund specified amount for payment
  *
  * @param \Varien_Object $payment
  * @param float          $amount
  *
  * @return $this
  * @throws \Mage_Core_Exception
  */
 public function refund(Varien_Object $payment, $amount)
 {
     try {
         // Attempt to load the invoice
         /* @var $invoice Mage_Sales_Model_Order_Invoice */
         $invoice = $payment->getCreditmemo()->getInvoice();
         if (!$invoice) {
             Mage::throwException('Unable to load invoice from credit memo.');
         }
         // Init the environment
         $this->_getWrapper()->init($payment->getOrder()->getStoreId());
         // Convert the refund amount
         $refundAmount = $this->_getWrapper()->getCaptureAmount($payment->getOrder(), $amount);
         // Retrieve the transaction ID
         $transactionId = $this->_getWrapper()->getCleanTransactionId($invoice->getTransactionId());
         // Load the transaction from Braintree
         $transaction = Braintree_Transaction::find($transactionId);
         // If the transaction hasn't yet settled we can't do partial refunds
         if ($transaction->status === Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT) {
             // If we're doing a partial refund and it's not settled it's a no go
             if ($transaction->amount != $refundAmount) {
                 Mage::throwException($this->_getHelper()->__('This transaction has not yet settled, please wait until the transaction has settled to process a partial refund.'));
             }
         }
         // Swap between refund and void
         $result = $transaction->status === Braintree_Transaction::SETTLED || $transaction->status == Braintree_Transaction::SETTLING || isset($transaction->paypal) && isset($transaction->paypal['paymentId']) && !empty($transaction->paypal['paymentId']) ? Braintree_Transaction::refund($transactionId, $refundAmount) : Braintree_Transaction::void($transactionId);
         // If it's a success close the transaction
         if ($result->success) {
             // Pass over the transaction ID
             $payment->getCreditmemo()->setRefundTransactionId($result->transaction->id);
             // Only close the transaction once the
             if ($transaction->amount == $refundAmount) {
                 $payment->setIsTransactionClosed(1);
                 // Mark the invoice as canceled if the invoice was completely refunded
                 $invoice->setState(Mage_Sales_Model_Order_Invoice::STATE_CANCELED);
             }
         } else {
             if ($result->errors->deepSize() > 0) {
                 Mage::throwException($this->_getWrapper()->parseErrors($result->errors->deepAll()));
             } else {
                 Mage::throwException('An unknown error has occurred whilst trying to process the transaction');
             }
         }
     } catch (Exception $e) {
         Mage::throwException($this->_getHelper()->__('An error occurred whilst trying to process the refund: ') . $e->getMessage());
     }
     return $this;
 }
예제 #11
0
 /**
  * The transaction is captured with the specified amount.
  *
  * @param Varien_Object $payment The payment object containing all the payment specific data for the order.
  * @param unknown_type $amount The amount to capture. This may be less than the amount of the order but not more.
  * @return Customweb_SaferpayCw_Model_Method
  */
 public function capture(Varien_Object $payment, $amount)
 {
     $invoice = Mage::registry('current_invoice');
     try {
         $transaction = $this->getHelper()->loadTransactionByPayment($payment->getId());
         $order = $payment->getOrder();
         Customweb_SaferpayCw_Model_ConfigurationAdapter::setStore($order);
         $adapter = $this->getHelper()->createContainer()->getBean('Customweb_Payment_BackendOperation_Adapter_Service_ICapture');
         if ($transaction->getTransactionObject()->isCapturePossible()) {
             if ($transaction->getTransactionObject()->isPartialCapturePossible()) {
                 if ($invoice instanceof Mage_Sales_Model_Order_Invoice) {
                     $items = $this->getInvoiceItems($invoice);
                 } else {
                     $items = Customweb_Util_Invoice::getItemsByReductionAmount($transaction->getTransactionObject()->getTransactionContext()->getOrderContext()->getInvoiceItems(), $amount, $transaction->getTransactionObject()->getCurrencyCode());
                 }
                 $adapter->partialCapture($transaction->getTransactionObject(), $items, true);
             } else {
                 $adapter->capture($transaction->getTransactionObject());
             }
             $transaction->save();
         }
         if ($transaction->getTransactionObject()->isCaptured()) {
             $payment->setIsTransactionClosed(false);
             $captures = $transaction->getTransactionObject()->getCaptures();
             $capture = end($captures);
             $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('TRANSACTIONID' => $transaction->getTransactionObject()->getPaymentId(), 'CAPTUREID' => $capture->getCaptureId(), 'AMOUNT' => $capture->getAmount(), 'AMT' => $capture->getAmount(), 'STATUS' => $capture->getStatus()));
             $this->_generateTransactionId($payment, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE);
             return $this;
         } else {
             $this->getHelper()->log("Capture failed. Transaction error messages : " . print_r($transaction->getTransactionObject()->getErrorMessages(), true));
             $messages = $transaction->getTransactionObject()->getErrorMessages();
             Mage::throwException($this->getHelper()->__('The invoice could not be captured and processed. Reason: ') . end($messages));
         }
     } catch (Exception $e) {
         $this->getHelper()->log("Exception in Method::capture() : " . $e->getMessage());
         Mage::getSingleton('core/session')->addError($e->getMessage());
         throw $e;
     }
 }
 /**
  * Authorize or Capture payment
  *
  * @param Varien_Object|Mage_Sales_Model_Order_Payment $payment
  * @param float $amount
  * @param bool $capture
  * @return  $this
  */
 private function _authorize(Varien_Object $payment, $amount, $capture)
 {
     $order = $payment->getOrder();
     /* @var $order Mage_Sales_Model_Order */
     $multiToken = false;
     $cardData = null;
     $additionalData = new Varien_Object($payment->getAdditionalData() ? unserialize($payment->getAdditionalData()) : null);
     $secureToken = $additionalData->getSecuresubmitToken() ? $additionalData->getSecuresubmitToken() : null;
     $saveCreditCard = !!(bool) $additionalData->getCcSaveFuture();
     $customerId = $additionalData->getCustomerId();
     $giftService = $this->_getGiftService();
     $giftCardNumber = $additionalData->getGiftcardNumber();
     if ($giftCardNumber) {
         // 1. check balance
         $giftcard = new HpsGiftCard();
         $giftcard->number = $giftCardNumber;
         $giftResponse = $giftService->balance($giftcard);
         // 2. is balance > amount?
         if ($giftResponse->balanceAmount > $amount) {
             //  2.yes. process full to gift
             try {
                 if (strpos($this->getConfigData('secretapikey'), '_cert_') !== false) {
                     $giftresp = $giftService->sale($giftcard, 10.0);
                 } else {
                     $giftresp = $giftService->sale($giftcard, $amount);
                 }
                 $order->addStatusHistoryComment('Used Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $amount . '. [full payment]');
                 $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('gift_card_number' => $giftCardNumber, 'gift_card_transaction' => $giftresp->transactionId, 'gift_card_amount_charged' => $amount));
                 $payment->setStatus(self::STATUS_APPROVED);
                 $payment->setAmount($amount);
                 $payment->setLastTransId($response->transactionId);
                 $payment->setTransactionId($response->transactionId);
                 $payment->setIsTransactionClosed(0);
                 return $this;
             } catch (Exception $e) {
                 Mage::logException($e);
                 $payment->setStatus(self::STATUS_ERROR);
                 $this->throwUserError($e->getMessage(), null, true);
             }
         } else {
             //  2.no. process full gift card amt and card process remainder
             $giftresp = $giftService->sale($giftcard, $giftResponse->balanceAmount);
             $order->addStatusHistoryComment('Used Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $giftResponse->balanceAmount . '. [partial payment]')->save();
             $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('gift_card_number' => $giftCardNumber, 'gift_card_transaction' => $giftresp->transactionId, 'gift_card_amount_charged' => $giftResponse->balanceAmount));
             $payment->setAmount($giftResponse->balanceAmount)->save();
             $amount = $amount - $giftResponse->balanceAmount;
             // remainder
             // 3. TODO: if the card payment fails later, refund the gift transaction
         }
     }
     if ($saveCreditCard) {
         $multiToken = true;
         $cardData = new HpsCreditCard();
         $cardData->number = $payment->getCcLast4();
         $cardData->expYear = $payment->getCcExpYear();
         $cardData->expMonth = $payment->getCcExpMonth();
     }
     $chargeService = $this->_getChargeService();
     $cardHolder = $this->_getCardHolderData($order);
     $details = $this->_getTxnDetailsData($order);
     $cardOrToken = new HpsTokenData();
     $cardOrToken->tokenValue = $secureToken;
     try {
         if ($capture) {
             if ($payment->getCcTransId()) {
                 $response = $chargeService->capture($payment->getCcTransId(), $amount);
             } else {
                 $response = $chargeService->charge($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
             }
         } else {
             $response = $chargeService->authorize($amount, strtolower($order->getBaseCurrencyCode()), $cardOrToken, $cardHolder, $multiToken, $details);
         }
         $this->_debugChargeService($chargeService);
         $payment->setStatus(self::STATUS_APPROVED);
         $payment->setAmount($amount);
         $payment->setLastTransId($response->transactionId);
         $payment->setCcTransId($response->transactionId);
         $payment->setTransactionId($response->transactionId);
         $payment->setIsTransactionClosed(0);
         if ($giftCardNumber) {
             $order->addStatusHistoryComment('Remaining amount to be charged to credit card  ' . $this->_formatAmount($amount) . '. [partial payment]')->save();
         }
         if ($multiToken) {
             $tokenData = $response->tokenData;
             /* @var $tokenData HpsTokenData */
             if ($tokenData->responseCode == '0') {
                 if ($customerId > 0) {
                     Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType, $customerId);
                 } else {
                     Mage::helper('hps_securesubmit')->saveMultiToken($response->tokenData->tokenValue, $cardData, $response->cardType);
                 }
             } else {
                 Mage::log('Requested multi token has not been generated for the transaction # ' . $response->transactionId, Zend_Log::WARN);
             }
         }
     } catch (HpsCreditException $e) {
         Mage::logException($e);
         $this->getFraudSettings();
         $this->_debugChargeService($chargeService, $e);
         // refund gift (if used)
         if ($giftCardNumber) {
             $order->addStatusHistoryComment('Reversed Heartland Gift Card ' . $giftCardNumber . ' for amount $' . $giftResponse->balanceAmount . '. [full reversal]')->save();
             $giftResponse = $giftService->reverse($giftcard, $giftResponse->balanceAmount);
         }
         if ($this->_allow_fraud && $e->getCode() == HpsExceptionCodes::POSSIBLE_FRAUD_DETECTED) {
             // we can skip the card saving if it fails for possible fraud there will be no token.
             if ($this->_email_fraud && $this->_fraud_address != '') {
                 // EMAIL THE PEOPLE
                 $this->sendEmail($this->_fraud_address, $this->_fraud_address, 'Suspicious order (' . $order->getIncrementId() . ') allowed', 'Hello,<br><br>Heartland has determined that you should review order ' . $order->getRealOrderId() . ' for the amount of ' . $amount . '.');
             }
             $payment->setStatus(self::STATUS_APPROVED);
             $payment->setAmount($amount);
             $payment->setIsTransactionClosed(0);
         } else {
             $payment->setStatus(self::STATUS_ERROR);
             if ($e->getCode() == HpsExceptionCodes::POSSIBLE_FRAUD_DETECTED) {
                 $this->throwUserError($this->_fraud_text, null, true);
             } else {
                 $this->throwUserError($e->getMessage(), null, true);
             }
         }
     } catch (HpsException $e) {
         $this->_debugChargeService($chargeService, $e);
         $payment->setStatus(self::STATUS_ERROR);
         $this->throwUserError($e->getMessage(), null, true);
     } catch (Exception $e) {
         $this->_debugChargeService($chargeService, $e);
         Mage::logException($e);
         $payment->setStatus(self::STATUS_ERROR);
         $this->throwUserError($e->getMessage());
     }
     return $this;
 }
 public function void(Varien_Object $payment)
 {
     try {
         $result = Braintree_Transaction::void($payment->getCcTransId());
         if ($result->success) {
             $payment->setIsTransactionClosed(1);
         } else {
             Mage::throwException($result->message);
         }
     } catch (Exception $e) {
         Mage::throwException(sprintf('There was an error voiding the transaction. (%s)', $e->getMessage()));
     }
     return $this;
 }
예제 #14
0
 /**
  * Authorize payment abstract method
  *
  * @param Varien_Object $payment
  * @param float $amount
  *
  * @return Mage_Payment_Model_Abstract
  */
 public function authorize(Varien_Object $payment, $amount)
 {
     // Leave the transaction opened so it can later be captured in backend
     $payment->setIsTransactionClosed(false);
     $this->_doOpenpayTransaction($payment, $amount, false);
     return $this;
 }
예제 #15
0
 /**
  * Authorize a payment
  *
  * @param Varien_Object $payment
  * @param float $amount
  *
  * @return Mage_Payment_Model_Abstract
  */
 public function authorize(Varien_Object $payment, $amount)
 {
     if (!$this->_isBackendOrder) {
         if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
             $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
             $payment->setTransactionId($transID);
             $payment->setIsTransactionClosed(0);
             Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
             return $this;
         } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
             //$payment->setTransactionId(Mage::getSingleton('core/session')->getTransactionId());
             Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
             return $this;
         }
     }
     /* @var Mage_Sales_Model_Order_Payment $payment */
     if ($amount <= 0) {
         Mage::throwException(Mage::helper('paygate')->__('Invalid amount for authorize.'));
     }
     $request = Mage::getModel('ewayrapid/request_token');
     /** @todo there's an error in case recurring profile */
     if (!$payment->getIsRecurring()) {
         $this->_shouldCreateOrUpdateToken($payment, $request);
     }
     $amount = round($amount * 100);
     $request->doAuthorisation($payment, $amount);
     return $this;
 }
 /**
  * Order payment method
  *
  * @param Varien_Object $payment
  * @param float $amount
  *
  * @return Amazon_Payments_Model_PaymentMethod
  */
 public function order(Varien_Object $payment, $amount)
 {
     if (!$amount) {
         return $this;
     }
     $orderReferenceId = $payment->getAdditionalInformation('order_reference');
     if (!$orderReferenceId) {
         $orderReferenceId = Mage::getSingleton('checkout/session')->getAmazonOrderReferenceId();
         if (!$orderReferenceId) {
             Mage::throwException('Please log in to your Amazon account by clicking the Amazon pay button.');
         }
         $payment->setAdditionalInformation('order_reference', $orderReferenceId);
     }
     $payment->setTransactionId($orderReferenceId);
     $order = $payment->getOrder();
     // If previous order submission failed (e.g. bad credit card), must validate order status to prevent multiple setOrderReferenceDetails()
     if ($this->_getErrorCheck()) {
         $orderReferenceDetails = $this->_getApi()->getOrderReferenceDetails($orderReferenceId);
     }
     if (!$this->_getErrorCheck() || $orderReferenceDetails->getOrderReferenceStatus()->getState() == 'Draft') {
         $apiResult = $this->_getApi()->setOrderReferenceDetails($orderReferenceId, $order->getBaseGrandTotal(), $order->getBaseCurrencyCode(), $order->getIncrementId(), $this->_getApi()->getConfig()->getStoreName());
     }
     try {
         $apiResult = $this->_getApi()->confirmOrderReference($orderReferenceId);
     } catch (Exception $e) {
         Mage::throwException("Please try another Amazon payment method." . "\n\n" . substr($e->getMessage(), 0, strpos($e->getMessage(), 'Stack trace')));
         $this->_setErrorCheck();
         return;
     }
     $payment->setIsTransactionClosed(false);
     $payment->setSkipOrderProcessing(true);
     $message = Mage::helper('payment')->__(($this->getConfigData('is_async') ? 'Asynchronous ' : '') . 'Order of %s sent to Amazon Payments.', $order->getStore()->convertPrice($amount, true, false));
     $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_ORDER, null, false, $message);
     switch ($this->getConfigData('payment_action')) {
         case self::ACTION_AUTHORIZE:
             $this->_authorize($payment, $amount, false);
             break;
         case self::ACTION_AUTHORIZE_CAPTURE:
             $this->_authorize($payment, $amount, true);
             break;
         default:
             break;
     }
     return $this;
 }
예제 #17
0
 public function createOrder(Varien_Object $payment, $amount, $authorize)
 {
     $store_id = Mage::app()->getStore()->getStoreId();
     $logger = Mage::helper('worldpay/logger');
     if ($payment->getOrder()) {
         $orderId = $payment->getOrder()->getIncrementId();
         $order = $payment->getOrder();
     } else {
         $quote = $payment->getQuote();
         $orderId = $quote->getReservedOrderId();
         $quote->save();
     }
     $session = Mage::getSingleton('core/session');
     $token = $session->getData('payment_token');
     $savedCard = $session->getData('saved_card');
     $logger->log('Begin create order');
     $session->setData('wp_3dsSuccess', false);
     $session->setData('wp_orderCode', false);
     $worldpay = $this->setupWorldpay();
     $checkout = Mage::getSingleton('checkout/session')->getQuote();
     $billing = $checkout->getBillingAddress();
     $order_description = Mage::getStoreConfig('payment/worldpay/description', $store_id);
     if (!$order_description) {
         $order_description = "Order";
     }
     $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
     $name = $billing->getName();
     $billing_address = array("address1" => $billing->getStreet(1), "address2" => $billing->getStreet(2), "address3" => $billing->getStreet(3), "postalCode" => $billing->getPostcode(), "city" => $billing->getCity(), "state" => "", "countryCode" => $billing->getCountry());
     try {
         $mode = Mage::getStoreConfig('payment/worldpay_mode', Mage::app()->getStore()->getStoreId());
         $settlementCurrency = Mage::getStoreConfig('payment/worldpay/settlementcurrency', Mage::app()->getStore()->getStoreId());
         $createOrderRequest = array('token' => $token, 'orderDescription' => $order_description, 'amount' => $amount * 100, 'currencyCode' => $currency_code, 'name' => $name, 'billingAddress' => $billing_address, 'customerOrderCode' => $orderId, 'settlementCurrency' => $settlementCurrency, 'successUrl' => Mage::getUrl('worldpay/apm/success', array('_secure' => true)), 'pendingUrl' => Mage::getUrl('worldpay/apm/pending', array('_secure' => true)), 'failureUrl' => Mage::getUrl('worldpay/apm/failure', array('_secure' => true)), 'cancelUrl' => Mage::getUrl('worldpay/apm/cancel', array('_secure' => true)));
         $logger->log('Order Request: ' . print_r($createOrderRequest, true));
         $response = $worldpay->createApmOrder($createOrderRequest);
         $logger->log('Order Response: ' . print_r($response, true));
         if ($response['paymentStatus'] === 'SUCCESS') {
             $this->setStore($payment->getOrder()->getStoreId());
             $logger->log('Order: ' . $response['orderCode'] . ' SUCCESS');
             $payment->setStatus(self::STATUS_APPROVED);
             $payment->setAmount($amount);
             $payment->setLastTransId($orderId);
             $payment->setTransactionId($response['orderCode']);
             $payment->setAdditionalInformation("worldpayOrderCode", $response['orderCode']);
             $payment->setShouldCloseParentTransaction(1)->setIsTransactionClosed(1)->registerCaptureNotification($amount);
         } else {
             if ($response['paymentStatus'] == 'PRE_AUTHORIZED') {
                 $logger->log('Order: ' . $response['orderCode'] . ' PRE_AUTHORIZED');
                 $payment->setAmount($amount);
                 $payment->setAdditionalInformation("worldpayOrderCode", $response['orderCode']);
                 $payment->setLastTransId($orderId);
                 $payment->setTransactionId($response['orderCode']);
                 $payment->setIsTransactionClosed(false);
                 $session->setData('wp_redirectURL', $response['redirectURL']);
                 $session->setData('wp_orderCode', $response['orderCode']);
             } else {
                 if (isset($response['paymentStatusReason'])) {
                     throw new Exception($response['paymentStatusReason']);
                 } else {
                     throw new Exception(print_r($response, true));
                 }
             }
         }
     } catch (Exception $e) {
         $payment->setStatus(self::STATUS_ERROR);
         $payment->setAmount($amount);
         $payment->setLastTransId($orderId);
         $logger->log($e->getMessage());
         Mage::throwException('Payment failed, please try again later ' . $e->getMessage());
     }
     return $this;
 }
예제 #18
0
 /**
  * Authorize a payment
  *
  * @param Varien_Object $payment
  * @param float $amount
  *
  * @return Mage_Payment_Model_Abstract
  */
 public function authorize(Varien_Object $payment, $amount)
 {
     if (!$this->_isBackendOrder) {
         if ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_SHARED_PAGE) {
             $transID = Mage::getSingleton('core/session')->getData('ewayTransactionID');
             $payment->setTransactionId($transID);
             $payment->setIsTransactionClosed(0);
             Mage::getSingleton('core/session')->unsetData('ewayTransactionID');
             return $this;
         } elseif ($this->_connectionType === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
             $payment = Mage::getModel('ewayrapid/request_transparent')->setTransaction($payment);
             return $this;
         }
     }
     /* @var Mage_Sales_Model_Order_Payment $payment */
     if ($amount <= 0) {
         Mage::throwException(Mage::helper('paygate')->__('Invalid amount for authorize.'));
     }
     if (Mage::getStoreConfig('payment/ewayrapid_general/connection_type') === Eway_Rapid31_Model_Config::CONNECTION_TRANSPARENT) {
         //Mage::app()->getResponse()->setRedirect(Mage::getUrl('ewayrapid/transparent/'))->sendResponse();
         //exit;
     }
     $amount = round($amount * 100);
     $request = Mage::getModel('ewayrapid/request_direct');
     $request->doAuthorisation($payment, $amount);
     return $this;
 }
예제 #19
0
 public function createOrder(Varien_Object $payment, $amount, $authorize)
 {
     $store_id = Mage::app()->getStore()->getStoreId();
     if ($payment->getOrder()) {
         $orderId = $payment->getOrder()->getIncrementId();
     } else {
         $orderId = $payment->getQuote()->getIncrementId();
         // $order = $payment->getOrder())
     }
     $logger = Mage::helper('worldpay/logger');
     $session = Mage::getSingleton('core/session');
     $token = $session->getData('payment_token');
     $savedCard = $session->getData('saved_card');
     $logger->log('Begin create order');
     $session->setData('wp_3dsSuccess', false);
     $session->setData('wp_orderCode', false);
     $worldpay = $this->setupWorldpay();
     if (Mage::app()->getStore()->isAdmin()) {
         $checkout = Mage::getSingleton('adminhtml/session_quote')->getQuote();
     } else {
         $checkout = Mage::getSingleton('checkout/session')->getQuote();
     }
     $billing = $checkout->getBillingAddress();
     $order_description = Mage::getStoreConfig('payment/' . $this->_code . '/description', $store_id);
     if (!$order_description) {
         $order_description = "Order";
     }
     $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
     $name = $billing->getName();
     $billing_address = array("address1" => $billing->getStreet(1), "address2" => $billing->getStreet(2), "address3" => $billing->getStreet(3), "postalCode" => $billing->getPostcode(), "city" => $billing->getCity(), "state" => "", "countryCode" => $billing->getCountry());
     try {
         $mode = Mage::getStoreConfig('payment/worldpay_mode', Mage::app()->getStore()->getStoreId());
         $orderType = 'ECOM';
         $threeDS = Mage::getStoreConfig('payment/worldpay_cc/use3ds', Mage::app()->getStore()->getStoreId());
         if (Mage::app()->getStore()->isAdmin()) {
             $orderType = 'MOTO';
             $threeDS = false;
         }
         if ($threeDS && $mode == 'Test Mode') {
             $name = '3D';
         }
         $settlementCurrency = Mage::getStoreConfig('payment/worldpay_cc/settlementcurrency', Mage::app()->getStore()->getStoreId());
         $createOrderRequest = array('token' => $token, 'orderDescription' => $order_description, 'amount' => $amount * 100, 'currencyCode' => $currency_code, 'name' => $name, 'orderType' => $orderType, 'is3DSOrder' => $threeDS, 'authoriseOnly' => $authorize, 'billingAddress' => $billing_address, 'customerOrderCode' => $orderId, 'settlementCurrency' => $settlementCurrency);
         $logger->log('Order Request: ' . print_r($createOrderRequest, true));
         $response = $worldpay->createOrder($createOrderRequest);
         $logger->log('Order Response: ' . print_r($response, true));
         if ($response['paymentStatus'] === 'SUCCESS') {
             $this->setStore($payment->getOrder()->getStoreId());
             $logger->log('Order: ' . $response['orderCode'] . ' SUCCESS');
             $payment->setStatus(self::STATUS_APPROVED);
             $payment->setAmount($amount);
             $payment->setLastTransId($orderId);
             $payment->setTransactionId($response['orderCode']);
             $payment->setAdditionalInformation("worldpayOrderCode", $response['orderCode']);
             // $formatedPrice = $order->getBaseCurrency()->formatTxt($amount);
             $payment->setShouldCloseParentTransaction(1)->setIsTransactionClosed(1)->registerCaptureNotification($amount);
         } else {
             if ($response['paymentStatus'] == 'AUTHORIZED') {
                 $this->setStore($payment->getOrder()->getStoreId());
                 $logger->log('Order: ' . $response['orderCode'] . ' AUTHORIZED');
                 $payment->setIsTransactionClosed(0);
                 $payment->setSkipOrderProcessing(true);
                 $payment->setStatus(self::STATUS_APPROVED);
                 $payment->setAmount($amount);
                 $payment->setAdditionalInformation("worldpayOrderCode", $response['orderCode']);
                 $payment->setLastTransId($orderId);
                 $payment->setTransactionId($response['orderCode']);
             } else {
                 if ($response['is3DSOrder']) {
                     $session = Mage::getSingleton('core/session');
                     $logger->log('Starting 3DS Order: ' . $response['orderCode']);
                     $session->setData('wp_3dsSuccess', false);
                     $session->setData('wp_redirectURL', $response['redirectURL']);
                     $session->setData('wp_oneTime3DsToken', $response['oneTime3DsToken']);
                     $session->setData('wp_orderCode', $response['orderCode']);
                     // IF normal checkout
                     $currentUrl = Mage::helper('core/url')->getCurrentUrl();
                     $url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
                     $path = $url->getPath();
                     if (strpos($path, 'onepage') === false) {
                         Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('worldpay/threeDS'));
                         Mage::app()->getResponse()->sendResponse();
                     } else {
                         echo 'window.WorldpayMagento.loadThreeDS("' . Mage::getUrl('worldpay/threeDS') . '")';
                     }
                     exit;
                 } else {
                     if (isset($response['paymentStatusReason'])) {
                         throw new Exception($response['paymentStatusReason']);
                     } else {
                         throw new Exception(print_r($response, true));
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $payment->setStatus(self::STATUS_ERROR);
         $payment->setAmount($amount);
         $payment->setLastTransId($orderId);
         $logger->log($e->getMessage());
         Mage::throwException('Payment failed, please try again later ' . $e->getMessage());
     }
     return $this;
 }
예제 #20
0
 public function capture(Varien_Object $payment, $amount)
 {
     $session = Mage::getSingleton('adminhtml/session');
     //
     // Verify if remote interface is enabled
     //
     if (!$this->_canDoCapture($payment->getOrder())) {
         return $this;
     }
     if ((int) $this->getConfigData('remoteinterface', $payment->getOrder() ? $payment->getOrder()->getStoreId() : null) != 1) {
         $this->addOrderComment($payment->getOrder(), Mage::helper('epay')->__('EPAY_LABEL_73'));
         return $this;
     }
     try {
         //
         // Read info directly from the database
         $read = Mage::getSingleton('core/resource')->getConnection('core_read');
         $row = $read->fetchRow("select * from epay_order_status where orderid = '" . $payment->getOrder()->getIncrementId() . "'");
         if ($row["status"] == '1') {
             $epayamount = (string) ($amount * 100);
             $tid = $row["tid"];
             $param = array('merchantnumber' => $this->getConfigData('merchantnumber', $payment->getOrder() ? $payment->getOrder()->getStoreId() : null), 'transactionid' => $tid, 'amount' => $epayamount, 'group' => '', 'pbsResponse' => 0, 'epayresponse' => 0, 'pwd' => $this->getConfigData('remoteinterfacepassword', $payment->getOrder() ? $payment->getOrder()->getStoreId() : null));
             $client = new SoapClient('https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx?WSDL');
             $result = $client->capture($param);
             if ($result->captureResult == 1) {
                 //
                 // Success - transaction captured!
                 //
                 $this->addOrderComment($payment->getOrder(), "Transaction with id: " . $tid . " has been captured by amount: " . number_format($amount, 2, ",", "."));
                 if (!$payment->getParentTransactionId() || $tid != $payment->getParentTransactionId()) {
                     $payment->setTransactionId($tid);
                 }
                 $payment->setIsTransactionClosed(0);
             } else {
                 if ($result->epayresponse != -1) {
                     if ($result->epayresponse == -1002) {
                         $this->addOrderComment($payment->getOrder(), "Transaction could not be deleted by ePay: " . $result->epayresponse . ". Forretningsnummeret findes ikke.");
                         throw new Exception("Transaction could not be captured by ePay: " . $result->epayresponse . ". Forretningsnummeret findes ikke.");
                     } else {
                         if ($result->epayresponse == -1003 || $result->epayresponse == -1006) {
                             $this->addOrderComment($payment->getOrder(), "Transaction could not be captured by ePay: " . $result->epayresponse . ". Der er ikke adgang til denne funktion (API / Remote Interface).");
                             throw new Exception("Transaction could not be captured by ePay: " . $result->epayresponse . ". Der er ikke adgang til denne funktion (API / Remote Interface).");
                         } else {
                             $this->addOrderComment($payment->getOrder(), 'Transaction could not be captured by ePay: ' . $result->epayresponse . '. ' . $this->getEpayErrorText($result->epayresponse));
                             throw new Exception('Transaction could not be captured by ePay: ' . $result->epayresponse . '. ' . $this->getEpayErrorText($result->epayresponse));
                         }
                     }
                 } else {
                     throw new Exception("Transaction could not be captured by ePay: " . $result->pbsResponse . '. ' . $this->getPbsErrorText($result->pbsResponse));
                 }
             }
         } else {
             //
             // Somehow the order was not found - this must be an error!
             //
             throw new Exception("Order not found - please check the epay_order_status table!");
         }
     } catch (Exception $e) {
         $session->addException($e, $e->getMessage() . " - Go to the ePay administration to capture the payment manually.");
     }
     return $this;
 }
예제 #21
0
 /**
  * 
  * @param Varien_Object $payment
  * @param type $amount
  * @return of type Velocity_CreditCard_Model_Payment class $this object.
  */
 public function refund(Varien_Object $payment, $amount)
 {
     Mage::log($amount, 1);
     try {
         $this->_callVelocityGateway();
         $response = $this->velocityProcessor->returnById(array('amount' => $amount, 'TransactionId' => $payment->_data['last_trans_id']));
         $xml = VelocityXmlCreator::returnByIdXML(number_format($amount, 2, '.', ''), $payment->_data['last_trans_id']);
         // got ReturnById xml object.
         $req = $xml->saveXML();
         $obj_req = serialize($req);
         Mage::log(print_r($response, 1));
         if (is_array($response) && !empty($response) && isset($response['Status']) && $response['Status'] == 'Successful') {
             $payment->setTransactionId($response['TransactionId']);
             $payment->setIsTransactionClosed(1);
             $insertData = array('transaction_id' => $response['TransactionId'], 'transaction_status' => $response['Status'], 'order_id' => $response['OrderId'], 'request_obj' => $obj_req, 'response_obj' => json_encode($response));
             $collectionSet = Mage::getModel('creditcard/card');
             $collectionSet->setData($insertData)->save();
         } else {
             if (is_array($response) && !empty($response)) {
                 $errorMsg = $this->_getHelper()->__($response['StatusMessage']);
             } else {
                 $errorMsg = $this->_getHelper()->__($response);
             }
         }
     } catch (Exception $e) {
         Mage::throwException($e->getMessage());
     }
     if (isset($errorMsg) && !empty($errorMsg)) {
         Mage::throwException($errorMsg);
     }
     return $this;
 }
예제 #22
0
파일: Partpayment.php 프로젝트: ext/magento
 public function authorize(Varien_Object $payment, $amount)
 {
     $gateway = Mage::getSingleton('partpayment/gateway');
     $invoiceId = $gateway->makePayment();
     $payment->setTransactionId($invoiceId);
     $payment->setIsTransactionClosed(0);
 }