Adyen / adyen-java-api-library

Adyen API Library for Java
MIT License
116 stars 133 forks source link

PaymentMethodsResponse.toString() modifies response? #305

Closed tddouglas closed 4 years ago

tddouglas commented 4 years ago

Java version: 1.8 Library version: 4.0.1 Description Why does the toString() function in PaymentMethodsResponse.java modify the response from Adyen by appending stuff like "class PaymentMethodsResponse." Surely the main usecase for this function would be people using dropin or a component interested in passing this result into the component. Seems silly I have to write my own toString() function in order to do this as opposed to the default toString function stringifying the /paymentMethods result.

For example, this is the response of toString() currently:

class PaymentMethodsResponse {
    oneClickPaymentMethods: null
    paymentMethods: [class PaymentMethod {
        brands: null
        configuration: null
        details: [class InputDetail {
            configuration: null
            details: null
            itemSearchUrl: null
            items: [class Item {
                id: 1121
                name: Test Issuer
            }, class Item {
                id: 1154
                name: Test Issuer 5
            }...]
        group: null
        name: iDEAL
        paymentMethodData: null
        supportsRecurring: true
        type: ideal
    }, class PaymentMethod {
        brands: [mc, visa, amex, cartebancaire, maestro, diners, discover, jcb]
        configuration: null
        details: [class InputDetail {
            configuration: null
            details: null
            itemSearchUrl: null
            items: null
            key: number
            optional: null
            type: text
            value: null
        }, class InputDetail {
            configuration: null
            details: null
            itemSearchUrl: null
            items: null
            key: expiryMonth
            optional: null
            type: text
            value: null
        }, class InputDetail {
            configuration: null
            details: null
            itemSearchUrl: null
            items: null
            key: expiryYear
            optional: null
            type: text
            value: null
        }...]
        group: null
        name: Credit Card
        paymentMethodData: null
        supportsRecurring: null
        type: scheme
    }, class PaymentMethod {
        brands: null
        configuration: null
        details: null
        group: null
        name: PayPal
        paymentMethodData: null
        supportsRecurring: true
        type: paypal
    }, class PaymentMethod {
        brands: null
        configuration: null
        details: [class InputDetail {
            configuration: null
            details: [class SubInputDetail {
                items: null
                key: firstName
                optional: null
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: lastName
                optional: null
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: [class Item {
                    id: M
                    name: male
                }, class Item {
                    id: F
                    name: female
                }]
                key: gender
                optional: null
                type: radio
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: dateOfBirth
                optional: null
                type: date
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: telephoneNumber
                optional: null
                type: tel
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: shopperEmail
                optional: null
                type: emailAddress
                value: null
                configuration: null
            }]
            itemSearchUrl: null
            items: null
            key: personalDetails
            optional: null
            type: fieldSet
            value: null
        }, class InputDetail {
            configuration: null
            details: [class SubInputDetail {
                items: null
                key: street
                optional: null
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: houseNumberOrName
                optional: null
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: city
                optional: null
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: postalCode
                optional: null
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: stateOrProvince
                optional: true
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: [class Item {
                    id: NL
                    name: Netherlands
                }, class Item {
                    id: BE
                    name: Belgium
                }]
                key: country
                optional: null
                type: select
                value: null
                configuration: null
            }]
            itemSearchUrl: null
            items: null
            key: billingAddress
            optional: null
            type: address
            value: null
        }, class InputDetail {
            configuration: null
            details: null
            itemSearchUrl: null
            items: null
            key: separateDeliveryAddress
            optional: true
            type: boolean
            value: false
        }, class InputDetail {
            configuration: null
            details: [class SubInputDetail {
                items: null
                key: street
                optional: null
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: houseNumberOrName
                optional: null
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: city
                optional: null
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: postalCode
                optional: null
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: null
                key: stateOrProvince
                optional: true
                type: text
                value: null
                configuration: null
            }, class SubInputDetail {
                items: [class Item {
                    id: NL
                    name: Netherlands
                }, class Item {
                    id: BE
                    name: Belgium
                }]
                key: country
                optional: null
                type: select
                value: null
                configuration: null
            }]
            itemSearchUrl: null
            items: null
            key: deliveryAddress
            optional: true
            type: address
            value: null
        }, class InputDetail {
            configuration: null
            details: null
            itemSearchUrl: null
            items: null
            key: consentCheckbox
            optional: null
            type: boolean
            value: null
        }]
        group: null
        name: AfterPay Invoice
        paymentMethodData: null
        supportsRecurring: true
        type: afterpay_default
    }, class PaymentMethod {
        brands: null
        configuration: null
        details: null
        group: null
        name: Pay later with Klarna.
        paymentMethodData: null
        supportsRecurring: true
        type: klarna
    }, class PaymentMethod {
        brands: null
        configuration: null
        details: [class InputDetail {
            configuration: null
            details: null
            itemSearchUrl: null
            items: null
            key: ownerName
            optional: null
            type: text
            value: null
        }, class InputDetail {
            configuration: null
            details: null
            itemSearchUrl: null
            items: null
            key: iban
            optional: null
            type: text
            value: null
        }]
        group: null
        name: SEPA Direct Debit
        paymentMethodData: null
        supportsRecurring: true
        type: sepadirectdebit
    }, class PaymentMethod {
        brands: null
        configuration: null
        details: [class InputDetail {
            configuration: null
            details: null
            itemSearchUrl: null
            items: null
            key: applepay.token
            optional: null
            type: applePayToken
            value: null
        }]
        group: null
        name: Apple Pay
        paymentMethodData: null
        supportsRecurring: true
        type: applepay
    }, class PaymentMethod {
        brands: null
        configuration: null
        details: null
        group: null
        name: SEPA Bank Transfer
        paymentMethodData: null
        supportsRecurring: true
        type: bankTransfer_IBAN
    }, class PaymentMethod {
        brands: null
        configuration: null
        details: null
        group: null
        name: Pay now with Klarna.
        paymentMethodData: null
        supportsRecurring: true
        type: klarna_paynow
    }, class PaymentMethod {
        brands: null
        configuration: null
        details: [class InputDetail {
            configuration: null
            details: null
            itemSearchUrl: null
            items: null
            key: paywithgoogle.token
            optional: null
            type: payWithGoogleToken
            value: null
        }]
        group: null
        name: Google Pay
        paymentMethodData: null
        supportsRecurring: true
        type: paywithgoogle
    }]
    storedPaymentMethods: null
    groups: [class PaymentMethodsGroup {
        groupType: null
        name: Credit Card
        types: [mc, visa, amex, cartebancaire, maestro, diners, discover, jcb]
    }]
}
tddouglas commented 4 years ago

Nevermind, just need to use Gson to serialize e.g.:

PaymentMethodsResponse response = checkout.paymentMethods(paymentMethodsRequest);
String serializedResponse = new Gson().toJson(response);