Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Authorise recurring payment with Client-Side Encryption fails: Unprocessable Entity #2

Closed
Jarrich opened this issue Jan 26, 2018 · 5 comments

Comments

@Jarrich
Copy link

Jarrich commented Jan 26, 2018

When trying to authorize a recurring payment using Client-Side Encryption; the request fails due to an Unprocessable Entity.

The expected JSON to be sent to Adyen /authorize endpoint in this case would be

{"amount":{"currency":"USD","value":0},"reference":"xxxxx","shopperIp":"xxxxx","merchantAccount":"xxxxx","shopperEmail":"xxxxxxx","shopperReference":"xxxxxxx","recurring":{"contract":"RECURRING"},"additionalData":{"card.encrypted.json": "adyenjs_0_1_19$xxxxxxx"}}

But instead we get:
{"amount":{"currency":"USD","value":0},"reference":"xxxxx","shopperIp":"xxxxx","merchantAccount":"xxxxx","shopperEmail":"xxxxxxx","shopperReference":"xxxxxxx","recurring":{"contract":"RECURRING"},"additionalData":{"Key":"card.encrypted.json","Value":"adyenjs_0_1_19$xxxxxxx"}}

Because the AdditionalData is implemented as a KeyValuePair and the underlying JsonSerializer produces the wrong output in this scenario ("Key": xxx, "Value": xxxx)

Additionally; I believe the AdditionalData property on the PaymentRequest model should accept multiple key/value pairs; since it's normally possible to pass more than 1 "additional data" (see https://docs.adyen.com/developers/risk-management/skip-risk-checks )

@AlexandrosMor
Copy link
Contributor

Hello @Jarrich,

Thank you for adding the issue. I tried to reproduce it and the json parser handles the additional data property properly. Furthermore, In order to test the JsonSerializer I added a create additional data method in BaseTest class which is used by TestAuthoriseSuccessMockedResponse.
The json request for payment now is:

{"card":{"number":"xxxxxxxxxxxxxxxxx","cvc":"123","holderName":"John Smith","expiryMonth":"08","expiryYear":"2018"},
"additionalData":{"liabilityShift":"true","fraudResultType":"GREEN","authCode":"43733"},
"amount":{"currency":"EUR","value":1500},"reference":"payment - 20180126","merchantAccount":"MerchantAccount"}

The same JsonSerializer is used everywhere in the library.
Would you like to provide us more information how we can reproduce it and investigate it further?

Thank you in advance,
Alexandros Moraitis

@Jarrich
Copy link
Author

Jarrich commented Jan 27, 2018

Hi Alexandros,

Is it possible that the published NuGet is out of date? On GitHub i can see that the AdditionalData property is a Dictionary in the PaymentRequest class; whereas when I add the NuGet to my project; the AdditionalData property on PaymentRequest model is a KeyValuePair (which would explain my test results that I describe below)

image

I reproduced the issue in a brand new, empty .NET Core console application; after adding the Adyen.EcommLibrary NuGet

My code:

`var username = "xxxx";
var password = "xxxx";
var adyenEnvironment = Adyen.EcommLibrary.Model.Enum.Environment.Test;
var applicationName = "xxxx";

        var client = new Client(username, password, adyenEnvironment, applicationName);
        client.Config.MerchantAccount = "xxxx";

        var recurring = new Adyen.EcommLibrary.Service.Payment(client);
        Adyen.EcommLibrary.Model.PaymentRequest paymentRequest = new Adyen.EcommLibrary.Model.PaymentRequest
        {
            MerchantAccount = client.Config.MerchantAccount,
            Amount = new Adyen.EcommLibrary.Model.Amount
            {
                Value = Convert.ToInt64(string.Format("{0:0.00}", 0).Replace(".", "")),
                Currency = "USD"
            },
            FraudOffset = 0,
            Reference = "randomreference",
            ShopperEmail = "jarrich@outlook.com",
            ShopperIp = "xx.xx.xx.xx",
            ShopperReference = "xxxx",
            Recurring = new Adyen.EcommLibrary.Model.Reccuring.Recurring
            {
                Contract = Adyen.EcommLibrary.Model.Enum.Contract.Recurring
            }
        };
        paymentRequest.AdditionalData = new KeyValuePair<string, string>("card.encrypted.json", cardData);

        var result = recurring.Authorise(paymentRequest);`

When I inspect the call made to Adyen using Fiddler; I see the following JSON payload:

{"amount":{"currency":"USD","value":0},"reference":"xxxx","shopperIp":"xxxx","merchantAccount":"xxxx","shopperEmail":"jarrich@outlook.com","shopperReference":"xxxxx","recurring":{"contract":"ONECLICK"},"additionalData":{"Key":"card.encrypted.json","Value":"adyenjs_0_1_19$xxxx"}}

Error returned: 422 Unprocessable Entity

When I replace

"Key":"card.encrypted.json","Value":"adyenjs_0_1_19$xxxx"

With the expected

"card.encrypted.json":"adyenjs_0_1_19$xxxx"

The response is 200 OK; resultCode Authorized.

Additionally; I'm wondering why the Contract in the JSON body still mentions ONECLICK when I specifically indicate I want RECURRING in my .NET application.

@AlexandrosMor
Copy link
Contributor

Hello @Jarrich

The issue with the additional data is fixed and published on nuget. You can download the 1.0.2 version.
About the Contract in the JSON body which is mentions ONECLICK would you like to test it with 1.02? If it is not fixed let us know.

kind regards,
Alexandros Moraitis

@Jarrich
Copy link
Author

Jarrich commented Feb 16, 2018

Sorry for being late. The new NuGet seems to work.

@Jarrich Jarrich closed this as completed Feb 16, 2018
@AlexandrosMor
Copy link
Contributor

@Jarrich Thank you for the confirmation.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants