Example #1
0
 public function process(Customweb_Payment_Authorization_ITransaction $transaction)
 {
     $initialTransaction = $transaction->getTransactionContext()->getInitialTransaction();
     $this->useInitialTransactionData($initialTransaction, $transaction);
     $transaction->setAuthorizationMethod(self::AUTHORIZATION_METHOD_NAME);
     $this->requestAuthorization($transaction);
 }
 public function partialRefund(Customweb_Payment_Authorization_ITransaction $transaction, $items, $close)
 {
     if (!$transaction instanceof Customweb_Saferpay_Authorization_Transaction) {
         throw new Exception("The given transaction is not instanceof Customweb_Saferpay_Authorization_Transaction.");
     }
     $amount = Customweb_Util_Invoice::getTotalAmountIncludingTax($items);
     // Check the transaction state
     $transaction->refundByLineItemsDry($items, $close);
     $builder = new Customweb_Saferpay_BackendOperation_Adapter_Refund_ParameterBuilder($transaction, $this->getConfiguration(), $this->container);
     $sendParameters = $builder->buildParameters($amount);
     $requestUrl = Customweb_Saferpay_Util::addParametersToUrl($this->getExecuteUrl(), $sendParameters);
     $response = Customweb_Saferpay_Util::sendRequest($requestUrl);
     $parameters = $this->getXmlParameters($response);
     if ($parameters['RESULT'] == 0) {
         $id = $parameters['ID'];
         $this->capture($transaction, $amount, $id);
         $refundItem = $transaction->refundByLineItems($items, $close, Customweb_I18n_Translation::__("The total amount of the transaction was refunded. Refund transaction ID: '!paymentId' .", array('!paymentId' => $id)));
         $refundItem->setRefundId($id);
     } else {
         if ($parameters['RESULT'] == '75') {
             throw new Exception(Customweb_I18n_Translation::__('Refund of !amount failed because no card reference id was provided. This most likely because you try to refund a transaction authorized over the payment page. (Code: !result).', array('!amount' => $amount, '!result' => $parameters['RESULT'])));
         } else {
             throw new Exception(Customweb_I18n_Translation::__('Refund of !amount failed with code: !result.', array('!amount' => $amount, '!result' => $parameters['RESULT'])));
         }
     }
 }
Example #3
0
 public function isHeaderRedirectionSupported(Customweb_Payment_Authorization_ITransaction $transaction, array $formData)
 {
     if ($transaction->isUseExistingAlias()) {
         return false;
     }
     return strlen($this->getRedirectionUrl($transaction, $formData)) <= self::MAX_ALLOWED_URL_LENGTH;
 }
Example #4
0
 /**
  * 
  * @Action("index")
  */
 public function process(Customweb_Payment_Authorization_ITransaction $transaction, Customweb_Core_Http_IRequest $request)
 {
     $adapter = $this->getAdapterFactory()->getAuthorizationAdapterByName($transaction->getAuthorizationMethod());
     $parameters = $request->getParameters();
     $response = $adapter->processAuthorization($transaction, $parameters);
     return $response;
 }
 public function cancel(Customweb_Payment_Authorization_ITransaction $transaction)
 {
     if (!$transaction instanceof Customweb_Saferpay_Authorization_Transaction) {
         throw new Exception("The given transaction is not instanceof Customweb_Saferpay_Authorization_Transaction.");
     }
     $transaction->cancelDry();
     $builder = new Customweb_Saferpay_BackendOperation_Adapter_Cancel_ParameterBuilder($transaction, $this->getConfiguration(), $this->container);
     $parameters = $builder->buildParameters();
     $this->performPayCompleteAction($parameters, Customweb_I18n_Translation::__('Transaction could not be canceled.'));
     $transaction->cancel();
 }
Example #6
0
 /**
  * Called when iframe/pp fails, as PSP does not send a notification
  * @Action("fail")
  */
 public function fail(Customweb_Payment_Authorization_ITransaction $transaction, Customweb_Core_Http_IRequest $request)
 {
     if (!$transaction instanceof Customweb_Saferpay_Authorization_Transaction) {
         throw new Customweb_Core_Exception_CastException('Customweb_Saferpay_Authorization_Transaction');
     }
     if (!$transaction->isAuthorizationFailed() && !$transaction->isAuthorized()) {
         $message = new Customweb_Payment_Authorization_ErrorMessage(Customweb_I18n_Translation::__("The payment could not be processed."), Customweb_I18n_Translation::__("The payment failed."));
         $transaction->setAuthorizationFailed($message);
     }
     $url = $this->getAdapterFactory()->getAuthorizationAdapterByName($transaction->getAuthorizationMethod())->getFailedUrl($transaction);
     return Customweb_Core_Http_Response::redirect($url);
 }
 public function partialCapture(Customweb_Payment_Authorization_ITransaction $transaction, $items, $close)
 {
     if (!$transaction instanceof Customweb_Saferpay_Authorization_Transaction) {
         throw new Exception("The given transaction is not instanceof Customweb_Saferpay_Authorization_Transaction.");
     }
     $amount = Customweb_Util_Invoice::getTotalAmountIncludingTax($items);
     // Check the transaction state
     $transaction->partialCaptureByLineItemsDry($items, true);
     $builder = new Customweb_Saferpay_BackendOperation_Adapter_Capture_ParameterBuilder($transaction, $this->getConfiguration(), $this->container);
     $builder->setAmount($amount);
     $parameters = $builder->buildParameters();
     $this->performPayCompleteAction($parameters, Customweb_I18n_Translation::__('The transaction could not be captured.'));
     $transaction->partialCaptureByLineItems($items, true);
 }
 public function capture(Customweb_Payment_Authorization_ITransaction $transaction)
 {
     $transactionModel = $transaction->getTransactionContext()->getTransactionModel();
     $order = $transactionModel->getOrder();
     $transactionModel->setTransactionObject($transaction);
     $transactionModel->save();
     $invoices = $order->getInvoiceCollection();
     if ($invoices->count() == 1) {
         $invoice = $invoices->getFirstItem();
         if ($invoice->canCapture()) {
             $invoice->capture();
             Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder())->save();
         }
     }
 }
 public function partialRefund(Customweb_Payment_Authorization_ITransaction $transaction, $items, $close)
 {
     $transactionModel = $transaction->getTransactionContext()->getTransactionModel();
     $order = $transactionModel->getOrder();
     $transactionModel->setTransactionObject($transaction);
     $transactionModel->save();
     try {
         $data = array();
         $orderItems = $order->getItemsCollection();
         $totalRefund = 0;
         $totalOrder = 0;
         foreach ($items as $item) {
             switch ($item->getType()) {
                 case Customweb_Payment_Authorization_IInvoiceItem::TYPE_PRODUCT:
                     $orderItem = $orderItems->getItemByColumnValue('sku', $item->getSku());
                     if (!isset($data['qtys'][$orderItem->getId()])) {
                         $data['qtys'][$orderItem->getId()] = $item->getQuantity();
                     } else {
                         $data['qtys'][$orderItem->getId()] += $item->getQuantity();
                     }
                     $totalRefund += $item->getAmountIncludingTax();
                     $totalOrder += $orderItem->getRowTotalInclTax();
                     break;
                 case Customweb_Payment_Authorization_IInvoiceItem::TYPE_SHIPPING:
                     if (!isset($data['shipping_amount'])) {
                         $data['shipping_amount'] = $order->getShippingAmount();
                     } else {
                         $data['shipping_amount'] += $order->getShippingAmount();
                     }
                     $totalRefund += $item->getAmountIncludingTax();
                     $totalOrder += $order->getShippingAmount() + $order->getShippingTaxAmount();
                     break;
             }
         }
         if ($totalOrder > $totalRefund) {
             $data['adjustment_negative'] = $totalOrder - $totalRefund;
         }
         $this->createCreditmemo($order, $data);
     } catch (Exception $e) {
         Mage::helper('SaferpayCw')->logException($e);
     }
 }
Example #10
0
 public function finalizeAuthorizationRequest(Customweb_Payment_Authorization_ITransaction $transaction)
 {
     $response = new Customweb_Core_Http_Response();
     $response->setLocation($transaction->getNextRedirectUrl());
     return $response;
 }
 /**
  * 
  * @param Customweb_Payment_Authorization_ITransaction $transaction
  * @param Customweb_Saferpay_Configuration $configuration
  */
 public function __construct(Customweb_Payment_Authorization_ITransaction $transaction, Customweb_Saferpay_Configuration $configuration, Customweb_DependencyInjection_IContainer $container)
 {
     parent::__construct($transaction->getTransactionContext(), $configuration, $container);
     $this->setTransaction($transaction);
 }
Example #12
0
 public function finalizeAuthorizationRequest(Customweb_Payment_Authorization_ITransaction $transaction)
 {
     return "redirect:" . $transaction->getNextRedirectUrl();
 }
 public function persistTransactionObject(Customweb_Payment_Authorization_ITransaction $transactionObject)
 {
     $transaction = $this->getManager()->fetch($this->getTransactionClassName(), $transactionObject->getTransactionId(), false);
     if (!$transaction instanceof Customweb_Payment_Entity_AbstractTransaction) {
         throw new Exception("Unabel to find transaction with id " . $transactionObject->getTransactionId() . ".");
     }
     if ($transaction->getAuthorizationStatus() == Customweb_Payment_Entity_AbstractTransaction::AUTHORIZATION_STATUS_AUTHORIZING) {
         throw new Customweb_Payment_Exception_OptimisticLockingException($transaction->getTransactionId());
     }
     if ($transaction->isAuthorizationRequired($transactionObject)) {
         $transaction->setAuthorizationStatus(Customweb_Payment_Entity_AbstractTransaction::AUTHORIZATION_STATUS_AUTHORIZING);
         $transaction->setSkipOnSaveMethods(true);
         try {
             $this->getManager()->persist($transaction);
         } catch (Customweb_Database_Entity_Exception_OptimisticLockingException $e) {
             throw new Customweb_Payment_Exception_OptimisticLockingException($transaction->getTransactionId());
         }
         $transaction = $this->getManager()->fetch($this->getTransactionClassName(), $transactionObject->getTransactionId(), false);
         if (!method_exists($transactionObject, 'setVersionNumber')) {
             throw new Exception('setVersionNumber function is required on the transactionObject.');
         }
         $transactionObject->setVersionNumber($transaction->getVersionNumber());
     }
     $transaction->setTransactionObject($transactionObject);
     try {
         $this->getManager()->persist($transaction);
     } catch (Customweb_Database_Entity_Exception_OptimisticLockingException $e) {
         throw new Customweb_Payment_Exception_OptimisticLockingException($transaction->getTransactionId());
     }
 }
 public function persistTransactionObject(Customweb_Payment_Authorization_ITransaction $transactionObject)
 {
     $transaction = $this->getManager()->fetch($this->getTransactionClassName(), $transactionObject->getTransactionId());
     if (!$transaction instanceof Customweb_Payment_Entity_AbstractTransaction) {
         throw new Exception("Unabel to find transaction with id " . $transactionObject->getTransactionId() . ".");
     }
     $transaction->setTransactionObject($transactionObject);
     $this->getManager()->persist($transaction);
 }
 /**
  * Validates the parameters against the transaction
  * 
  * @param Customweb_Payment_Authorization_ITransaction $transaction
  * @param array $parameters
  * @return boolean True if parameters are valid.
  */
 protected function validateParameters(Customweb_Payment_Authorization_ITransaction $transaction, $parameters)
 {
     $isValid = true;
     if ($parameters['AMOUNT'] != number_format($transaction->getAuthorizationAmount(), 2, '', '')) {
         $isValid = false;
     } else {
         if ($parameters['ACCOUNTID'] != $this->getConfiguration()->getAccountId()) {
             $isValid = false;
         } else {
             if (!$this->getConfiguration()->isTestMode() && $parameters['PROVIDERID'] == self::SAFERPAYTEST_PROVIDER_ID) {
                 $isValid = false;
             } else {
                 if ($parameters['CURRENCY'] != $transaction->getCurrencyCode()) {
                     $isValid = false;
                 }
             }
         }
     }
     return $isValid;
 }
 public function isAuthorizationRequired(Customweb_Payment_Authorization_ITransaction $transaction)
 {
     if ($transaction !== null && $transaction instanceof Customweb_Payment_Authorization_ITransaction && $transaction->isAuthorized() && $this->getAuthorizationStatus() === Customweb_Payment_Authorization_ITransaction::AUTHORIZATION_STATUS_PENDING) {
         return true;
     } else {
         return false;
     }
 }
 public function finalizeAuthorizationRequest(Customweb_Payment_Authorization_ITransaction $transaction)
 {
     /* @var $transaction Customweb_Saferpay_Authorization_Transaction */
     if ($transaction->isAuthorizationFailed()) {
         return 'redirect:' . $this->getFailedUrl($transaction);
     }
     if ($transaction->isAuthorized()) {
         return 'redirect:' . $this->getSuccessUrl($transaction);
     }
     return $this->container->getBean('Customweb_Payment_Endpoint_IAdapter')->getUrl("process", "index", array('cw_transaction_id' => $transaction->getExternalTransactionId()));
 }