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 98723b54 authored by Rik ter Beek's avatar Rik ter Beek Committed by GitHub

Merge pull request #591 from Adyen/feature/PW-1835

[PW-1835] paymentMethods endpoint returns all payment methods. Filter…
parents 960c7cd6 83fc873c
...@@ -1098,43 +1098,6 @@ class Data extends AbstractHelper ...@@ -1098,43 +1098,6 @@ class Data extends AbstractHelper
return false; return false;
} }
/**
* @return mixed
*/
/**
* @param $paymentMethod
* @return bool
*/
public function isPaymentMethodBcmcMobileQRMethod($paymentMethod)
{
if (strpos($paymentMethod, 'bcmc_mobile_QR') !== false) {
return true;
}
return false;
}
/**
* The payment method for wechat should be only wechatweb until we support the others too.
*
* @param $paymentMethod
* @return bool
*/
public function isPaymentMethodWechatpayExceptWeb($paymentMethod)
{
if (strpos($paymentMethod, 'wechatpay') !== false) {
if (strpos($paymentMethod, 'wechatpayWeb') !== false) {
return false;
}
return true;
}
return false;
}
public function getRatePayId() public function getRatePayId()
{ {
return $this->getAdyenHppConfigData("ratepay_id"); return $this->getAdyenHppConfigData("ratepay_id");
...@@ -1156,18 +1119,6 @@ class Data extends AbstractHelper ...@@ -1156,18 +1119,6 @@ class Data extends AbstractHelper
return false; return false;
} }
/**
* @param $paymentMethod
* @return bool
*/
public function isPaymentMethodBoletoMethod($paymentMethod)
{
if (strpos($paymentMethod, 'boleto') !== false) {
return true;
}
return false;
}
/** /**
* @return bool * @return bool
*/ */
......
...@@ -135,41 +135,7 @@ class PaymentMethods extends AbstractHelper ...@@ -135,41 +135,7 @@ class PaymentMethods extends AbstractHelper
$quote = $this->quoteRepository->getActive($quoteId); $quote = $this->quoteRepository->getActive($quoteId);
$store = $quote->getStore(); $store = $quote->getStore();
$paymentMethods = $this->addHppMethodsToConfig($store, $country); $paymentMethods = $this->fetchAlternativeMethods($store, $country);
return $paymentMethods;
}
/**
* @param $store
* @return array
*/
protected function addHppMethodsToConfig($store, $country)
{
$paymentMethods = [];
$ccEnabled = $this->config->getValue(
'payment/' . \Adyen\Payment\Model\Ui\AdyenCcConfigProvider::CODE . '/active',
\Magento\Store\Model\ScopeInterface::SCOPE_STORES,
$store->getCode()
);
$ccTypes = array_keys($this->adyenHelper->getCcTypesAltData());
foreach ($this->fetchAlternativeMethods($store, $country) as $methodCode => $methodData) {
/*
* skip payment methods if it is a creditcard that is enabled in adyen_cc or a boleto method or wechat but
* not wechatpay
*/
if (($ccEnabled && in_array($methodCode, $ccTypes)) ||
$this->adyenHelper->isPaymentMethodBoletoMethod($methodCode) ||
$this->adyenHelper->isPaymentMethodBcmcMobileQRMethod($methodCode) ||
$this->adyenHelper->isPaymentMethodWechatpayExceptWeb($methodCode)
) {
continue;
}
$paymentMethods[$methodCode] = $methodData;
}
return $paymentMethods; return $paymentMethods;
} }
...@@ -215,10 +181,6 @@ class PaymentMethods extends AbstractHelper ...@@ -215,10 +181,6 @@ class PaymentMethods extends AbstractHelper
if (isset($responseData['paymentMethods'])) { if (isset($responseData['paymentMethods'])) {
foreach ($responseData['paymentMethods'] as $paymentMethod) { foreach ($responseData['paymentMethods'] as $paymentMethod) {
if ($paymentMethod['type'] == "scheme") {
continue;
}
$paymentMethodCode = $paymentMethod['type']; $paymentMethodCode = $paymentMethod['type'];
$paymentMethod = $this->fieldMapPaymentMethod($paymentMethod); $paymentMethod = $this->fieldMapPaymentMethod($paymentMethod);
......
...@@ -43,6 +43,7 @@ define( ...@@ -43,6 +43,7 @@ define(
var paymentMethod = ko.observable(null); var paymentMethod = ko.observable(null);
var messageComponents; var messageComponents;
var shippingAddressCountryCode = quote.shippingAddress().countryId; var shippingAddressCountryCode = quote.shippingAddress().countryId;
var unsupportedPaymentMethods = ['scheme', 'boleto', 'bcmc_mobile_QR', 'wechatpay'];
/** /**
* Shareble adyen checkout component * Shareble adyen checkout component
* @type {AdyenCheckout} * @type {AdyenCheckout}
...@@ -70,7 +71,7 @@ define( ...@@ -70,7 +71,7 @@ define(
'bankLocationId' 'bankLocationId'
]); ]);
return this; return this;
},initialize: function () { }, initialize: function () {
var self = this; var self = this;
this._super(); this._super();
...@@ -87,9 +88,9 @@ define( ...@@ -87,9 +88,9 @@ define(
// reset variable: // reset variable:
adyenPaymentService.setPaymentMethods(); adyenPaymentService.setPaymentMethods();
adyenPaymentService.retrieveAvailablePaymentMethods(function() { adyenPaymentService.retrieveAvailablePaymentMethods(function () {
let paymentMethods = adyenPaymentService.getAvailablePaymentMethods(); var paymentMethods = adyenPaymentService.getAvailablePaymentMethods();
if (JSON.stringify(paymentMethods).indexOf("ratepay") > -1) { if (JSON.stringify(paymentMethods).indexOf("ratepay") > -1) {
var ratePayId = window.checkoutConfig.payment.adyenHpp.ratePayId; var ratePayId = window.checkoutConfig.payment.adyenHpp.ratePayId;
var dfValueRatePay = self.getRatePayDeviceIdentToken(); var dfValueRatePay = self.getRatePayDeviceIdentToken();
...@@ -133,7 +134,7 @@ define( ...@@ -133,7 +134,7 @@ define(
}, },
getAdyenHppPaymentMethods: function () { getAdyenHppPaymentMethods: function () {
var self = this; var self = this;
let currentShippingAddressCountryCode = quote.shippingAddress().countryId; var currentShippingAddressCountryCode = quote.shippingAddress().countryId;
// retrieve new payment methods if country code changed // retrieve new payment methods if country code changed
if (shippingAddressCountryCode != currentShippingAddressCountryCode) { if (shippingAddressCountryCode != currentShippingAddressCountryCode) {
...@@ -145,14 +146,19 @@ define( ...@@ -145,14 +146,19 @@ define(
var paymentMethods = adyenPaymentService.getAvailablePaymentMethods(); var paymentMethods = adyenPaymentService.getAvailablePaymentMethods();
var paymentList = _.map(paymentMethods, function (value) { var paymentList = _.reduce(paymentMethods, function (accumulator, value) {
if (!self.isPaymentMethodSupported(value.type)) {
return accumulator;
}
var result = {}; var result = {};
/** /**
* Returns the payment method's brand code (in checkout api it is the type) * Returns the payment method's brand code (in checkout api it is the type)
* @returns {*} * @returns {*}
*/ */
result.getBrandCode = function() { result.getBrandCode = function () {
return self.getBrandCodeFromPaymentMethod(value); return self.getBrandCodeFromPaymentMethod(value);
}; };
...@@ -180,7 +186,7 @@ define( ...@@ -180,7 +186,7 @@ define(
* @param bool * @param bool
* @returns {*} * @returns {*}
*/ */
result.isPlaceOrderAllowed = function(bool) { result.isPlaceOrderAllowed = function (bool) {
self.isPlaceOrderActionAllowed(bool); self.isPlaceOrderActionAllowed(bool);
return result.placeOrderAllowed(bool); return result.placeOrderAllowed(bool);
}; };
...@@ -191,11 +197,11 @@ define( ...@@ -191,11 +197,11 @@ define(
* @param bool * @param bool
* @returns {*} * @returns {*}
*/ */
result.isPlaceOrderAllowed = function(bool) { result.isPlaceOrderAllowed = function (bool) {
self.isPlaceOrderActionAllowed(bool); self.isPlaceOrderActionAllowed(bool);
return result.placeOrderAllowed(bool); return result.placeOrderAllowed(bool);
}; };
result.afterPlaceOrder = function() { result.afterPlaceOrder = function () {
return self.afterPlaceOrder(); return self.afterPlaceOrder();
}; };
/** /**
...@@ -282,7 +288,7 @@ define( ...@@ -282,7 +288,7 @@ define(
result.findIssuersProperty = function () { result.findIssuersProperty = function () {
var issuerKey = false; var issuerKey = false;
if (typeof value.details !== 'undefined') { if (typeof value.details !== 'undefined') {
$.each(value.details, function(key, detail) { $.each(value.details, function (key, detail) {
if (typeof detail.items !== 'undefined' && detail.key == 'issuer') { if (typeof detail.items !== 'undefined' && detail.key == 'issuer') {
issuerKey = key; issuerKey = key;
} }
...@@ -317,7 +323,7 @@ define( ...@@ -317,7 +323,7 @@ define(
* Returns the issuers for a payment method * Returns the issuers for a payment method
* @returns {*} * @returns {*}
*/ */
result.getIssuers = function() { result.getIssuers = function () {
if (result.hasIssuersAvailable()) { if (result.hasIssuersAvailable()) {
return value.details[result.findIssuersProperty()].items; return value.details[result.findIssuersProperty()].items;
} }
...@@ -502,11 +508,31 @@ define( ...@@ -502,11 +508,31 @@ define(
result.bankLocationId = ko.observable(null); result.bankLocationId = ko.observable(null);
} }
return result; accumulator.push(result);
}); return accumulator;
}, []);
return paymentList; return paymentList;
}, },
/**
* Some payment methods we do not want to render as it requires extra implementation
* or is already implemented in a separate payment method.
* Using a match as we want to prevent to render all Boleto and most of the WeChat types
* @param paymentMethod
* @returns {boolean}
*/
isPaymentMethodSupported: function (paymentMethod) {
if (paymentMethod == 'wechatpayWeb') {
return true;
}
for (var i = 0; i < unsupportedPaymentMethods.length; i++) {
var match = paymentMethod.match(unsupportedPaymentMethods[i]);
if (match) {
return false;
}
}
return true;
},
getGenderTypes: function () { getGenderTypes: function () {
return _.map(window.checkoutConfig.payment.adyenHpp.genderTypes, function (value, key) { return _.map(window.checkoutConfig.payment.adyenHpp.genderTypes, function (value, key) {
return { return {
...@@ -575,13 +601,13 @@ define( ...@@ -575,13 +601,13 @@ define(
return true; return true;
}, },
placeRedirectOrder: function(data) { placeRedirectOrder: function (data) {
// Place Order but use our own redirect url after // Place Order but use our own redirect url after
var self = this; var self = this;
fullScreenLoader.startLoader(); fullScreenLoader.startLoader();
var messageContainer = this.messageContainer; var messageContainer = this.messageContainer;
if(brandCode()) { if (brandCode()) {
messageContainer = self.messageComponents['messages-' + brandCode()]; messageContainer = self.messageComponents['messages-' + brandCode()];
} }
...@@ -599,7 +625,7 @@ define( ...@@ -599,7 +625,7 @@ define(
$("#messages-" + brandCode()).text(response['responseJSON'].message).slideDown(); $("#messages-" + brandCode()).text(response['responseJSON'].message).slideDown();
} }
setTimeout(function(){ setTimeout(function () {
$("#messages-" + brandCode()).slideUp(); $("#messages-" + brandCode()).slideUp();
}, 10000); }, 10000);
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
...@@ -630,9 +656,9 @@ define( ...@@ -630,9 +656,9 @@ define(
}, },
validate: function (brandCode) { validate: function (brandCode) {
var form = '#payment_form_' + this.getCode() + '_' + brandCode; var form = '#payment_form_' + this.getCode() + '_' + brandCode;
var validate = $(form).validation() && $(form).validation('isValid'); var validate = $(form).validation() && $(form).validation('isValid');
if(!validate) { if (!validate) {
return false; return false;
} }
...@@ -691,11 +717,11 @@ define( ...@@ -691,11 +717,11 @@ define(
* @param arr * @param arr
* @returns {*} * @returns {*}
*/ */
filterUndefinedItemsInArray: function(arr) { filterUndefinedItemsInArray: function (arr) {
return arr.filter(function(item){ return arr.filter(function (item) {
return typeof item !== 'undefined'; return typeof item !== 'undefined';
}); });
} }
}); });
} }
); );
\ No newline at end of file
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