admin管理员组文章数量:1414931
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
4 Answers
Reset to default 2Please 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.
本文标签: javascript2checkout Payment API don39t give me Success CallbackStack Overflow
版权声明:本文标题:javascript - 2checkout Payment API don't give me Success Callback - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745155914a2645169.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论