We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday 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
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()
{
return $this->getAdyenHppConfigData("ratepay_id");
......@@ -1156,18 +1119,6 @@ class Data extends AbstractHelper
return false;
}
/**
* @param $paymentMethod
* @return bool
*/
public function isPaymentMethodBoletoMethod($paymentMethod)
{
if (strpos($paymentMethod, 'boleto') !== false) {
return true;
}
return false;
}
/**
* @return bool
*/
......
......@@ -135,41 +135,7 @@ class PaymentMethods extends AbstractHelper
$quote = $this->quoteRepository->getActive($quoteId);
$store = $quote->getStore();
$paymentMethods = $this->addHppMethodsToConfig($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;
}
$paymentMethods = $this->fetchAlternativeMethods($store, $country);
return $paymentMethods;
}
......@@ -215,10 +181,6 @@ class PaymentMethods extends AbstractHelper
if (isset($responseData['paymentMethods'])) {
foreach ($responseData['paymentMethods'] as $paymentMethod) {
if ($paymentMethod['type'] == "scheme") {
continue;
}
$paymentMethodCode = $paymentMethod['type'];
$paymentMethod = $this->fieldMapPaymentMethod($paymentMethod);
......
......@@ -43,6 +43,7 @@ define(
var paymentMethod = ko.observable(null);
var messageComponents;
var shippingAddressCountryCode = quote.shippingAddress().countryId;
var unsupportedPaymentMethods = ['scheme', 'boleto', 'bcmc_mobile_QR', 'wechatpay'];
/**
* Shareble adyen checkout component
* @type {AdyenCheckout}
......@@ -70,7 +71,7 @@ define(
'bankLocationId'
]);
return this;
},initialize: function () {
}, initialize: function () {
var self = this;
this._super();
......@@ -88,8 +89,8 @@ define(
// reset variable:
adyenPaymentService.setPaymentMethods();
adyenPaymentService.retrieveAvailablePaymentMethods(function() {
let paymentMethods = adyenPaymentService.getAvailablePaymentMethods();
adyenPaymentService.retrieveAvailablePaymentMethods(function () {
var paymentMethods = adyenPaymentService.getAvailablePaymentMethods();
if (JSON.stringify(paymentMethods).indexOf("ratepay") > -1) {
var ratePayId = window.checkoutConfig.payment.adyenHpp.ratePayId;
var dfValueRatePay = self.getRatePayDeviceIdentToken();
......@@ -133,7 +134,7 @@ define(
},
getAdyenHppPaymentMethods: function () {
var self = this;
let currentShippingAddressCountryCode = quote.shippingAddress().countryId;
var currentShippingAddressCountryCode = quote.shippingAddress().countryId;
// retrieve new payment methods if country code changed
if (shippingAddressCountryCode != currentShippingAddressCountryCode) {
......@@ -145,14 +146,19 @@ define(
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 = {};
/**
* Returns the payment method's brand code (in checkout api it is the type)
* @returns {*}
*/
result.getBrandCode = function() {
result.getBrandCode = function () {
return self.getBrandCodeFromPaymentMethod(value);
};
......@@ -180,7 +186,7 @@ define(
* @param bool
* @returns {*}
*/
result.isPlaceOrderAllowed = function(bool) {
result.isPlaceOrderAllowed = function (bool) {
self.isPlaceOrderActionAllowed(bool);
return result.placeOrderAllowed(bool);
};
......@@ -191,11 +197,11 @@ define(
* @param bool
* @returns {*}
*/
result.isPlaceOrderAllowed = function(bool) {
result.isPlaceOrderAllowed = function (bool) {
self.isPlaceOrderActionAllowed(bool);
return result.placeOrderAllowed(bool);
};
result.afterPlaceOrder = function() {
result.afterPlaceOrder = function () {
return self.afterPlaceOrder();
};
/**
......@@ -282,7 +288,7 @@ define(
result.findIssuersProperty = function () {
var issuerKey = false;
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') {
issuerKey = key;
}
......@@ -317,7 +323,7 @@ define(
* Returns the issuers for a payment method
* @returns {*}
*/
result.getIssuers = function() {
result.getIssuers = function () {
if (result.hasIssuersAvailable()) {
return value.details[result.findIssuersProperty()].items;
}
......@@ -502,11 +508,31 @@ define(
result.bankLocationId = ko.observable(null);
}
return result;
});
accumulator.push(result);
return accumulator;
}, []);
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 () {
return _.map(window.checkoutConfig.payment.adyenHpp.genderTypes, function (value, key) {
return {
......@@ -575,13 +601,13 @@ define(
return true;
},
placeRedirectOrder: function(data) {
placeRedirectOrder: function (data) {
// Place Order but use our own redirect url after
var self = this;
fullScreenLoader.startLoader();
var messageContainer = this.messageContainer;
if(brandCode()) {
if (brandCode()) {
messageContainer = self.messageComponents['messages-' + brandCode()];
}
......@@ -599,7 +625,7 @@ define(
$("#messages-" + brandCode()).text(response['responseJSON'].message).slideDown();
}
setTimeout(function(){
setTimeout(function () {
$("#messages-" + brandCode()).slideUp();
}, 10000);
self.isPlaceOrderActionAllowed(true);
......@@ -632,7 +658,7 @@ define(
var form = '#payment_form_' + this.getCode() + '_' + brandCode;
var validate = $(form).validation() && $(form).validation('isValid');
if(!validate) {
if (!validate) {
return false;
}
......@@ -691,8 +717,8 @@ define(
* @param arr
* @returns {*}
*/
filterUndefinedItemsInArray: function(arr) {
return arr.filter(function(item){
filterUndefinedItemsInArray: function (arr) {
return arr.filter(function (item) {
return typeof item !== 'undefined';
});
}
......
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