【发布时间】:2015-01-19 11:01:33
【问题描述】:
我在使用 Stripe Connect 处理付款时遇到了一些问题。出于某种原因,我一提交表单就收到此错误:
发生网络错误,尚未向您收费。请重试
我设置系统的方式是用户可以使用 Stripe 登录,这会从 Stripe 发回以下详细信息,我将这些详细信息与用户 ID 一起保存到数据库中。
- access_token
- 刷新令牌
- 可发布的密钥
在我的付款页面上,我有这个脚本:
Stripe.setPublishableKey('<?= $publishable_key; ?>');
var stripeResponseHandler = function(status, response) {
var $form = $('#payment-form');
$form.find('.form-error').text("")
$form.find('.error').removeClass("error")
validate = validateFields();
if (response.error) {
error = 0;
// Show the errors on the form
if (response.error.message == "This card number looks invalid"){
error = error + 1;
$form.find('.card_num').text(response.error.message);
$('#dcard_num').addClass("error");
}
if (response.error.message == "Your card number is incorrect."){
error = error + 1;
$form.find('.card_num').text(response.error.message);
$('#dcard_num').addClass("error");
}
if (response.error.message == "Your card's expiration year is invalid."){
error = error + 1;
$form.find('.exp').text(response.error.message);
$('#dexp').addClass("error");
}
if (response.error.message == "Your card's expiration month is invalid."){
error = error + 1;
$form.find('.exp').text(response.error.message);
$('#dexp').addClass("error");
}
if (response.error.message == "Your card's security code is invalid."){
error = error + 1;
$form.find('.cvc').text(response.error.message);
$('#dcvc').addClass("error");
}
if (error == 0){
$form.find('.payment-errors').text(response.error.message);
}
$form.find('button').prop('disabled', false);
} else {
if (validate == 1){
// token contains id, last4, and card type
var token = response.id;
// Insert the token into the form so it gets submitted to the server
$form.append($('<input type="hidden" name="stripeToken" />').val(token));
// and re-submit
$form.get(0).submit();
}
}
};
由于某种原因,验证永远不会发生,而且我没有获得卡详细信息的令牌。结果是我的代码的下一部分,我实际上向用户收费的地方没有运行:
global $wpdb;
$author_id = get_the_author_meta('id');
$stripe_connect_account = $wpdb->get_row("SELECT * FROM wp_stripe_connect WHERE wp_user_id = $author_id", ARRAY_A);
if($stripe_connect_account != null){
$publishable_key = $stripe_connect_account['stripe_publishable_key'];
$secret_key = $stripe_connect_account['stripe_access_token'];
}
$charging = chargeWithCustomer($secret_key, $amountToDonate, $currency_stripe, $stripe_usr_id);
这是chargeWithCustomer 函数:
function chargeWithCustomer($secret_key, $amountToDonate, $currency, $customer) {
require_once('plugin/Stripe.php');
Stripe::setApiKey($secret_key);
$charging = Stripe_Charge::create(array("amount" => $amountToDonate,
"currency" => $currency,
"customer" => $customer,
"description" => ""));
return $charging;
}
如果有人能在这个问题上帮助我,我将不胜感激。我很困惑我哪里出错了,我在 Stripes 文档中找不到答案。
【问题讨论】:
标签: javascript php jquery stripe-payments