Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 条带费用无效请求_Php_Wordpress_Try Catch_Stripe Payments - Fatal编程技术网

Php 条带费用无效请求

Php 条带费用无效请求,php,wordpress,try-catch,stripe-payments,Php,Wordpress,Try Catch,Stripe Payments,我成功地使用Stripe的说明在我正在构建的Wordpress插件中创建并实现了充电: 但是,我现在正尝试使用客户功能将单次充电转换为节省的充电。在添加用于检查或创建客户的部分后,我现在在每次尝试收费时都会收到无效的请求响应,但我无法找出哪里出了问题。有人能发现错误吗 // Get the payment token submitted by the form: $token = $_POST['stripeToken']; // Token is created using Stripe.js

我成功地使用Stripe的说明在我正在构建的Wordpress插件中创建并实现了充电:

但是,我现在正尝试使用客户功能将单次充电转换为节省的充电。在添加用于检查或创建客户的部分后,我现在在每次尝试收费时都会收到无效的请求响应,但我无法找出哪里出了问题。有人能发现错误吗

// Get the payment token submitted by the form:
$token = $_POST['stripeToken']; // Token is created using Stripe.js, not hard-coded
$cartID = (int)$_POST['cartID'];
$cartTotal = (int)$_POST['cart-total'];

//Get the current user's info
$user = get_userdata(get_current_user_id());
$userid = $user->ID;

//See if this user already has a stripe customer ID set in their meta
$custID = get_user_meta($userid, 'stripeCustID', true);
if (!isset($custID)) {
    // Create a new Customer
    $customer = \Stripe\Customer::create(array(
      "email" => $user->user_email,
      "source" => $token,
        )
    );
    $custID = $customer->id;

    //Add the customer ID to the user meta
    add_user_meta($userid, 'stripeCustID', $custID, true);
}

// Try to charge the card
try {
    $charge = \Stripe\Charge::create(array(
      "amount" => $cartTotal,
      "currency" => "usd",
      "description" => "TPS Space Rental",
      //"source" => $token, //we're charging the customer instead of the token
      'customer' => $custID,
    ));
    if ($charge) {
        //Add the charge object as post meta
        add_post_meta($cartID, 'checkoutCharge', $charge, true); //only one checkCharge per cart please
        //Update the cart to published
        wp_update_post(array('ID'=>$cartID, 'post_status'=>'publish'));
        //Redirect to the confirmation page
        wp_redirect(get_bloginfo('url').'/rental-confirmation?confirmCart='.$cartID);
        exit;
    }

} catch (\Stripe\Error\ApiConnection $e) {
     // Network problem, perhaps try again.
    wp_redirect(get_bloginfo('url').'/space-checkout?error=networkProblems');
    exit;
} catch (\Stripe\Error\InvalidRequest $e) {
     // You screwed up in your programming.
     wp_redirect(get_bloginfo('url').'/space-checkout?error=invalidRequest');
    exit;
} catch (\Stripe\Error\Api $e) {
     // Stripe's servers are down!
     wp_redirect(get_bloginfo('url').'/space-checkout?error=stripeServers');
    exit;
} catch (\Stripe\Error\Card $e) {
    // Card was declined.
     $e_json = $e->getJsonBody();
     $error = $e_json['error'];
     // Use $error['message'] to display the specific error
     $_SESSION['declinedError'] = $error['message'];
     wp_redirect(get_bloginfo('url').'/space-checkout?error=declined');
     exit;
}

我明白了。愚蠢的PHP错误

而不是
if(!isset($custID)){..

我需要专门检查一个空字符串,所以我这样做:

if (empty($custID) || $custID == '') {

一切正常。

解决了。愚蠢的PHP错误

而不是
if(!isset($custID)){..

我需要专门检查一个空字符串,所以我这样做:

if (empty($custID) || $custID == '') {
一切都很好