Adyen / adyen-cse-web

[DEPRECATED] Client-side encryption on JavaScript
MIT License
15 stars 39 forks source link

Could you help me : {err: "Unknown server Error"} #13

Closed powolnymarcel closed 8 years ago

powolnymarcel commented 8 years ago

I'm working with angularJS and I get an error response, can you try to help me ?

First The form (an object vm.ayden is created then submitted to my client side controller with vm.adyenSub() ) :

            <form ng-submit="vm.adyenSub()" id="adyen-encrypted-form">
                <div class="form-group">
                    <label for="adyen-encrypted-form-number">Card Number</label>
                    <input type="text" ng-model="vm.adyen.number" class="form-control" id="adyen-encrypted-form-number" value="5555444433331111" size="20" autocomplete="off" data-encrypted-name="number">
                </div>
                <div class="form-group">
                    <label for="adyen-encrypted-form-holder-name">Card Holder Name</label>
                    <input type="text" ng-model="vm.adyen.holderName" class="form-control" id="adyen-encrypted-form-holder-name" value="John Doe" size="20" autocomplete="off" data-encrypted-name="holderName">
                </div>
                <div class="form-group">
                    <label for="adyen-encrypted-form-cvc">CVC</label>
                    <input type="text" ng-model="vm.adyen.cvc" class="form-control" id="adyen-encrypted-form-cvc" value="737" size="4" autocomplete="off" data-encrypted-name="cvc">
                </div>
                <div class="form-group col-xs-6">
                    <label for="adyen-encrypted-form-expiry-month">Expiration Month (MM)</label>
                    <input type="text" ng-model="vm.adyen.expiryMonth" class="form-control" value="06" id="adyen-encrypted-form-expiry-month" size="2"  autocomplete="off" data-encrypted-name="expiryMonth">
                </div>
                <div class="form-group col-xs-6">
                    <label for="adyen-encrypted-form-expiry-year">Expiration Year (YYYY)</label>
                    <input type="text" ng-model="vm.adyen.expiryYear" class="form-control" value="2016" id="adyen-encrypted-form-expiry-year"  size="4"  autocomplete="off" data-encrypted-name="expiryYear">
                </div>

                <input type="hidden" ng-model="vm.adyen.crypted" id="adyen-encrypted-form-expiry-generationtime" data-encrypted-name="generationtime" />
                <button type="submit" class="btn btn-default">Create payment</button>
            </form>

Second My controller handle the data and make a POST to NodeJS, (no unencrypted data travelling to the server )

    vm.adyenSub=function(){
        var key     =   "10001|THE KEY PROVIDED BY ADYEN";
        var options = {}; // See adyen.encrypt.nodom.html for details
        var cseInstance = adyen.encrypt.createEncryption(key, options);
        function encryptMyData() {
            var postData = {};
            var cardData = {
                number :            vm.adyen.number,
                cvc :               vm.adyen.cvc,
                holderName :        vm.adyen.holderName,
                expiryMonth :       vm.adyen.expiryMonth,
                expiryYear :        vm.adyen.expiryYear,
                generationtime :    vm.dateAdyen
            };
            postData['adyen-encrypted-data'] = cseInstance.encrypt(cardData);
        return postData
        }

//Here I make the POST to nodeJS with the result of encryptMyData()

        $http.post('/companyAPI/checkout/adyen', encryptMyData(), {headers: {Authorization: 'Bearer ' + authentificationService.getToken()}}).success(function (data) {
            console.log(data);
        }).error(function (data) {
            console.log(data)
        });
    }

THIRD I successfully send to nodeJS this payload

{ action: 'Payment.authorise',
  'paymentRequest.merchantAccount': 'Hic2hMerchant',
  'paymentRequest.amount.currency': 'EUR',
  'paymentRequest.amount.value': '199',
  'paymentRequest.reference': 'TEST-PAYMENT-2016-03-03T13:53:29+01:00',
  'paymentRequest.shopperIP': '11.111.111.111',
  'paymentRequest.shopperEmail': 'test@hic2h.com',
  'paymentRequest.shopperReference': 'test-hic2h',
  'paymentRequest.fraudOffset': '0',
  'paymentRequest.additionalData.card.encrypted.json': 'adyenjs_0_1_16$hUD6rjw3MMVpWmYs+5OQhrBIFnzaF49HKNTUxap0Q/Ita2JbfZi6tTUydP94KDhlT6hFT0Wo5DMZXbrf/eI/H79/E3ARY+vB90pSmWjjrhEDdweFWr7FS+5veBTX/XEE8FyMOBT+g7jsgCn8p+1ZUthbWsgSgH1iOWKqFs5agvkzM1HYlg9T2jV77BWB8PvMD+kLFS3iFay9UBRogaUdFFbvqJqDpbHsJRzqfyL4VGlcbNQGuoXyyPJO+wq3crRBtfnHREMzK9DhMhu7akQcPOPR41nPOAljKd9GkBafEplfH63aYPXJ31A6cOYXYBk0eyczEa/MOYBjXdUozQwJaoGA==$hR9nGIoQbm8eSQNgzPZTU15rbYgvYlkxnjVygu6WJyF7wgwvegGIqdy3/hnP03gYTOp8+NK3MfSI6fHSDDuUDGsF3HMByNXoYwpNyXcp/0yIvF/9iqGnsWZ2JfujHkvsf+NAbsxNDZyTqYVknPLomD0Lg+WkIEKkaiBYb6fzBEy8MZbCVGT4SixltwR/aZgTlBJIThIHal3HuoIiik7gBakZG5PqdVYjucuGzXht8wrz/7hEKmP4jrMR/jPahzxn0R5P0ZBvS+wD5082s5GED23TQ5cttUxW4NxnKSZB5d6EYJgbcSLBKHGPv6gFsfwvvanfFNBzTUXeY1qLXyGiJhQ8WRMReQgAYTjjlQe29cdY6P6gFt0hzfTRfDkAWXY22J5/YNQCSw==' }

then I do :

adyen.test("ws_209413@Company.COMPANYX", "myPassword", adyenRequestBody, function(err, response){
        res.json({err: err, response: response});
    });

And i receive this response : {err: "Unknown server Error"}

powolnymarcel commented 8 years ago

Is it because i kept the default value in :

"paymentRequest.merchantAccount" : "Hic2hMerchant",
'paymentRequest.shopperEmail': 'test@hic2h.com',
'paymentRequest.shopperReference': 'test-hic2h',

?

ArnoudAdyen commented 8 years ago

For this type of error's it is faster to contact Adyen support. They can probably help you figure out what is wrong here, as from my perspective it seems the coding is sound.

powolnymarcel commented 8 years ago

I found my error i needed to change the value here : "paymentRequest.merchantAccount" : "Hic2hMerchant",

TO "paymentRequest.merchantAccount" : "MY_ACCCOUNT",

but now i get :

Object {err: null, response: Object}
err: null
response: Object
paymentResult.pspReference: "8614570137167924"
paymentResult.refusalReason: "010+Not+allowed"
paymentResult.resultCode: "Refused"

Is the "Hosted Client Side Encryption" from adyen https://test.adyen.com/hpp/cse/js/76214570238431463.shtml

and the one you provide here not the same ? Will that cause my error ?

I know I'm close of getting it work but there is still a small error I guess and I need help :)

ArnoudAdyen commented 8 years ago

What is the actual JSON structure you are sending to the server? It should be similar to the one's that will show up if you go to the https://www.adyen.com/apidocs/?example=CSE%20Authorisation

powolnymarcel commented 8 years ago

This is what I send from client to NodeJS:

OObject {adyen-encrypted-data: "adyenjs_0_1_15$Kuvv07s1E7LeHJedplcSb0yPqSvHXrEnrwZ…gS3YwqEpS3meOv/UwtzPcTVWLYg0qk+M8A1Gz7Z9r24F8eg=="}
adyen-encrypted-data: "adyenjs_0_1_15$Kuvv07s1E7EDFedplcSb0yPqSvHXrEnrwZQlNU3sREPdW+o/5IEUsYd9MQalie3oDQ+mlhIT/khOSPzBRwN7/8TQyVXEzL2JDgTgQizWyk8842aaYkRwq0n5Kxb1ri+DB2Oaz2rxccM6K41PpMXglPEohzQ5yRQiYwnUwUu3C89HaD0MwoEclQMoULi6yJsoOjYGjLxaIhu/MbXXe/WEtUmO5U7HlJ5nK83zH8JKHUU23pUJyS0Rnci4GHlgWZEKnonzMJHys36/5FZf++4sCjryKxPt2snnl5hnU8mgcnF1DA66AGe54+AhvUvoYBojUfrEktY4LoJIWIzlf6cVg==$bI8Xvb4QKA+9Fmsjk/xZG9SJ6G7tIfuoqs5vYI2HKyuzRndH6dRBl5yWUC7e4OiN6xk/Nu9C7ug9q+6yEfK37NuqE0aAWonNsbfVzuenbzP/GVw7HvZjJS2TPI3kYvfVee7fx2S/VzEba2o+NfvO+B0UbZA1rQfZj+zupKMgHhKIZm4kHNtkQcXWXIVUY1m19if2vXb/rgb+JFjRv9SS0I79yb2nkji5W9LmViNclhnozfliSz7DsUNDp1BYwfP4WmJ3o5UFBknPZhqRuCNgS3YwqEpS3meOv/UwtzPcTVWLYg0qk+M8A1Gz7Z9r24F8eg=="
__proto__: Object

This is what I send from NodeJS to the adyen server

{ action: 'Payment.authorise',
  'paymentRequest.merchantAccount': 'MyCompanyBE',
  'paymentRequest.amount.currency': 'EUR',
  'paymentRequest.amount.value': '199',
  'paymentRequest.reference': 'TEST-PAYMENT-2016-03-03T15:06:16+01:00',
  'paymentRequest.shopperIP': '11.111.111.111',
  'paymentRequest.shopperEmail': 'test@hic2h.com',
  'paymentRequest.shopperReference': 'test-hic2h',
  'paymentRequest.fraudOffset': '0',
  'paymentRequest.additionalData.card.encrypted.json': 'adyenjs_0_1_15$Kuvv07s1E7LeHJedplcSb0yPqSvHXrEnrwZQlNU3sREPdW+o/5IEUsYd9MQalie3oDQ+mlhIT/khOSPzBRwN7/8TQyVXEzL2JDgTgQizWyk8842aaYkRwq0n5Kxb1ri+DB2Oaz2rxccM6K41PpMXglPEohzQ5yRQiYwnUwUu3C89HaD0MwoEclQMoULi6yJsoOjYGjLxaIhu/MbXXe/WEtUmO5U7HlJ5nK83zH8JKHUU23pUJyS0Rnci4GHlgWZEKnonzMJHys36/5FZf++4sCjryKxPt2snnl5hnU8mgcnF1DA66AGe54+AhvUvoYBojUfrEktY4LoJIWIzlf6cVg==$bI8Xvb4QKA+9Fmsjk/xZG9SJ6G7tIfuoqs5vYI2dfdendH6dRBl5yWUC7e4OiN6xk/Nu9C7ug9q+6yEfK37NuqE0aAWonNsbfVzuenbzP/GVw7HvZjJS2TPI3kYvfVee7fx2S/VzEba2o+NfvO+B0UbZA1rQfZj+zupKMgHhKIZm4kHNtkQcXWXIVUY1m19if2vXb/rgb+JFjRv9SS0I79yb2nkji5W9LmViNclhnozfliSz7DsUNDp1BYwfP4WmJ3o5UFBknPZhqRuCNgS3YwqEpS3meOv/UwtzPcTVWLYg0qk+M8A1Gz7Z9r24F8eg==' }

What am I doing wrong ?

I keep receiving :

paymentResult.pspReference: "7914530236558147"
paymentResult.refusalReason: "010+Not+allowed"
paymentResult.resultCode: "Refused"
powolnymarcel commented 8 years ago

OK found the error, the last step in nodeJS is

adyen.test("ws@Company.XXXXX", "PASSWORD", adyenRequestBody, function(err, response){
        res.json({err: err, response: response});
    });

I don't know why but on the adyen website under User List i have 2 system's user and I was using the wrong one....

Now if I test a VISA or a Mastercard i get

paymentResult.resultCode: "Refused"

It's good, maybe my error will serve someone one day...