示例#1
0
 public function getLanguage()
 {
     $langCode = $this->language;
     if ($this->language == 'store') {
         $langCode = Payfort_Fort_Language::getCurrentLanguageCode();
     }
     if ($langCode != 'ar') {
         $langCode = 'en';
     }
     return $langCode;
 }
 public function __construct()
 {
     global $woocommerce;
     $this->has_fields = false;
     $this->load_plugin_textdomain();
     $this->icon = apply_filters('woocommerce_FORT_icon', PAYFORT_FORT_URL . 'assets/images/cards.png');
     if (is_admin()) {
         $this->has_fields = true;
         $this->init_form_fields();
     }
     // Define user set variables
     $this->title = Payfort_Fort_Language::__('Credit / Debit Card');
     $this->description = $this->get_option('description');
     $this->pfConfig = Payfort_Fort_Config::getInstance();
     $this->pfHelper = Payfort_Fort_Helper::getInstance();
     $this->pfPayment = Payfort_Fort_Payment::getInstance();
     $this->enable_sadad = $this->get_option('enable_sadad') == 'yes' ? true : false;
     $baseCurrency = $this->pfHelper->getBaseCurrency();
     $frontCurrency = $this->pfHelper->getFrontCurrency();
     if ($this->pfHelper->getFortCurrency($baseCurrency, $frontCurrency) != 'SAR') {
         $this->enable_sadad = false;
     }
     $this->enable_naps = $this->get_option('enable_naps') == 'yes' ? true : false;
     if ($this->pfHelper->getFortCurrency($baseCurrency, $frontCurrency) != 'QAR') {
         $this->enable_naps = false;
     }
     $this->enable_credit_card = $this->get_option('enable_credit_card') == 'yes' ? true : false;
     // Actions
     add_action('woocommerce_receipt_' . $this->id, array($this, 'receipt_page'));
     add_action('wp_enqueue_scripts', array($this, 'payment_scripts'));
     // Save options
     add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options'));
     if (!$this->is_valid_for_use()) {
         $this->enabled = false;
     }
     //add_action('woocommerce_api_'.strtolower(get_class($this).'_process_response'), array(&$this, 'process_response'));
     //add_action('woocommerce_api_'.strtolower(get_class($this).'_merchantPageResponse'), array(&$this, 'merchantPageResponse'));
     //add_action('woocommerce_api_'.strtolower(get_class($this).'_merchantPageCancel'), array(&$this, 'merchantPageCancel'));
     add_action('woocommerce_wc_gateway_payfort_fort_process_response', array(&$this, 'process_response'));
     add_action('woocommerce_wc_gateway_payfort_fort_responseOnline', array(&$this, 'responseOnline'));
     add_action('woocommerce_wc_gateway_payfort_fort_merchantPageResponse', array(&$this, 'merchantPageResponse'));
     add_action('woocommerce_wc_gateway_payfort_fort_merchantPageCancel', array(&$this, 'merchantPageCancel'));
 }
示例#3
0
 public function merchantPageCancel()
 {
     $orderId = $this->pfOrder->getSessionOrderId();
     $this->pfOrder->loadOrder($orderId);
     if ($orderId) {
         $this->pfOrder->cancelOrder();
     }
     $this->pfHelper->setFlashMsg(Payfort_Fort_Language::__('text_payment_canceled'));
     return true;
 }
示例#4
0
 public function successOrder($response_params, $response_mode)
 {
     $status = $this->pfConfig->getSuccessOrderStatusId();
     $response_message = Payfort_Fort_Language::__('Redirecting, please wait...');
     $success = true;
     try {
         /** trying to create invoice * */
         if (!$this->order->canInvoice()) {
             $response_message = Mage::helper('core')->__('cannot create an invoice !');
             //already created invoice by host to host
             $success = false;
             Mage::throwException(Mage::helper('core')->__('cannot create an invoice !'));
         } else {
             /** create invoice  * */
             //$invoiceId = Mage::getModel('sales/order_invoice_api')->create($this->order->getIncremenetId(), array());
             $invoice = Mage::getModel('sales/service_order', $this->order)->prepareInvoice();
             if (!$invoice->getTotalQty()) {
                 $response_message = Mage::helper('core')->__('cannot create an invoice without products !');
                 //already created invoice by host to host
                 $success = false;
                 Mage::throwException(Mage::helper('core')->__('cannot create an invoice without products !'));
             }
             if ($success) {
                 $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
                 $invoice->register();
                 $transactionSave = Mage::getModel('core/resource_transaction')->addObject($invoice)->addObject($invoice->getOrder());
                 $transactionSave->save();
                 $this->order->setState($status, true, 'Payfort has accepted the payment.');
             }
             /** load invoice * */
             //$invoice = Mage::getModel('sales/order_invoice')->loadByIncrementId($invoiceId);
             /** pay invoice * */
             //$invoice->capture()->save();
         }
     } catch (Mage_Core_Exception $e) {
         //Mage::throwException(Mage::helper('core')->__('cannot create an invoice !'));
         return array($success, $response_message);
     }
     if ($success) {
         if ($response_mode == 'offline') {
             $this->order->sendNewOrderEmail();
             $this->order->setEmailSent(true);
             $this->order->save();
         }
         $response_status = $response_params['status'];
         if ($response_status == 14) {
             $response_message = Payfort_Fort_Language::__('Your payment is accepted.');
         } elseif ($response_status == 02) {
             $response_message = Payfort_Fort_Language::__('Your payment is authorized.');
         } else {
             $response_message = Payfort_Fort_Language::__('Unknown response status.');
         }
     }
     return array($success, $response_message);
 }