2016-05-08 37 views
0

我想通過條帶中的php變量,但它們顯示錯誤缺少參數數量。在帶狀條件下傳遞php變量charg

這是我的代碼,我從上一頁得到這個數額,並希望在此代碼中傳遞量變量,但我在網上搜索他們說只通過分值。 是否有任何解決方案,通過變量傳遞量我想通過動態價值不是一成不變的,怎麼可能

$amountvalue = '123'; 
    try { 
     if (empty($_POST['street']) || empty($_POST['city']) || empty($_POST['zip'])) 
      throw new Exception("Fill out all required fields."); 
     if (!isset($_POST['stripeToken'])) 
      throw new Exception("The Stripe Token was not generated correctly"); 
     Stripe_Charge::create(array("amount" => $amountvalue, 
            "currency" => "aud", 
            "card" => $_POST['stripeToken'], 
            "description" => $_POST['email'])); 
     $success = '<div class="alert alert-success"> 
        <strong>Success!</strong> Your payment was successful. 
        </div>'; 
     } 
     catch (Exception $e) { 
     $error = '<div class="alert alert-danger"> 
        <strong>Error!</strong> '.$e->getMessage().' 
        </div>'; 
     } 

但似乎條紋不會除了這個變量。它把一個「缺少必要PARAM:量」的錯誤頁面上,只希望接受諸如「1234」

enter image description here

+0

那麼你的問題是什麼? – RiggsFolly

+0

您是否嘗試過'$ amountvalue = 123;' – RiggsFolly

+0

我只是想通過varible在 – flower

回答

0

如果實際整數,根據你的Stripe_Charge ::創建()靜態方法只需要數字數據而不是String;那麼你可以也只是給它的數值數據太多,就像這樣:

<?php 
     // THIS IS EXACTLY THE SAME CODE YOU SUPPLIED ABOVE WITH JUST A SIMPLE CHANGE: 
     // THIS TIME WE ARE USING CENTS RATHER TO MAKE IT EASIER. 
     $amountvalue = '123'; 
     try { 
      if (empty($_POST['street']) || empty($_POST['city']) || empty($_POST['zip'])) 
       throw new Exception("Fill out all required fields."); 
      if (!isset($_POST['stripeToken'])) 
       throw new Exception("The Stripe Token was not generated correctly"); 
      // NOTICE THAT THE ONLY CHANGE HERE IS TO WRAP THE $amountvalue INSIDE OF intval() 
      // THIS CONVERTS THAT $amountvalue TO AN INTEGER, 
      // REGARDLESS OF WHETHER IT IS DYNAMIC OR HARD-CODED AS IT IN THIS CASE. 
      // NOTICE ALSO THAT WE ARE MULTIPLYING THE PASSED AMOUNT BY 100 
      // THAT IS CONVERTING THE $amountvalue TO CENTS... 
      Stripe_Charge::create(array("amount"  => intval($amountvalue)*100, 
             "currency" => "aud", 
             "card"  => $_POST['stripeToken'], 
             "description" => $_POST['email'])); 
      $success = '<div class="alert alert-success"> 
         <strong>Success!</strong> Your payment was successful. 
         </div>'; 
     } 
     catch (Exception $e) { 
      $error = '<div class="alert alert-danger"> 
         <strong>Error!</strong> '.$e->getMessage().' 
         </div>'; 
     } 

條紋要求你傳遞一個信號源參數含有信用卡數據像這樣:

\Stripe\Charge::create(array(
     "amount" => 400, 
     "currency" => "usd", 
     // YOU'RE NOT PASSING THIS source ARRAY PARAMETER... 
     // YOU'RE PASSING JUST card INSTEAD... PROBABLY THE CREDIT-CARD NR. ONLY 
     "source" => array(
     "number" => "4242424242424242", 
     "exp_month" => 5, 
     "exp_year" => 2017, 
     "cvc" => "314" 
    ), 
     "description" => "Charge for [email protected]" 
    )); 

參考:https://stripe.com/us/features

如果你的功能是真的NUMBER HUNG RY,它會與那裏變化不大微笑...... ;-)

乾杯&好運....

+0

再次發現錯誤 – flower

+0

錯誤!無效的正整數 – flower

+0

@flower我編輯的代碼,這次使用Cents而不是...你可能想要嘗試,如果你會... – Poiz

0

的問題似乎並沒有要你通過量,但數據的創建功能。看看這個代碼:

<?php 

     // THIS IS EXACTLY THE SAME CODE YOU SUPPLIED ABOVE WITH JUST A SIMPLE CHANGE: 
     // THIS TIME WE ARE USING CENTS RATHER TO MAKE IT EASIER. 
     $amountvalue = '123'; 
     try { 
      if (empty($_POST['street']) || empty($_POST['city']) || empty($_POST['zip'])) 
       throw new Exception("Fill out all required fields."); 
      if (!isset($_POST['stripeToken'])) 
       throw new Exception("The Stripe Token was not generated correctly"); 

      Stripe_Charge::create(array("amount"  => intval($amountvalue)*100, 
             "currency"  => "aud", 
             //HERE WAS THE ISSUE: 
             'source'  => array(   
              "number" => $_POST['stripeToken'], 
              "exp_month" => $_POST['expiry_month'], // GET THE CORRESPONDING POST VALUE FOR EXPIRY MONTH 
              "exp_year" => $_POST['expiry_year'], // GET THE CORRESPONDING POST VALUE FOR EXPIRY MONTH 
              "cvc"  => $_POST['cvc']   // GET THE CORRESPONDING POST VALUE FOR EXPIRY MONTH 
             ), 
             // REMOVE THIS ENTRY: "card" 
             // "card"   => $_POST['stripeToken'], 
             "description" => $_POST['email'])); 

      $success = '<div class="alert alert-success"> 
         <strong>Success!</strong> Your payment was successful. 
         </div>'; 
     } 
     catch (Exception $e) { 
      $error = '<div class="alert alert-danger"> 
         <strong>Error!</strong> '.$e->getMessage().' 
         </div>'; 
     } 

你只需要一種方式來獲得和傳遞的信用卡信息:信用卡號碼,到期月,到期年和CVC。我相信這會解決你的問題...