Skip to content

Commit

Permalink
Merge pull request #505 from Adyen/fix/paymentMethodsResponse-null-va…
Browse files Browse the repository at this point in the history
…lues

Fix null value issues on PaymentMethodsResponse
  • Loading branch information
marcperez committed Nov 12, 2020
2 parents 94f5633 + 1196938 commit d876b38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class PaymentMethodsResponse {
constructor(response, options = {}) {
checkPaymentMethodsResponse(response);

this.paymentMethods = response ? processPaymentMethods(response, options) : [];
this.storedPaymentMethods = response ? processStoredPaymentMethods(response, options) : [];
this.paymentMethods = response ? processPaymentMethods(response.paymentMethods, options) : [];
this.storedPaymentMethods = response ? processStoredPaymentMethods(response.storedPaymentMethods, options) : [];
}

has(paymentMethod: string): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PaymentMethod, PaymentMethodsResponseInterface } from '../../../types';
import { PaymentMethod, StoredPaymentMethod } from '../../../types';
import {
filterAllowedPaymentMethods,
filterEcomStoredPaymentMethods,
Expand All @@ -11,20 +11,17 @@ const processStoredPaymentMethod = (pm): PaymentMethod => ({
storedPaymentMethodId: pm.id
});

export const processPaymentMethods = (
paymentMethodsResponse: PaymentMethodsResponseInterface,
{ allowPaymentMethods = [], removePaymentMethods = [] }
): PaymentMethod[] => {
const { paymentMethods = [] } = paymentMethodsResponse;
export const processPaymentMethods = (paymentMethods: PaymentMethod[], { allowPaymentMethods = [], removePaymentMethods = [] }): PaymentMethod[] => {
if (!paymentMethods) return [];

return paymentMethods.filter(filterAllowedPaymentMethods, allowPaymentMethods).filter(filterRemovedPaymentMethods, removePaymentMethods);
};

export const processStoredPaymentMethods = (
paymentMethodsResponse: any = {},
storedPaymentMethods: StoredPaymentMethod[],
{ allowPaymentMethods = [], removePaymentMethods = [] }
): PaymentMethod[] => {
const { storedPaymentMethods = [] } = paymentMethodsResponse;
if (!storedPaymentMethods) return [];

return storedPaymentMethods
.filter(filterSupportedStoredPaymentMethods) // only display supported stored payment methods
Expand Down

0 comments on commit d876b38

Please sign in to comment.