Stripe在本地返回成功的测试事务,但不在活动页面上返回
Stripe returns successful test transaction locally but not on live page
我已经设置了页面,使用SSL/MAMP Pro在本地服务器上执行测试事务。当我提交时,我看到"信用卡已成功充值",我看到交易通过Stripe的测试支付数据页面。当上传到服务器(w/有效的SSL证书),我得到"错误:未能调用pay.php处理事务。"奇怪的是,这笔交易在Stripe那边成功完成了。我不明白为什么反应不同。我的PHP错误日志中没有错误,当记录提交的变量时,一切都检查出来了。
buy-controller.js:
function stripeResponseHandler(status, response)
{
if (response.error)
{
// Stripe.js failed to generate a token. The error message will explain why.
// Usually, it's because the customer mistyped their card info.
// You should customize this to present the message in a pretty manner:
alert(response.error.message);
}
else
{
// Stripe.js generated a token successfully. We're ready to charge the card!
var token = response.id;
var fName = $('#first_name').val();
var lName = $('#last_name').val();
var email = $('#email').val();
// alert(fName);
// alert(lName); WORKS
// We need to know what amount to charge. Assume $20.00 for the tutorial.
// You would obviously calculate this on your own:
var price = 70;
// Make the call to the server-script to process the order.
// Pass the token and non-sensitive form information.
var request = $.ajax ({
type: "POST",
url: "../pay.php",
dataType: "json",
data: {
"stripeToken" : token,
"fName" : fName,
"lName" : lName,
"email" : email,
"price" : price
}
});
request.done(function(msg)
{
if (msg.result === 0)
{
// Customize this section to present a success message and display whatever
// should be displayed to the user.
alert("The credit card was charged successfully!");
}
else
{
// The card was NOT charged successfully, but we interfaced with Stripe
// just fine. There's likely an issue with the user's credit card.
// Customize this section to present an error explanation
alert("The user's credit card failed.");
}
});
request.fail(function(jqXHR, textStatus)
{
// We failed to make the AJAX call to pay.php. Something's wrong on our end.
// This should not normally happen, but we need to handle it if it does.
alert("Error: failed to call pay.php to process the transaction.");
});
}
}
$(document).ready(function()
{
$('#purchase_premium').submit(function(event)
{
// immediately disable the submit button to prevent double submits
$('#purchase_submit').attr("disabled", "disabled");
var fName = $('#first_name').val();
var lName = $('#last_name').val();
var email = $('#email').val();
var cardNumber = $('#cc_number').val();
var cardCVC = $('#cc_cvc').val();
// Boom! We passed the basic validation, so we're ready to send the info to
// Stripe to create a token! (We'll add this code soon.)
Stripe.createToken({
number: cardNumber,
cvc: cardCVC,
exp_month: $('#cc_expiration_month').val(),
exp_year: $('#cc_expiration_year').val()
}, stripeResponseHandler);
});
});
Pay.php
<?php
// Credit Card Billing
require_once('includes/Stripe.php'); // change this path to wherever you put the Stripe PHP library!
// For testing purposes
function createLog ($str) {
$file = 'pay_log.txt';
// The new person to add to the file
$str .= "'n";
// Write the contents to the file,
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
file_put_contents($file, $str, FILE_APPEND | LOCK_EX);
}
// Helper Function: used to post an error message back to our caller
function returnErrorWithMessage($message)
{
$a = array('result' => 1, 'errorMessage' => $message);
echo json_encode($a);
}
$trialAPIKey = "---"; // These are the SECRET keys!
$liveAPIKey = "---";
Stripe::setApiKey($trialAPIKey); // Switch to change between live and test environments
// Get all the values from the form
$token = $_POST['stripeToken'];
$email = $_POST['email'];
$firstName = $_POST['fName'];
$lastName = $_POST['lName'];
$price = $_POST['price'];
$priceInCents = $price * 100; // Stripe requires the amount to be expressed in cents
try
{
// We must have all of this information to proceed. If it's missing, balk.
if (!isset($token)) throw new Exception("Website Error: The Stripe token was not generated correctly or passed to the payment handler script. Your credit card was NOT charged. Please report this problem to the webmaster.");
if (!isset($email)) throw new Exception("Website Error: The email address was NULL in the payment handler script. Your credit card was NOT charged. Please report this problem to the webmaster.");
if (!isset($firstName)) throw new Exception("Website Error: FirstName was NULL in the payment handler script. Your credit card was NOT charged. Please report this problem to the webmaster.");
if (!isset($lastName)) throw new Exception("Website Error: LastName was NULL in the payment handler script. Your credit card was NOT charged. Please report this problem to the webmaster.");
if (!isset($priceInCents)) throw new Exception("Website Error: Price was NULL in the payment handler script. Your credit card was NOT charged. Please report this problem to the webmaster.");
try
{
// create the charge on Stripe's servers. THIS WILL CHARGE THE CARD!
$charge = Stripe_Charge::create(array(
"amount" => $priceInCents,
"currency" => "usd",
"card" => $token,
"description" => $email)
);
// If no exception was thrown, the charge was successful!
// Here, you might record the user's info in a database, email a receipt, etc.
// Return a result code of '0' and whatever other information you'd like.
// This is accessible to the jQuery Ajax call return-handler in "buy-controller.js"
$array = array('result' => 0, 'email' => $email, 'price' => $price, 'message' => 'Thank you; your transaction was successful!');
echo json_encode($array);
}
catch (Stripe_Error $e)
{
// The charge failed for some reason. Stripe's message will explain why.
$message = $e->getMessage();
returnErrorWithMessage($message);
}
}
catch (Exception $e)
{
// One or more variables was NULL
$message = $e->getMessage();
returnErrorWithMessage($message);
}
?>
编辑:通过运行console.log(jqXHR.responseText);在请求中。失败块,我得到:
<br />
<b>Warning</b>: stream_socket_client() [<a href='function.stream-socket-client'>function.stream-socket-client</a>]: Unable to set verify locations `/nfs/c06/h04/mnt/188388/domains/website.com/html/includes/Stripe/../data/ca-certificates.crt' `(null)' in <b>/nfs/c06/h04/mnt/188388/domains/website.com/html/includes/Stripe/ApiRequestor.php</b> on line <b>340</b><br />
<br />
<b>Warning</b>: stream_socket_client() [<a href='function.stream-socket-client'>function.stream-socket-client</a>]: failed to create an SSL handle in <b>/nfs/c06/h04/mnt/188388/domains/website.com/html/includes/Stripe/ApiRequestor.php</b> on line <b>340</b><br />
<br />
<b>Warning</b>: stream_socket_client() [<a href='function.stream-socket-client'>function.stream-socket-client</a>]: Failed to enable crypto in <b>/nfs/c06/h04/mnt/188388/domains/website.com/html/includes/Stripe/ApiRequestor.php</b> on line <b>340</b><br />
<br />
<b>Warning</b>: stream_socket_client() [<a href='function.stream-socket-client'>function.stream-socket-client</a>]: unable to connect to ssl://api.stripe.com:443 (Unknown error) in <b>/nfs/c06/h04/mnt/188388/domains/website.com/html/includes/Stripe/ApiRequestor.php</b> on line <b>340</b><br />
<br />
<b>Warning</b>: stream_context_get_params() expects parameter 1 to be resource, boolean given in <b>/nfs/c06/h04/mnt/188388/domains/website.com/html/includes/Stripe/ApiRequestor.php</b> on line <b>350</b><br />
<br />
<b>Warning</b>: openssl_x509_export() [<a href='function.openssl-x509-export'>function.openssl-x509-export</a>]: cannot get cert from parameter 1 in <b>/nfs/c06/h04/mnt/188388/domains/website.com/html/includes/Stripe/ApiRequestor.php</b> on line <b>355</b><br />
{"result":0,"email":"timh@blah.com","price":"70","message":"Thank you; your transaction was successful!"}
看起来最后它试图通过AJAX传递一个成功的事务。我不确定到底该怎么做,但任何帮助都会非常感激。
关闭pay.php上的错误报告会抑制导致JSON响应无效的警告。
您面临这个问题,因为端口80被阻塞。STRIPE不返回令牌,因此它抛出一个TIMEOUT错误,SSL stream_socket_client(): unable to connect to ssl://api.stripe.com:443
相关文章:
- 如何在Facebook上的iframe应用程序中使后退按钮返回到上一页
- 我希望只有在我滚动页面后才能显示我的返回页首图标
- 返回上一页时,Javascript仍处于活动状态
- 如何返回一页并检查调用该操作的页面
- 如何抓取使用直接Web远程处理(DWR)返回操纵页面的Javascript的网站's的HTML
- Javascript 强制浏览器后退按钮返回 2 页
- Java Servlet 总是在 AJAX GET 请求 SERVLET 时返回调用页面的 HTML 代码
- 获取用户尝试返回的页面的 URL
- ASP.NET MVC&Angular:会话到期后,Angular Factory返回登录页面的HTML,而不是
- 带错误的Onsen UI导航:您不能提供no"ons页”;元素到“;ons导航器”;当返回第一页时
- 其他人如何在活动页面的DOM中搜索元素
- 联系表单返回空白页
- 当单击取消按钮时返回同一页面的Javascript代码
- 将JS变量返回到页面源
- 初始化jQuery返回空白页的数据表
- 使用window.location.href返回2页并重新加载
- jQuery Mobile:如何返回一页
- javascript退格默认问题..返回一页
- jQuery 表单在提交时返回空白页
- ng-repeat返回空白页