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;
}
});
}
......
......@@ -21,6 +21,7 @@
</div>
<form class="form" id="co-transparent-form" action="#" method="post" data-bind="mageInit: {
'transparent':{
'context': context(),
......@@ -29,11 +30,203 @@
}, 'validation':[]}">
<input type="hidden" name="payment[test]" value="TEST"/>
<!-- ko template: 'Magento_Payment/payment/cc-form' --><!-- /ko -->
<fieldset data-bind="attr: {class: 'fieldset payment items ccard ' + getCode(), id: 'payment_form_' + getCode()}">
<!-- ko if: (isShowLegend())-->
<legend class="legend">
<span><!-- ko i18n: 'Credit Card Information'--><!-- /ko --></span>
</legend><br />
<!-- /ko -->
<div class="field type required">
<label data-bind="attr: {for: getCode() + '_cc_type'}" class="label">
<span><!-- ko i18n: 'Credit Card Type'--><!-- /ko --></span>
</label>
<div class="control">
<ul class="credit-card-types">
<!-- ko foreach: {data: getCcAvailableTypesValues(), as: 'item'} -->
<li class="item" data-bind="css: {_active: $parent.selectedCardType() == item.value} ">
<!--ko if: $parent.getIcons(item.value) -->
<img data-bind="attr: {
'src': $parent.getIcons(item.value).url,
'alt': item.type,
'width': $parent.getIcons(item.value).width,
'height': $parent.getIcons(item.value).height
}">
<!--/ko-->
</li>
<!--/ko-->
</ul>
<input type="hidden"
name="payment[cc_type]"
class="input-text"
value=""
data-bind="attr: {id: getCode() + '_cc_type', 'data-container': getCode() + '-cc-type'},
value: creditCardType
">
</div>
</div>
<div class="field number required">
<label data-bind="attr: {for: getCode() + '_cc_number'}" class="label">
<span><!-- ko i18n: 'Credit Card Number'--><!-- /ko --></span>
</label>
<div class="control">
<input type="number" name="payment[cc_number]" class="input-text" value=""
data-bind="attr: {
autocomplete: off,
id: getCode() + '_cc_number',
title: $t('Credit Card Number'),
'data-container': getCode() + '-cc-number',
'data-validate': JSON.stringify({'required-number':true, 'validate-card-number':'#' + getCode() + '_cc_type', 'validate-cc-type':'#' + getCode() + '_cc_type'})},
enable: isActive($parents),
value: creditCardNumber,
valueUpdate: 'keyup' "/>
</div>
</div>
<div class="field type required">
<label data-bind="attr: {for: getCode() + '_cc_owner'}" class="label">
<span><!-- ko i18n: 'Credit Card Owner'--><!-- /ko --></span>
</label>
<div class="control">
<input type="text"
name="payment[cc_owner]"
class="input-text"
value=""
data-bind="attr: {id: getCode() + '_cc_owner', 'data-container': getCode() + '-cc-owner'},
enable: isActive($parents),
value: creditCardOwner">
</div>
</div>
<div class="field date required" data-bind="attr: {id: getCode() + '_cc_type_exp_div'}">
<label data-bind="attr: {for: getCode() + '_expiration'}" class="label">
<span><!-- ko i18n: 'Expiration Date'--><!-- /ko --></span>
</label>
<div class="control">
<div class="fields group group-2">
<div class="field no-label month">
<div class="control">
<select name="payment[cc_exp_month]"
class="select select-month"
data-bind="attr: {id: getCode() + '_expiration', 'data-container': getCode() + '-cc-month', 'data-validate': JSON.stringify({required:true, 'validate-cc-exp':'#' + getCode() + '_expiration_yr'})},
enable: isActive($parents),
options: getCcMonthsValues(),
optionsValue: 'value',
optionsText: 'month',
optionsCaption: $t('Month'),
value: creditCardExpMonth">
</select>
</div>
</div>
<div class="field no-label year">
<div class="control">
<select name="payment[cc_exp_year]"
class="select select-year"
data-bind="attr: {id: getCode() + '_expiration_yr', 'data-container': getCode() + '-cc-year', 'data-validate': JSON.stringify({required:true})},
enable: isActive($parents),
options: getCcYearsValues(),
optionsValue: 'value',
optionsText: 'year',
optionsCaption: $t('Year'),
value: creditCardExpYear">
</select>
</div>
</div>
</div>
</div>
</div>
<!-- ko if: (hasVerification())-->
<div class="field cvv required" data-bind="attr: {id: getCode() + '_cc_type_cvv_div'}">
<label data-bind="attr: {for: getCode() + '_cc_cid'}" class="label">
<span><!-- ko i18n: 'Card Verification Number'--><!-- /ko --></span>
</label>
<div class="control _with-tooltip">
<input type="number"
autocomplete="off"
class="input-text cvv"
name="payment[cc_cid]"
value=""
data-bind="attr: {id: getCode() + '_cc_cid',
title: $t('Card Verification Number'),
'data-container': getCode() + '-cc-cvv',
'data-validate': JSON.stringify({'required-number':true, 'validate-card-cvv':'#' + getCode() + '_cc_type'})},
enable: isActive($parents),
value: creditCardVerificationNumber" />
<div class="field-tooltip toggle">
<span class="field-tooltip-action action-cvv"
tabindex="0"
data-toggle="dropdown"
data-bind="attr: {title: $t('What is this?')}, mageInit: {'dropdown':{'activeClass': '_active'}}">
<span><!-- ko i18n: 'What is this?'--><!-- /ko --></span>
</span>
<div class="field-tooltip-content"
data-target="dropdown"
data-bind="html: getCvvImageHtml()"></div>
</div>
</div>
</div>
<!-- /ko -->
<!-- ko if: (hasSsCardType())-->
<div class="field switch solo required" data-bind="attr: {id: getCode() + '_cc_type_ss_div'}">
<div class="nested">
<div class="field switch-solo required">
<label data-bind="attr: {for: getCode() + '_cc_issue'}" class="label">
<span><!-- ko i18n: 'Switch/Solo/Maestro Only'--><!-- /ko --></span>
</label>
</div>
<div class="field number required">
<label data-bind="attr: {for: getCode() + '_cc_issue'}" class="label">
<span><!-- ko i18n: 'Issue Number'--><!-- /ko --></span>
</label>
<div class="control">
<input type="number" name="payment[cc_ss_issue]"
value=""
class="input-text cvv"
data-bind="attr: {id: getCode() + '_cc_issue', title: $t('Issue Number'), 'data-container': getCode() + '-cc-issue', 'data-validate': JSON.stringify({'validate-cc-ukss':true})}, enable: isActive($parents)"/>
</div>
</div>
<div class="field date required">
<label data-bind="attr: {for: getCode() + '_start_month'}" class="label">
<span><!-- ko i18n: 'Start Date'--><!-- /ko --></span>
</label>
<div class="control">
<div class="fields group group-2">
<div class="field no-label month">
<div class="control">
<select name="payment[cc_ss_start_month]"
class="select select-month"
data-bind="attr: {id: getCode() + '_start_month', 'data-container': getCode() + '-cc-start-month', 'data-validate': JSON.stringify({'validate-cc-ukss':true})},
enable: isActive($parents),
options: getCcMonthsValues(),
optionsValue: 'value',
optionsText: 'month',
optionsCaption: $t('Month'),
value: creditCardSsStartMonth">
</select>
</div>
</div>
<div class="field no-label year">
<div class="control">
<select name="payment[cc_ss_start_year]"
class="select select-year"
data-bind="attr: {id: getCode() + '_start_year', 'data-container': getCode() + '-cc-start-year',
'data-validate': JSON.stringify({'validate-cc-ukss':true})},
enable: isActive($parents),
options: getSsStartYearsValues(),
optionsValue: 'value',
optionsText: 'year',
optionsCaption: $t('Year'),
value: creditCardSsStartYear">
</select>
</div>
</div>
</div>
</div>
</div>
<div class="adv container" data-validation-msg="validate-cc-ukss">&nbsp;</div>
</div>
</div>
<!-- /ko -->
</fieldset>
<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
......@@ -58,3 +251,6 @@
</form>
</div>
</div>
......@@ -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