2017-01-12 18 views
1

https://stripe.com/docs/chargesストライプ担当無効な要求

しかし、私は今まで1回の充電からそれを変換しようとしています顧客機能を使用して保存された料金。顧客を確認または作成するためのセクションを追加した後、それぞれの請求の際に無効なリクエスト応答が表示されますが、間違った場所を特定できません。誰もがエラーを見つけることができますか?

// 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; 
} 

答えて

0

はそれを考え出しました。愚かなPHPエラー。

代わり if(!isset($custID)) {....私は特に、空の文字列をチェックするために必要な

ので、私はこれをしなかった:

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

そして、すべてが正常に動作します。