【发布时间】:2018-12-13 22:53:24
【问题描述】:
我的 wordpress 有问题,我使用的是 stripe,但我收到以下错误消息:“此客户没有附加付款来源”,但我不明白为什么。在开发环境中我没有问题,现在在产品中我有这个问题。有关信息,我使用卡号 4242 4242 4242 4242 进行测试。
非常感谢您的帮助
if(isset($_POST['action']) && $_POST['action'] == 'stripe' && wp_verify_nonce($_POST['stripe_nonce'], 'stripe-nonce')) {
global $stripe_options, $post;
// load the stripe libraries
require_once(STRIPE_BASE_DIR . '/init.php');
// retrieve the token generated by stripe.js
$token = $_POST['stripeToken'];
$amount = base64_decode($_POST['amount'])*100;
$email = $_POST['email'];
$plan_nickname = $_POST['plan_nickname'];
$plan_id = $_POST['plan_id'];
$nom = $_POST['name'];
$prenom = $_POST['prenom'];
$adresse = $_POST['address-line1'];
$ville = $_POST['address-city'];
$zip = $_POST['address-zip'];
// check if we are using test mode
if(isset($stripe_options['test_mode']) && $stripe_options['test_mode']) {
$secret_key = $stripe_options['test_secret_key'];
} else {
$secret_key = $stripe_options['live_secret_key'];
}
// attempt to charge the customer's card
try {
\Stripe\Stripe::setApiKey($secret_key);
$product = \Stripe\Product::create([
'name' => $stripe_options['product_name'],
'type' => 'service',
]);
$plan = \Stripe\Plan::create([
'product' => $stripe_options['product_key'],
'nickname' => $plan_nickname,
'interval' => 'month',
'currency' => 'eur',
'amount' => $amount,
]);
$customer = \Stripe\Customer::create([
'email' => $email,
'source' => $token,
'description' => $plan_nickname,
]);
$subscription = \Stripe\Subscription::create([
'customer' => $customer->id,
'items' => [['plan' => $plan_id]],
]);
// redirect on successful payment
$redirect = add_query_arg('payment', 'paid', $_POST['redirect']);
} catch (Exception $e) {
// redirect on failed payment
//$redirect = add_query_arg('payment', 'failed', $_POST['redirect_failed']);
var_dump($e);
}
// redirect back to our previous page with the added query variable
wp_redirect($redirect); exit;
}
}
【问题讨论】:
-
实际上对于 Stripe,如果客户没有注册卡(付款来源),您无法创建订阅,因此您需要在 Stripe 中添加该客户的 CC 信息。或者可能是您帐户中的条带试用期已结束
-
问题是在我的帖子请求中,StripeToken = null。我没有创建任何令牌!
-
好的,那你知道你需要做什么
-
是的,您应该检查创建令牌的前端代码。请注意,您不能在 Live 模式下使用 4242 测试卡,并且会出现错误,所以我敢打赌这就是正在发生的事情。
标签: php wordpress stripe-payments