コード例 #1
0
 /**
  * Process exceptions for gateway action with a lot of transactions
  *
  * @param  Mage_Payment_Model_Info $payment
  * @param  string $messages
  * @param  bool $isSuccessfulTransactions
  */
 protected function _processFailureMultitransactionAction($payment, $messages, $isSuccessfulTransactions)
 {
     if ($isSuccessfulTransactions) {
         $messages[] = Mage::helper('paygate')->__('Gateway actions are locked because the gateway cannot complete one or more of the transactions. Please log in to your Authorize.Net account to manually resolve the issue(s).');
         /**
          * If there is successful transactions we can not to cancel order but
          * have to save information about processed transactions in order`s comments and disable
          * opportunity to voiding\capturing\refunding in future. Current order and payment will not be saved because we have to
          * load new order object and set information into this object.
          */
         $currentOrderId = $payment->getOrder()->getId();
         $copyOrder = Mage::getModel('sales/order')->load($currentOrderId);
         $copyOrder->getPayment()->setAdditionalInformation($this->_isGatewayActionsLockedKey, 1);
         foreach ($messages as $message) {
             $copyOrder->addStatusHistoryComment($message);
         }
         $copyOrder->save();
     }
     Mage::throwException(Mage::helper('paygate')->convertMessagesToMessage($messages));
 }
コード例 #2
0
ファイル: Paymentmethod.php プロジェクト: payfort/magento
 public function collectPayment(\Mage_Payment_Model_Info $payment, $amount, $capture = true)
 {
     $Currency = Mage::app()->getStore()->getBaseCurrencyCode();
     require_once MAGENTO_ROOT . '/lib/Start/autoload.php';
     # At the top of your PHP file
     $token = isset($_POST['payfortToken']) ? $_POST['payfortToken'] : false;
     $email = isset($_POST['payfortEmail']) ? $_POST['payfortEmail'] : false;
     if (!$token || !$email) {
         //this block will be executed if the order was authorized earlier and now trying to capture amount
         $token_array = $payment->getAdditionalInformation('token');
         $token = $token_array['token'];
         $email = $token_array['email'];
     }
     if (!$token || !$email) {
         Mage::throwException('Invalid Token');
     }
     $currency = !isset($Currency) ? 'AED' : $Currency;
     if (file_exists(MAGENTO_ROOT . '/data/currencies.json')) {
         $currency_json_data = json_decode(file_get_contents(MAGENTO_ROOT . '/data/currencies.json'), 1);
         $currency_multiplier = $currency_json_data[$currency];
     } else {
         $currency_multiplier = 100;
     }
     $amount_in_cents = $amount * $currency_multiplier;
     $order = $payment->getOrder();
     $order_items_array_full = array();
     foreach ($order->getAllVisibleItems() as $value) {
         $order_items_array['title'] = $value->getName();
         $order_items_array['amount'] = round($value->getPrice(), 2) * $currency_multiplier;
         $order_items_array['quantity'] = $value->getQtyOrdered();
         array_push($order_items_array_full, $order_items_array);
     }
     $shipping_amount = $order->getShippingAmount();
     $shipping_amount = $shipping_amount * $currency_multiplier;
     if (Mage::getSingleton('customer/session')->isLoggedIn()) {
         $customer = Mage::getSingleton('customer/session')->getCustomer();
         $username = $customer->getName();
         $registered_at = date(DATE_ISO8601, strtotime($customer->getCreatedAt()));
     } else {
         $username = "******";
         $registered_at = date(DATE_ISO8601, strtotime(date("Y-m-d H:i:s")));
     }
     $billing_data = $order->getBillingAddress()->getData();
     if (is_object($order->getShippingAddress())) {
         $shipping_data = $order->getShippingAddress()->getData();
         $shipping_address = array("first_name" => $shipping_data['firstname'], "last_name" => $shipping_data['lastname'], "country" => $shipping_data['country_id'], "city" => $shipping_data['city'], "address" => $shipping_data['customer_address'], "phone" => $shipping_data['telephone'], "postcode" => $shipping_data['postcode']);
     } else {
         $shipping_address = array();
     }
     $billing_address = array("first_name" => $billing_data['firstname'], "last_name" => $billing_data['lastname'], "country" => $billing_data['country_id'], "city" => $billing_data['city'], "address" => $billing_data['customer_address'], "phone" => $billing_data['telephone'], "postcode" => $billing_data['postcode']);
     $shopping_cart_array = array('user_name' => $username, 'registered_at' => $registered_at, 'items' => $order_items_array_full, 'billing_address' => $billing_address, 'shipping_address' => $shipping_address);
     $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
     $charge_args = array('description' => "Magento charge for " . $email, 'card' => $token, 'currency' => $currency, 'email' => $email, 'ip' => $_SERVER['REMOTE_ADDR'], 'amount' => $amount_in_cents, 'capture' => $capture, 'shipping_amount' => $shipping_amount, 'shopping_cart' => $shopping_cart_array, 'metadata' => array('reference_id' => $orderId));
     $ver = new Mage();
     $version = $ver->getVersion();
     $userAgent = 'Magento ' . $version . ' / Start Plugin ' . self::PLUGIN_VERSION;
     Start::setUserAgent($userAgent);
     $method = $payment->getMethodInstance();
     if ($method->getConfigData('test_mode') == 1) {
         Start::setApiKey($method->getConfigData('test_secret_key'));
     } else {
         Start::setApiKey($method->getConfigData('live_secret_key'));
     }
     try {
         // Charge the token
         $charge = Start_Charge::create($charge_args);
         //need to process charge as success or failed
         $payment->setTransactionId($charge["id"]);
         if ($capture) {
             $payment->setIsTransactionClosed(1);
         } else {
             $payment->setIsTransactionClosed(0);
         }
     } catch (Start_Error $e) {
         $error_code = $e->getErrorCode();
         if ($error_code === "card_declined") {
             $errorMsg = 'Charge was declined. Please, contact you bank for more information or use a different card.';
         } else {
             $errorMsg = $e->getMessage();
         }
         throw new Mage_Payment_Model_Info_Exception($errorMsg);
     }
     //need to process charge as success or failed
 }
コード例 #3
0
ファイル: Data.php プロジェクト: hyhoocchan/mage-local
 /**
  * Format price with currency sign
  * @param  Mage_Payment_Model_Info $payment
  * @param float $amount
  * @return string
  */
 protected function _formatPrice($payment, $amount)
 {
     return $payment->getOrder()->getBaseCurrency()->formatTxt($amount);
 }
 /**
  * Process exceptions for gateway action with a lot of transactions
  *
  * @param  Mage_Payment_Model_Info $payment
  * @param  string $messages
  * @param  bool $isSuccessfulTransactions
  */
 protected function _processFailureMultitransactionAction($payment, $messages, $isSuccessfulTransactions)
 {
     if ($isSuccessfulTransactions) {
         $currentOrderId = $payment->getOrder()->getId();
         $copyOrder = Mage::getModel('sales/order')->load($currentOrderId);
         foreach ($messages as $message) {
             $copyOrder->addStatusHistoryComment($message);
         }
         $copyOrder->save();
     }
     Mage::throwException(Mage::helper('paygate')->convertMessagesToMessage($messages));
 }
コード例 #5
0
 /**
  * Returns request object with needed data for API request to PayPal to get form URL.
  *
  * @param Mage_Payment_Model_Info $payment
  * @return Mage_Paypal_Model_Hostedpro_Request
  */
 protected function _buildFormUrlRequest(Mage_Payment_Model_Info $payment)
 {
     $request = $this->_buildBasicRequest()->setOrder($payment->getOrder())->setPaymentMethod($this);
     return $request;
 }
コード例 #6
0
 /**
  * Validate payment method is allowed for the customer's billing address country.
  * @param Mage_Payment_Model_Info $info
  * @return self
  */
 protected function _validateCountry(Mage_Payment_Model_Info $info)
 {
     /**
      * Get the order when dealing with an order payment, quote otherwise.
      * @see Mage_Payment_Model_Method_Abstract
      */
     if ($info instanceof Mage_Sales_Model_Order_Payment) {
         $billingCountry = $info->getOrder()->getBillingAddress()->getCountryId();
     } else {
         $billingCountry = $info->getQuote()->getBillingAddress()->getCountryId();
     }
     if (!$this->canUseForCountry($billingCountry)) {
         throw Mage::exception('EbayEnterprise_CreditCard', $this->_helper->__(self::METHOD_NOT_ALLOWED_FOR_COUNTRY));
     }
     return $this;
 }
コード例 #7
0
 /**
  * Send void request to MerchantWare gateway
  *
  * @param Mage_Payment_Model_Info $payment
  * @return $result
  * @throws Mage_Core_Exception
  */
 private function _void($payment)
 {
     $error = false;
     $soapClient = $this->getSoapApi();
     $this->iniRequest();
     //Add token
     if ($payment->getParentTransactionId() !== FALSE) {
         $this->_request->token = $payment->getParentTransactionId();
     } else {
         //Cannot void
         $error = Mage::helper('merchantware_directpost')->__('No previous transactions could be found.  Cannot void this transaction.');
         Mage::throwException($error);
     }
     //Add order info
     $order = $payment->getOrder();
     $this->_request->merchantTransactionId = $order->getIncrementId();
     $additionalInfo = array();
     try {
         $result = $soapClient->Void($this->_request);
         $result = $result->VoidResult;
         if (!empty($result->ErrorMessage)) {
             $additionalInfo['ErrorMessage'] = $result->ErrorMessage;
         }
         //Authorization is approved.
         $additionalInfo['ApprovalStatus'] = $result->ApprovalStatus;
         $additionalInfo['Amount'] = $result->Amount;
         $additionalInfo['AuthorizationCode'] = $result->AuthorizationCode;
         if (!empty($result->Cardholder)) {
             $additionalInfo['Cardholder'] = $result->Cardholder;
         }
         if (!empty($result->AvsResponse)) {
             $additionalInfo['AvsResponse'] = $result->AvsResponse;
         }
         if (!empty($result->CvResponse)) {
             $additionalInfo['CvResponse'] = $result->AvsResponse;
         }
         $additionalInfo['CardType'] = $result->CardType;
         if (!empty($result->InvoiceNumber)) {
             $additionalInfo['InvoiceNumber'] = $result->InvoiceNumber;
         }
         $additionalInfo['Token'] = $result->Token;
         $additionalInfo['TransactionDate'] = $result->TransactionDate;
         $additionalInfo['TransactionType'] = $result->TransactionType;
         if (!empty($result->ExtraData)) {
             $additionalInfo['ExtraData'] = $result->ExtraData;
         }
         switch ($this->_parseApprovalStatus($result->ApprovalStatus)) {
             case self::APPROVAL_STATUS_APPROVED:
                 //Void Approved.
                 $message = 'Type: Void | ApprovalStatus: ' . $result->ApprovalStatus . ' |  Amount: ' . $result->Amount;
                 $payment->setSkipTransactionCreation(false);
                 $payment->setTransactionId($result->Token)->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_VOID, null, false, $message)->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, $additionalInfo)->setIsTransactionClosed(1)->save();
                 break;
             case self::APPROVAL_STATUS_DECLINED:
             case self::APPROVAL_STATUS_DECLINED_DUPLICATE:
             case self::APPROVAL_STATUS_FAILED:
                 $error = Mage::helper('merchantware_directpost')->__('Void request failed.  Gateway error response: %s', $result->ApprovalStatus, $result->ErrorMessage);
                 Mage::throwException($error);
                 break;
             case self::APPROVAL_STATUS_REFERRAL:
             default:
                 $error = Mage::helper('merchantware_directpost')->__('Unable to void this transaction. Gateway approval status: %s | Gateway error response: %s', $result->ApprovalStatus, $result->ErrorMessage);
                 Mage::throwException($error);
                 break;
         }
         return $result;
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('merchantware_directpost')->__('Gateway request error: %s', $e->getMessage()));
     }
     if ($error !== false) {
         Mage::throwException($error);
     }
     return false;
 }
 /**
  * Perform transaction for void/Reversal
  *
  * @param Mage_Payment_Model_Info $payment
  * @return string $directResponse|bool
  */
 public function createReversalTransaction($payment)
 {
     /**
      * Set the order in its own object
      */
     $order = $payment->getOrder();
     $amount = $payment->getAmount() * 100;
     // Must set 100.00 to 10000 per api
     /**
      * Create the transaction
      */
     $data = array('txRefNum' => $payment->getTransId(), 'txRefIdx' => null, 'orderID' => $this->_getUniqueOrderId($payment, $order), 'adjustedAmount' => $amount > 0 ? $amount : null, 'reversalRetryNumber' => null, 'onlineReversalInd' => "N");
     $soap_env = array(self::TRANS_REFUND_TRANS_REQUEST => array_merge($this->_getAuthentication(), $data));
     if (!($response = $this->doCall(self::TRANS_REFUND, $soap_env))) {
         return false;
     }
     $response = $response->return;
     //Mage::log("full response");
     //Mage::log($response);
     /*
     if ($response->error != null) {
         foreach ($response->error as $error) {
             if (strpos($error, self::SOAPFAULT_LOCKED_DOWN)) {
                 $this->debugData($error);
                 $this->c($paymentInfo, $amount);
             } else {
                 //$this->addError($this->_response->procStatusMessage);
                 $this->addError($error);
             }
         }
     }
     */
     $hasErrors = $this->_checkErrors();
     if ($response) {
         if (!$hasErrors) {
             $response->return->respCode = '0';
             // set for successful request (this is not set on a reversal...)
             return $response;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
コード例 #9
0
ファイル: Abstract.php プロジェクト: LybeAB/magento-module
 /**
  * Builds the base queryOrder object
  *
  * @param Mage_Payment_Model_Info $payment
  * @param $transactionId
  * @return mixed
  */
 protected function _getCancelOrderRequest(Mage_Payment_Model_Info $payment, $transactionId)
 {
     $order = $payment->getOrder();
     $paymentMethodConfig = $this->getSveaStoreConfClass($order->getStoreId());
     $config = new SveaMageConfigProvider($paymentMethodConfig);
     $countryId = $order->getBillingAddress()->getCountryId();
     $request = WebPayAdmin::cancelOrder($config)->setOrderId($transactionId)->setCountryCode($countryId);
     return $request;
 }
コード例 #10
0
 /**
  * Retrieve transaction info details
  * @param Mage_Payment_Model_Info $payment
  * @param int $transactionId
  * @return bool
  */
 public function fetchTransactionInfo(Mage_Payment_Model_Info $payment, $transactionId)
 {
     if (!$transactionId) {
         return false;
     }
     $request = $this->_getApiRequest();
     $request->setData('transaction_id', $transactionId)->setData('order_id', $payment->getOrder()->getIncrementId());
     $api = $this->_getApi()->doFetchTransactionInfo($request);
     $this->_importResultToPayment($payment, $api->getResponse());
     $apiResponse = $api->getResponse();
     return $apiResponse;
 }