Skip to content

Commit

Permalink
Update checkout form as details are updated
Browse files Browse the repository at this point in the history
Changed the hidden form from being generated on the server side to
be generated on the client side instead. Added event listeners to
update the form as user details are modified.

Added scope settings to allow branding configuration to be changed
at the store level. Updated front end code to request data in the
correct scope.

Changes should fix issues #10, #17, #18 and #22.
  • Loading branch information
iugo-josh committed Mar 14, 2017
1 parent 13deaab commit 042f4f8
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 176 deletions.
117 changes: 0 additions & 117 deletions Oxipay/OxipayPaymentGateway/Block/Formoxipay.php

This file was deleted.

83 changes: 83 additions & 0 deletions Oxipay/OxipayPaymentGateway/Controller/Checkout/RequestDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Oxipay\OxipayPaymentGateway\Controller\Checkout;

use Magento\Framework\DataObject;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Controller\ResultFactory;

class RequestDetails extends \Magento\Framework\App\Action\Action
{
protected $_scopeConfigInterface;
protected $_checkoutSession;
protected $_urlBuilder;
protected $_oxipayCrypto;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $configInterface,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Framework\UrlInterface $urlBuilder,
\Oxipay\OxipayPaymentGateway\Gateway\Http\OxipayCrypto $oxipayCrypto)
{
parent::__construct($context);

$this->_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;
}
}
2 changes: 1 addition & 1 deletion Oxipay/OxipayPaymentGateway/Model/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
?>
8 changes: 5 additions & 3 deletions Oxipay/OxipayPaymentGateway/Model/Ui/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down
9 changes: 4 additions & 5 deletions Oxipay/OxipayPaymentGateway/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<system>
<section id="payment" translate="label" sortOrder="300" type="text" showInDefault="1" showInWebsite="1" showInStore="1">

<group id="oxipay_gateway" translate="label" sortOrder="100" type="text" showInDefault="1" showInWebsite="1">
<group id="oxipay_gateway" translate="label" sortOrder="100" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Oxipay Payment Gateway</label>
<field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="0">
<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Title</label>
</field>
<field id="description" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
<field id="description" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Description</label>
</field>
<field id="gateway_logo" translate="label comment" type="image" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
Expand Down Expand Up @@ -40,8 +40,7 @@
<label>Test Mode</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="sort_order" translate="label" type="text" sortOrder="160" showInDefault="1" showInWebsite="1"
showInStore="0">
<field id="sort_order" translate="label" type="text" sortOrder="160" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Sort Order</label>
<frontend_class>validate-number</frontend_class>
</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,5 @@
</argument>
</arguments>
</referenceBlock>
<referenceContainer name="content">
<block class="Oxipay\OxipayPaymentGateway\Block\Formoxipay" name="oxipay_formoxipay" template="Oxipay_OxipayPaymentGateway::formoxipay.phtml" method="append" />
</referenceContainer>
</body>
</page>

This file was deleted.

Loading

0 comments on commit 042f4f8

Please sign in to comment.