We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit a0baf50a authored by rikterbeek's avatar rikterbeek

Refactor code to get Adyen CC api working

parent d4486a92
......@@ -7,6 +7,7 @@ class Index extends \Magento\Framework\App\Action\Action
{
public function execute()
{
echo 'test';die();
$this->_view->loadLayout();
$this->_view->getLayout()->initMessages();
$this->_view->renderLayout();
......
......@@ -58,7 +58,7 @@ class PaymentRequest extends \Magento\Framework\Object
"paymentRequest.merchantAccount" => $merchantAccount,
"paymentRequest.amount.currency" => "EUR",
"paymentRequest.amount.value" => "199",
"paymentRequest.reference" => "TEST-PAYMENT-" . date("Y-m-d-H:i:s"),
"paymentRequest.reference" => $order->getIncrementId(),
"paymentRequest.shopperIP" => "ShopperIPAddress",
"paymentRequest.shopperEmail" => "TheShopperEmailAddress",
"paymentRequest.shopperReference" => "YourReference",
......@@ -110,9 +110,13 @@ class PaymentRequest extends \Magento\Framework\Object
throw new \Magento\Framework\Exception\LocalizedException(__('HTTP Status code' . $results));
}
throw new \Magento\Framework\Exception\LocalizedException(__('HTTP Status code' . print_r($results, true)));
parse_str($results,$results);
// throw new \Magento\Framework\Exception\LocalizedException(__('HTTP Status code' . print_r($results, true)));
parse_str($results, $results);
$this->_logger->critical("result is" . print_r($results,true));
curl_close($ch);
......
......@@ -97,7 +97,7 @@ class Cc extends \Magento\Payment\Model\Method\Cc
public function isAvailable($quote = null)
{
$this->_logger->critical("IS AVAILABLE!! IS TRUE");
$this->_logger->critical("CC IS AVAILABLE!! IS TRUE");
return true;
}
......@@ -110,7 +110,10 @@ class Cc extends \Magento\Payment\Model\Method\Cc
*/
public function assignData($data)
{
print_r($data);die();
$this->_logger->critical("Assign data!!:" . print_r($data, true));
return parent::assignData($data);
//// print_r($data);die();
// $this->_logger->critical("TEST in validate FUNTION !!:");
}
public function validate()
......@@ -160,10 +163,19 @@ class Cc extends \Magento\Payment\Model\Method\Cc
break;
}
$this->_logger->critical("HIERRR result is " . print_r($response,true));
if (!empty($response)) {
print_r($response);die();
$this->_logger->critical("NOT EMPTY ");
// print_r($response);die();
// $this->_processResponse($payment, $response, $request);
} else {
$this->_logger->critical(" EMPTY response");
throw new \Magento\Framework\Exception\LocalizedException(__('Empty result.'));
}
......
......@@ -33,7 +33,52 @@ class Hpp extends \Magento\Payment\Model\Method\AbstractMethod implements Gatewa
protected $_canAuthorize = true;
protected $_isInitializeNeeded = true;
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
* @param \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory
* @param \Magento\Payment\Helper\Data $paymentData
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param Logger $logger
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
\Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
\Magento\Payment\Helper\Data $paymentData,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Payment\Model\Method\Logger $logger,
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
parent::__construct(
$context,
$registry,
$extensionFactory,
$customAttributeFactory,
$paymentData,
$scopeConfig,
$logger,
$resource,
$resourceCollection,
$data
);
$this->_urlBuilder = $urlBuilder;
}
public function isAvailable($quote = null)
{
$this->_logger->critical("HPP IS AVAILABLE!! IS TRUE");
return true;
}
public function initialize($paymentAction, $stateObject)
{
......@@ -79,24 +124,17 @@ class Hpp extends \Magento\Payment\Model\Method\AbstractMethod implements Gatewa
// return \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE_CAPTURE;
// }
/**
* Checkout order place redirect URL getter
* Checkout redirect URL getter for onepage checkout (hardcode)
*
* @see \Magento\Checkout\Controller\Onepage::savePaymentAction()
* @see \Magento\Quote\Model\Quote\Payment::getCheckoutRedirectUrl()
* @return string
*/
public function getOrderPlaceRedirectUrl()
public function getCheckoutRedirectUrl()
{
$this->_logger->critical("getOrderPlaceRedirectUrl");
$method = $this->getMethodInstance();
if ($method) {
$this->_logger->critical("getOrderPlaceRedirectUrl url is:" . $method->getConfigData('order_place_redirect_url'));
return $method->getConfigData('order_place_redirect_url');
} else {
$this->_logger->critical("ELSE:");
return "http://www.google.com/";
}
return '';
// return $this->_urlBuilder->getUrl('paypal/payflowexpress/start');
return $this->_urlBuilder->getUrl('adyen/process/redirect');
}
......
......@@ -17,6 +17,7 @@
<arguments>
<argument name="configProviders" xsi:type="array">
<item name="adyen_cc_config_provider" xsi:type="object">AdyenCcConfigProvider</item>
<item name="adyen_hpp_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenHppConfigProvider</item>
</argument>
</arguments>
</type>
......
......@@ -3,5 +3,8 @@
<route id="hello" frontName="hello">
<module name="Adyen_Payment" />
</route>
<route id="adyen" frontName="adyen">
<module name="Adyen_Payment" />
</route>
</router>
</config>
\ No newline at end of file
......@@ -6,54 +6,72 @@
/*global define*/
define(
[
'jquery',
'Magento_Payment/js/view/payment/iframe',
'Magento_Checkout/js/action/set-payment-information'
'Magento_Payment/js/view/payment/cc-form',
'Magento_Checkout/js/action/set-payment-information',
],
function ($, Component, setPaymentInformationAction) {
function (Component, setPaymentInformationAction) {
'use strict';
return Component.extend({
defaults: {
template: 'Adyen_Payment/payment/cc-form'
template: 'Adyen_Payment/payment/cc-form',
creditCardOwner: ''
},
initObservable: function () {
this._super()
.observe([
'creditCardType',
'creditCardExpYear',
'creditCardExpMonth',
'creditCardNumber',
'creditCardVerificationNumber',
'creditCardSsStartMonth',
'creditCardSsStartYear',
'selectedCardType',
'creditCardOwner'
]);
return this;
},
placeOrderHandler: null,
validateHandler: null,
setPlaceOrderHandler: function(handler) {
this.placeOrderHandler = handler;
},
setValidateHandler: function(handler) {
this.validateHandler = handler;
},
context: function() {
return this;
},
isShowLegend: function() {
return true;
},
getCode: function() {
return 'adyen_cc';
},
getData: function() {
return {
'method': this.item.method,
'cc_type': this.creditCardType(),
'cc_exp_year': this.creditCardExpYear(),
'cc_exp_month': this.creditCardExpMonth(),
'cc_number': this.creditCardNumber(),
'cc_owner' : this.creditCardOwner(),
additional_data: {
'cc_cid': this.creditCardVerificationNumber(),
'cc_ss_start_month': this.creditCardSsStartMonth(),
'cc_ss_start_year': this.creditCardSsStartYear()
}
};
},
isActive: function() {
return true;
},
placeOrder: function() {
var self = this;
if (this.validateHandler()) {
this.isPlaceOrderActionAllowed(false);
$.when(setPaymentInformationAction()).done(function() {
self.placeOrderHandler();
}).fail(function() {
self.isPlaceOrderActionAllowed(true);
});
}
}
getTitle: function() {
return 'Adyen cc';
},
getControllerName: function() {
return window.checkoutConfig.payment.iframe.controllerName[this.getCode()];
},
getPlaceOrderUrl: function() {
return window.checkoutConfig.payment.iframe.placeOrderUrl[this.getCode()];
},
context: function() {
return this;
},
});
}
);
......
......@@ -6,13 +6,22 @@
/*global define*/
define(
[
'Magento_Checkout/js/view/payment/default'
'jquery',
'Magento_Checkout/js/view/payment/default',
'Adyen_Payment/js/action/set-payment-method'
],
function (Component) {
function ($, Component, setPaymentMethodAction) {
'use strict';
return Component.extend({
defaults: {
template: 'Adyen_Payment/payment/hpp-form'
},
/** Redirect to adyen */
continueToAdyen: function () {
//update payment method information if additional data was changed
this.selectPaymentMethod();
setPaymentMethodAction();
return false;
}
});
}
......
......@@ -12,28 +12,12 @@
data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()"/>
<label data-bind="attr: {'for': getCode()}" class="label"><span data-bind="text: getTitle()"></span></label>
</div>
<div class="payment-method-content">
<div class="payment-method-billing-address">
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<fieldset class="fieldset" data-bind='attr: {id: "payment_form_" + getCode()}'>
<div class="payment-method-note">
<!-- ko text: $t('You will be redirected to the Adyen website.') --><!-- /ko -->
</div>
<form class="form" id="co-transparent-form" action="#" method="post" data-bind="mageInit: {
'transparent':{
'context': context(),
'controller': getControllerName(),
'gateway': getCode(),
'orderSaveUrl':getPlaceOrderUrl(),
'cgiUrl': getCgiUrl(),
'dateDelim': getDateDelim(),
'cardFieldsMap': getCardFieldsMap(),
'nativeAction': getSaveOrderUrl()
}, 'validation':[]}">
</fieldset>
<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
......@@ -43,17 +27,11 @@
<div class="primary">
<button class="action primary checkout"
type="submit"
data-bind="
click: placeOrder,
attr: {title: $t('Place Order')},
enable: (getCode() == isChecked()),
css: {disabled: !isPlaceOrderActionAllowed()}
"
data-bind="click: continueToAdyen, enable: (getCode() == isChecked())"
disabled>
<span data-bind="text: $t('Place Order')"></span>
<span data-bind="text: $t('Continue to Adyen')"></span>
</button>
</div>
</div>
</form>
</div>
</div>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment