diff --git a/Oxipay/OxipayPaymentGateway/Block/Formoxipay.php b/Oxipay/OxipayPaymentGateway/Block/Formoxipay.php deleted file mode 100644 index d7adc27..0000000 --- a/Oxipay/OxipayPaymentGateway/Block/Formoxipay.php +++ /dev/null @@ -1,117 +0,0 @@ -_scopeConfigInterface = $configInterface; - $this->customerSession = $customerSession; - $this->sessionQuote = $sessionQuote; - $this->_urlBuilder = $context->getUrlBuilder(); - } - - public function getPaymentForm() - { - $om = \Magento\Framework\App\ObjectManager::getInstance(); - $customerSession = $om->get('Magento\Customer\Model\Session'); - $cart = $om->get('\Magento\Checkout\Model\Cart'); - $store = $om->get('Magento\Store\Model\StoreManagerInterface'); - $checkout = $om->get('Oxipay\OxipayPaymentGateway\Model\Checkout'); - $billingAddress = $cart->getQuote()->getBillingAddress(); - $shippingAddress= $cart->getQuote()->getShippingAddress(); - $CustomerID= $customerSession->getCustomer()->getId(); - $firstname=$customerSession->getCustomer()->getFirstname(); - $lastname= $customerSession->getCustomer()->getLastname(); - $email = $customerSession->getCustomer()->getEmail(); - $query =Array - ( - 'x_reference' => $cart->getQuote()->getId(), - 'x_account_id' => $checkout->getConfigData('payment/oxipay_gateway/merchant_number'), - 'x_amount' => (float)$cart->getQuote()->getGrandTotal(), - 'x_currency' => $store->getStore()->getCurrentCurrencyCode(), - 'x_url_callback' =>$this->_urlBuilder->getUrl("oxipay/checkout/saveorder",['quoteId' => $cart->getQuote()->getId()]), - 'x_url_complete' => $this->_urlBuilder->getUrl("oxipay/checkout/success",['quoteId' => $cart->getQuote()->getId()]), - 'x_url_cancel' => $this->_urlBuilder->getUrl("checkout"), - 'x_test' => $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/test_mode') ? 'true' : 'false', - 'x_shop_country' => 'AU', - 'x_shop_name' =>$store->getStore()->getName(), - 'x_customer_first_name' => $firstname, - 'x_customer_last_name' => $lastname, - 'x_customer_email' => $email, - 'x_customer_phone' => $billingAddress->getTelephone(), - 'x_customer_billing_country' => $billingAddress->getCountryId(), - 'x_customer_billing_city' => $billingAddress->getCity(), - 'x_customer_billing_address1' => $billingAddress->getStreetLine(1), - 'x_customer_billing_address2' => $billingAddress->getStreetLine(2), - 'x_customer_billing_state' => 'ACT', - 'x_customer_billing_zip' => $billingAddress->getPostcode(), - 'x_customer_shipping_country' => $shippingAddress->getCountryId(), - 'x_customer_shipping_city' => $shippingAddress->getCity(), - 'x_customer_shipping_address1' => $shippingAddress->getStreetLine(1), - 'x_customer_shipping_address2'=> $shippingAddress->getStreetLine(2), - 'x_customer_shipping_state' => '', - 'x_customer_shipping_zip' => $shippingAddress->getPostcode(), - 'gateway_url' => $this->getUrlGateway(), - ); - $signature = $this->oxipay_sign($query, $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/api_key')); - $query['x_signature'] = $signature; - return $this->generate_processing_form($query); - } - public function getConfigDataETS($key) - { - return $key; - return Mage::getStoreConfig('payment/oxipay_gateway/' . $key); - } - function generate_processing_form($query) { - $url = $query["gateway_url"]; - - $html ="
"; - return $html; - } - public function getUrlGateway() - { - return $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/gateway_url'); - } - public function oxipay_sign($query, $api_key ) - { - $clear_text = ''; - ksort($query); - foreach ($query as $key => $value) { - if (substr($key, 0, 2) === "x_") { - $clear_text .= $key . $value; - } - } - $hash = hash_hmac( "sha256", $clear_text, $api_key); - return str_replace('-', '', $hash); - } - public function displayErrors() - { - $om = \Magento\Framework\App\ObjectManager::getInstance(); - $store = $om->get('Magento\Store\Model\StoreManagerInterface'); - $cart = $om->get('\Magento\Checkout\Model\Cart'); - $error_oxipay= $this->getRequest()->getParam('error_oixpay'); - if($error_oxipay) - return true; - else - return false; - - } -} \ No newline at end of file diff --git a/Oxipay/OxipayPaymentGateway/Controller/Checkout/RequestDetails.php b/Oxipay/OxipayPaymentGateway/Controller/Checkout/RequestDetails.php new file mode 100644 index 0000000..ab55d2d --- /dev/null +++ b/Oxipay/OxipayPaymentGateway/Controller/Checkout/RequestDetails.php @@ -0,0 +1,83 @@ +_scopeConfigInterface = $configInterface; + $this->_checkoutSession = $checkoutSession; + $this->_urlBuilder = $urlBuilder; + $this->_oxipayCrypto = $oxipayCrypto; + } + + public function execute() + { + $request = $this->getRequest(); + $response = $this->resultFactory->create(ResultFactory::TYPE_JSON); + + $quote = $this->_checkoutSession->getQuote(); + $store = $quote->getStore(); + + $storeCountry = $this->_scopeConfigInterface->getValue('general/store_information/country_id', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); + //default to Australia if not set + if(strlen($storeCountry) == 0){ + $storeCountry = 'AU'; + } + + //data to be sent to Oxipay + $data = [ + 'x_reference' => $quote->getId(), + 'x_account_id' => $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/merchant_number', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE), + 'x_amount' => $request->getParam('amount'), + 'x_currency' => $request->getParam('currency'), + 'x_url_callback' => $this->_urlBuilder->getUrl("oxipay/checkout/saveorder", ['quoteId' => $quote->getId()]), + 'x_url_complete' => $this->_urlBuilder->getUrl("oxipay/checkout/success", ['quoteId' => $quote->getId()]), + 'x_url_cancel' => $this->_urlBuilder->getUrl("checkout"), + 'x_test' => $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/test_mode', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) ? 'true' : 'false', + 'x_shop_country' => $storeCountry, + 'x_shop_name' => $this->_scopeConfigInterface->getValue('general/store_information/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), + 'x_customer_first_name' => $request->getParam('customer_first_name'), + 'x_customer_last_name' => $request->getParam('customer_last_name'), + 'x_customer_email' => $request->getParam('customer_email'), + 'x_customer_phone' => $request->getParam('customer_phone'), + 'x_customer_billing_country' => $request->getParam('customer_billing_country'), + 'x_customer_billing_city' => $request->getParam('customer_billing_city'), + 'x_customer_billing_address1' => $request->getParam('customer_billing_address1'), + 'x_customer_billing_address2' => $request->getParam('customer_billing_address2'), + 'x_customer_billing_state' => $request->getParam('customer_billing_state'), + 'x_customer_billing_zip' => $request->getParam('customer_billing_zip'), + 'x_customer_shipping_country' => $request->getParam('customer_shipping_country'), + 'x_customer_shipping_city' => $request->getParam('customer_shipping_city'), + 'x_customer_shipping_address1' => $request->getParam('customer_shipping_address1'), + 'x_customer_shipping_address2'=> $request->getParam('customer_shipping_address2'), + 'x_customer_shipping_state' => $request->getParam('customer_shipping_state'), + 'x_customer_shipping_zip' => $request->getParam('customer_shipping_zip'), + ]; + + //sign the data + $data = $this->_oxipayCrypto->sign($data, $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/api_key', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE)); + + //return it to the front end + $response->setData($data); + + return $response; + } +} \ No newline at end of file diff --git a/Oxipay/OxipayPaymentGateway/Model/Checkout.php b/Oxipay/OxipayPaymentGateway/Model/Checkout.php index ed29f51..394f4a9 100644 --- a/Oxipay/OxipayPaymentGateway/Model/Checkout.php +++ b/Oxipay/OxipayPaymentGateway/Model/Checkout.php @@ -85,7 +85,7 @@ private function getCheckoutMethod($quote) } public function getConfigData($key) { - return $this->_scopeConfigInterface->getValue($key); + return $this->_scopeConfigInterface->getValue($key, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } } ?> \ No newline at end of file diff --git a/Oxipay/OxipayPaymentGateway/Model/Ui/ConfigProvider.php b/Oxipay/OxipayPaymentGateway/Model/Ui/ConfigProvider.php index 6e1c5f8..1b23903 100644 --- a/Oxipay/OxipayPaymentGateway/Model/Ui/ConfigProvider.php +++ b/Oxipay/OxipayPaymentGateway/Model/Ui/ConfigProvider.php @@ -52,14 +52,16 @@ public function getConfig() OxipayClient::FAILURE => __('Failure') ], 'errors' => $this->action->getRequest()->getParams('error_oxipay')?'The Payment provider rejected the transaction. Please try again.':'', - 'description' => $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/description'), + 'title' => $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), + 'description' => $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/description', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), + 'gateway_url' => $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/gateway_url', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE), ] ] ]; - $logoFile = $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/gateway_logo'); + $logoFile = $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/gateway_logo', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if(strlen($logoFile) > 0){ - $logo = '../pub/media/sales/store/logo/' . $this->_scopeConfigInterface->getValue('payment/oxipay_gateway/gateway_logo'); + $logo = '../pub/media/sales/store/logo/' . $logoFile; } else{ $params = ['_secure' => $this->action->getRequest()->isSecure()]; diff --git a/Oxipay/OxipayPaymentGateway/etc/adminhtml/system.xml b/Oxipay/OxipayPaymentGateway/etc/adminhtml/system.xml index f8fce72..5db8ab9 100644 --- a/Oxipay/OxipayPaymentGateway/etc/adminhtml/system.xml +++ b/Oxipay/OxipayPaymentGateway/etc/adminhtml/system.xml @@ -3,16 +3,16 @@