2

I am trying to charge the credit card using checkout.com. I am using Charge with card token. I have generated the card token using checkoutkit.js. And passing that token to my controller, where i am making payment call. But I am not getting response return. Even in debug mode it is not moving to next line. My view and controller code:

        <script>
        window.CKOConfig = {
            debugMode: true,
            publicKey: 'pk_test_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac',
            customerEmail: 'random@email.com',
            ready: function (event) {
                console.log("CheckoutKit.js is ready");
                CheckoutKit.monitorForm('.card-form', CheckoutKit.CardFormModes.CARD_TOKENISATION);
            },
            apiError: function (event) {
                alert('api error');
            },
            cardTokenised: function(e) {
                $.ajax({
                    type: 'POST',
                    url: '@Url.Action("Charge")',
                    data: { cardToken: e.data.id },
                    success: function (data) {
                        alert(data);
                        location.reload();
                    },
                    error: function() {
                        alert('error');
                    }
                });
            }
        };
    </script>

    <script async src="https://sandbox.checkout.com/js/v1/checkoutkit.js"></script>

    <div class="jumbotron">
        <form class="card-form" method="POST">
            <input data-checkout="email-address" type="email" placeholder="Email address">
            <input data-checkout="card-number" type="text" placeholder="Credit card number">
            <input data-checkout="card-name" type="text" placeholder="Name on card">
            <input data-checkout="expiry-month" type="text" placeholder="MM">
            <input data-checkout="expiry-year" type="text" placeholder="YY">
            <input data-checkout="cvv" type="text" placeholder="CVV">
            <input type="submit" value="Pay Now">
        </form>
    </div>

[HttpPost]
            public ActionResult Charge(string cardToken)
            {
                APIClient CheckoutClient = new APIClient("sk_test_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", Environment.Sandbox);

                CardTokenCharge cardTokenChargeModel = TestHelper.GetCardTokenChargeCreateModel(cardToken, TestHelper.RandomData.Email);

                HttpResponse<Charge> response = CheckoutClient.ChargeService.ChargeWithCardToken(cardTokenChargeModel);

                return Json(cardToken);
            }
Marc
  • 137
  • 3
  • 12
Atif
  • 51
  • 6

1 Answers1

2

I have checked the process and it seems working fine however there are couple of things I would like to confirm with you.

Can you make sure you are following the steps below please:

1- Your script relies on JQuery therefore you need to make sure you have the following line in your html page so your Ajax request can work:

2- When you populate the required card information and click on Pay Now button, the CheckoutKit.js will first connect to sandbox to generate a card token for you e.g. card_tok_C739732A...

Can you check if you receive a successful response in your browser console.

3- Once you got the card token, your script will post an Ajax call to charge endpoint which you defined as your action method.

Can you check if your cardToken parameter in your action is populated with a value.

4- Can you debug your code to check if you receive any response for the following call as it will return you a response (there is 60 second time out):

HttpResponse response = CheckoutClient.ChargeService.ChargeWithCardToken(cardTokenChargeModel);

Lets see what responses you will have so we can investigate more on it. I will be happy to provide help on this issue for you.

thanks

MMeydan
  • 21
  • 1
  • I am receiving the card token in my .net code. But when i use that token to charge the user the application won't return anything, no exception even. – Atif Nov 10 '15 at 05:09
  • Hi Atif, are you behind a proxy? It seems your request not reaching us. Can you check if you can submit a http post request from a simple console app to our sanbox environment. – MMeydan Nov 12 '15 at 08:05
  • No its not proxy to me it is bug in dot net api – Atif Nov 17 '15 at 09:45
  • Hi Atif, It seems you got an interesting issue here and I would like to help you. Can I suggest you to send an email to support@checkout.com giving us what version of client library you use (4.0 or 4.5), Api key that you use and the request payload populated in you sample request. You can also send as a zip of you sample application and we take it from there. Please include your skype username as well so we can have a chat directly to conclude this issue a little faster for you. – MMeydan Nov 18 '15 at 12:32
  • I have already sent many emails. only response i go is we are looking at your issue. :( – Atif Nov 19 '15 at 04:28
  • @Atif, Did you manage to solve the problem, can you post your solution so that other can use it – Learning Mar 07 '17 at 07:03