Mangopay / cardregistration-js-kit

Mangopay V2 JS resources for card registration front-end workflow
MIT License
38 stars 34 forks source link

homologation-webpayment.payline.com/webpayment/getToken 500 service unavailable #40

Closed remipassmoilesel closed 7 years ago

remipassmoilesel commented 7 years ago

Hi ! I try to use cardregistration-js-kit in a small market place. I have a sandbox account which works well. I use Spring to register a client and I can get his id without problem, and after I create a card registration with success.

I follow strictly the example provided in demo/index.php.

But when I try to send card details each time I get a http 500 error:

POST https://homologation-webpayment.payline.com/webpayment/getToken 500 (Internal Server Error)
_ajax @ mangopay-kit.js:566
_tokenizeCard @ mangopay-kit.js:117
registerCard @ mangopay-kit.js:71
(anonymous) @ paiement-securise:230
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
paiement-securise:1 XMLHttpRequest cannot load https://homologation-webpayment.payline.com/webpayment/getToken. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost:8443' is therefore not allowed access. The response had HTTP status code 500.

What am I doing wrong ?

Here is my front code:

<table class="creditCardTable">
    <tr>
        <td>Numéro de carte:</td>
        <td><input id="card_number" value="4970100000000154"/></td>
    </tr>
    <tr>
        <td>Date d'expiration (MMAA):</td>
        <td><input id="card_expiration_date" value="1020"/></td>
    </tr>
    <tr>
        <td>Code cvx:</td>
        <td><input id="card_cvx" value="123"/> (optional for Maestro)</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
    </tr>
    <tr>
        <td colspan="2">
            <button id="process">Process</button>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <div id="result"></div>
        </td>
    </tr>
</table>

<script type="text/javascript">

    $(function () {

        $("#process").click(function () {

            var resultDiv = document.getElementById("result");
            resultDiv.innerHTML = "Processing...";
            resultDiv.style.color = "black";

            // Card register data prepared on the server
            var cardRegisterData = {
                cardRegistrationURL: 'https://homologation-webpayment.payline.com/webpayment/getToken',
                preregistrationData: 'S8HjKhXaPXeNlzbaHMqIvw-NVoXNGhm6HXepEEoF6SfbAHfa4_6uTlwCRw4sUIWSS4wCy-yiraxeE65tmxOe8A',
                accessKey: '1X0m87dmM2LiwFgxPLBJ',
                Id: '30770236'
            };

            // Card data collected from the user
            var cardData = {
                cardNumber: document.getElementById("card_number").value,
                cardExpirationDate: document.getElementById("card_expiration_date").value,
                cardCvx: document.getElementById("card_cvx").value,
                cardType: 'CB_VISA_MASTERCARD'
            };

            // Set MangoPay API base URL and Client ID
            mangoPay.cardRegistration.baseURL = 'https://api.sandbox.mangopay.com';
            mangoPay.cardRegistration.clientId = 'xxxxxxxxxxx'

            // Initialize the CardRegistration Kit
            mangoPay.cardRegistration.init(cardRegisterData);

            // Register card
            mangoPay.cardRegistration.registerCard(cardData,
                function (res) {
                    var message = 'Card has been succesfully registered under the Card Id ' + res.CardId + '.<br />';
                    message += 'Card is now ready to use e.g. in a «Direct PayIn» Object.';
                    resultDiv.innerHTML = message;
                    resultDiv.style.color = "green";
                },
                function (res) {
                    var message = 'Error occured while registering the card.<br />';
                    message += 'Code: ' + res.ResultCode + ', message: ' + res.ResultMessage;
                    resultDiv.innerHTML = message;
                    resultDiv.style.color = "red";
                }
            );
        });

    });

</script>

<script type="text/javascript" src="bower_components/mangopay-cardregistration-js-kit/kit/mangopay-kit.js"></script>

Thanks for your help !

andrzej-rojek commented 7 years ago

This looks like a temporary issue on the Payline side. The Payline URL that is used to tokenize the card details gives a 503 Service Temporarily Unavailable error.

remipassmoilesel commented 7 years ago

Thanks for your response, I hope this is not a frequent error :)

If I can suggest something, maybe it is a good idea to handle this kind of error another way than throwing an error about CORS:

Code: 001596, message: An HTTP request was blocked by the User's computer (probably due to an antivirus)