javascript - 2checkout Payment API don't give me Success Callback - Stack Overflow

Hi I am trying to create a Payment which will use the 2checkout APII followed the instructions that 2c

Hi I am trying to create a Payment which will use the 2checkout API I followed the instructions that 2co provided in they documents and everything seems working but I never get the confirmation message that my order is done, I made an account on sandbox and I used the information from there but still no luck.

now see this is the first code that has the form and the 2co.js file included

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Example Form</title>
  <script type="text/javascript" src=".min.js"></script>
  <script src="//ajax.googleapis/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<form id="myCCForm" action="test3.php" method="post">
  <input name="token" type="hidden" value="" />
  <div>
    <label>
      <span>Card Number</span>
      <input id="ccNo" type="text" value="" autoplete="off" required />
    </label>
  </div>
  <div>
    <label>
      <span>Expiration Date (MM/YYYY)</span>
      <input id="expMonth" type="text" size="2" required />
    </label>
    <span> / </span>
    <input id="expYear" type="text" size="4" required />
  </div>
  <div>
    <label>
      <span>CVC</span>
      <input id="cvv" type="text" value="" autoplete="off" required />
    </label>
  </div>
  <input type="submit" value="Submit Payment" />
</form>

<script>
    // Called when token created successfully.
    var successCallback = function(data) {
        var myForm = document.getElementById('myCCForm');

        // Set the token as the value for the token input
        myForm.token.value = data.response.token.token;

        // IMPORTANT: Here we call `submit()` on the form element directly instead of using jQuery to prevent and infinite token request loop.
        myForm.submit();
    };

    // Called when token creation fails.
    var errorCallback = function(data) {
        // Retry the token request if ajax call fails
        if (data.errorCode === 200) {
            // This error code indicates that the ajax call failed. We remend that you retry the token request.
        } else {
            alert(data.errorMsg);
        }
    };

    var tokenRequest = function() {
        // Setup token request arguments
        var args = {
            sellerId: "901249656",
            publishableKey: "0A0C4A4D-FE71-41D0-A960-7C637F347785",
            ccNo: $("#ccNo").val(),
            cvv: $("#cvv").val(),
            expMonth: $("#expMonth").val(),
            expYear: $("#expYear").val()
        };

        // Make the token request
        TCO.requestToken(successCallback, errorCallback, args);
    };

    $(function() {
        // Pull in the public encryption key for our environment
        TCO.loadPubKey('sandbox', function() {
            // Execute when Public Key is available
        });​

        $("#myCCForm").submit(function(e) {
            // Call our token request function
            tokenRequest();

            // Prevent form from submitting
            return false;
        });
    });

</script>
</body>
</html> 

I got my sellerId: "901249656", and my publishableKey: "0A0C4A4D-FE71-41D0-A960-7C637F347785", from my sandbox demo account.

now this is other page "test3.php"

<?php
require_once("2checkout-php-master/lib/Twocheckout.php");
Twocheckout::privateKey('4D67BA12-CE09-4F1D-AB20-0133F24E3472');
Twocheckout::sellerId('901249656');
Twocheckout::sandbox(true);  #Unment to use Sandbox

try {
    $charge = Twocheckout_Charge::auth(array(
        "merchantOrderId" => "123",
        "token" => 'Y2U2OTdlZjMtOGQzMi00MDdkLWJjNGQtMGJhN2IyOTdlN2Ni',
        "currency" => 'USD',
        "total" => '10.00',
        "billingAddr" => array(
            "name" => 'Testing Tester',
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => '[email protected]',
            "phoneNumber" => '555-555-5555'
        ),
        "shippingAddr" => array(
            "name" => 'Testing Tester',
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => '[email protected]',
            "phoneNumber" => '555-555-5555'
        )
    ), 'array');
    if ($charge['response']['responseCode'] == 'APPROVED') {
        echo "Thanks for your Order!";
    }
} catch (Twocheckout_Error $e) {
    $e->getMessage();
}

I downloaded the Twocheckout.php from the provided link they given.

now the problem is it assume that if there is any error on the page it give me 'unauthorized'. So if there is no error and everything is OK it should give me 'authorized'. what happen is that I go to 'test3.php' and stops there with out any error or notes just white page and when try to refresh it gives 'resend'

any help please how this can be done? what is my mistaking? and I assume that when I submit this info I should see that someone has made a new order in my demo page "sandbox account"

Hi I am trying to create a Payment which will use the 2checkout API I followed the instructions that 2co provided in they documents and everything seems working but I never get the confirmation message that my order is done, I made an account on sandbox and I used the information from there but still no luck.

now see this is the first code that has the form and the 2co.js file included

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Example Form</title>
  <script type="text/javascript" src="https://www.2checkout./checkout/api/2co.min.js"></script>
  <script src="//ajax.googleapis./ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
<form id="myCCForm" action="test3.php" method="post">
  <input name="token" type="hidden" value="" />
  <div>
    <label>
      <span>Card Number</span>
      <input id="ccNo" type="text" value="" autoplete="off" required />
    </label>
  </div>
  <div>
    <label>
      <span>Expiration Date (MM/YYYY)</span>
      <input id="expMonth" type="text" size="2" required />
    </label>
    <span> / </span>
    <input id="expYear" type="text" size="4" required />
  </div>
  <div>
    <label>
      <span>CVC</span>
      <input id="cvv" type="text" value="" autoplete="off" required />
    </label>
  </div>
  <input type="submit" value="Submit Payment" />
</form>

<script>
    // Called when token created successfully.
    var successCallback = function(data) {
        var myForm = document.getElementById('myCCForm');

        // Set the token as the value for the token input
        myForm.token.value = data.response.token.token;

        // IMPORTANT: Here we call `submit()` on the form element directly instead of using jQuery to prevent and infinite token request loop.
        myForm.submit();
    };

    // Called when token creation fails.
    var errorCallback = function(data) {
        // Retry the token request if ajax call fails
        if (data.errorCode === 200) {
            // This error code indicates that the ajax call failed. We remend that you retry the token request.
        } else {
            alert(data.errorMsg);
        }
    };

    var tokenRequest = function() {
        // Setup token request arguments
        var args = {
            sellerId: "901249656",
            publishableKey: "0A0C4A4D-FE71-41D0-A960-7C637F347785",
            ccNo: $("#ccNo").val(),
            cvv: $("#cvv").val(),
            expMonth: $("#expMonth").val(),
            expYear: $("#expYear").val()
        };

        // Make the token request
        TCO.requestToken(successCallback, errorCallback, args);
    };

    $(function() {
        // Pull in the public encryption key for our environment
        TCO.loadPubKey('sandbox', function() {
            // Execute when Public Key is available
        });​

        $("#myCCForm").submit(function(e) {
            // Call our token request function
            tokenRequest();

            // Prevent form from submitting
            return false;
        });
    });

</script>
</body>
</html> 

I got my sellerId: "901249656", and my publishableKey: "0A0C4A4D-FE71-41D0-A960-7C637F347785", from my sandbox demo account.

now this is other page "test3.php"

<?php
require_once("2checkout-php-master/lib/Twocheckout.php");
Twocheckout::privateKey('4D67BA12-CE09-4F1D-AB20-0133F24E3472');
Twocheckout::sellerId('901249656');
Twocheckout::sandbox(true);  #Unment to use Sandbox

try {
    $charge = Twocheckout_Charge::auth(array(
        "merchantOrderId" => "123",
        "token" => 'Y2U2OTdlZjMtOGQzMi00MDdkLWJjNGQtMGJhN2IyOTdlN2Ni',
        "currency" => 'USD',
        "total" => '10.00',
        "billingAddr" => array(
            "name" => 'Testing Tester',
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => '[email protected]',
            "phoneNumber" => '555-555-5555'
        ),
        "shippingAddr" => array(
            "name" => 'Testing Tester',
            "addrLine1" => '123 Test St',
            "city" => 'Columbus',
            "state" => 'OH',
            "zipCode" => '43123',
            "country" => 'USA',
            "email" => '[email protected]',
            "phoneNumber" => '555-555-5555'
        )
    ), 'array');
    if ($charge['response']['responseCode'] == 'APPROVED') {
        echo "Thanks for your Order!";
    }
} catch (Twocheckout_Error $e) {
    $e->getMessage();
}

I downloaded the Twocheckout.php from the provided link they given.

now the problem is it assume that if there is any error on the page it give me 'unauthorized'. So if there is no error and everything is OK it should give me 'authorized'. what happen is that I go to 'test3.php' and stops there with out any error or notes just white page and when try to refresh it gives 'resend'

any help please how this can be done? what is my mistaking? and I assume that when I submit this info I should see that someone has made a new order in my demo page "sandbox account"

Share Improve this question edited May 25, 2014 at 6:37 Mikky asked May 21, 2014 at 11:54 MikkyMikky 1012 silver badges12 bronze badges 3
  • Your question has nothing to do with Paypal, so please delete the Paypal tag – Nikita 웃 Commented May 24, 2014 at 9:26
  • @Mikky: did you get solution? – devpro Commented Jan 14, 2015 at 7:50
  • @Mikky I have same problem. Please share your solution if you fixed it – Ghayel Commented May 2, 2016 at 7:16
Add a ment  | 

4 Answers 4

Reset to default 2

Please check whether https://www.2checkout./checkout/api/2co.min.js is loaded pletely or not then only you need to call

TCO.loadPubKey('sandbox', function() {
            // Execute when Public Key is available
});​

Use this code

$.getScript('https://www.2checkout./checkout/api/2co.min.js', function() {
                    try {
                            // Pull in the public encryption key for our environment
                            TCO.loadPubKey('sandbox');
                        } catch(e) {
                            alert(e.toSource());
                        }
                });

In test3.php server side, you need to change the value for 'token' in the try block.

'token' => 'Y2U2OTdlZjMtOGQzMi00MDdkLWJjNGQtMGJhN2IyOTdlN2Ni', //wrong value.

Change it to

'token' => $_POST['token'], //correct value.

Hope that helps.

I've learned (the hard way) that you need a "sandbox" account to run this example code successfully.

screenshot

i faced same problem, at last i got solution... i was putting credential of my live account... whenever i put "sandbox" in code... so if you are using for sandbox then make sure your 2checkout account is sandbox... please check attached screenshot.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745155914a4614118.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信