2016-10-29 179 views
0

これはウェブサイトからまっすぐです。 私はチュートリアルに続きましたが、明らかに何か間違っています。 I   SSLを使用しているサーバー上に持っています。ストライプ '有効なカードを持っていない顧客に請求できません'

これがコードの場合、どこが間違っていましたか。 jquery、v2.js、およびストライプが適切に含まれています。

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <!-- Stripe.js used; fewer compliance requirements! --> 
     <!-- Include Stripe.js, either in your <head> or as a direct descendant of <body> 
     at the end of the page --> 
     <script type="text/javascript" src="v2.js"></script> 
     <script type="text/javascript" src="development-bundle"></script> 
     <script type="text/javascript"> 
     Stripe.setPublishableKey('pk_test_thenthetestkeyidontwanttoshare'); 
     </script> 
     <script> 
     function stripeResponseHandler(status, response) { 
     // Grab the form: 
      var $form = $('#payment-form'); 

      if (response.error) { // Problem! 

      // Show the errors on the form: 
      $form.find('.payment-errors').text(response.error.message); 
      $form.find('.submit').prop('disabled', false); // Re-enable submission 

      } else { // Token was created! 

      // Get the token ID: 
      var token = response.id; 

      // Insert the token ID into the form so it gets submitted to the server: 
      $form.append($('<input type="hidden" name="stripeToken">').val(token)); 

      // Submit the form: 
      $form.get(0).submit(); 
      } 
     }; 
     $(function() { 
      var $form = $('#payment-form'); 
      $form.submit(function(event) { 
      // Disable the submit button to prevent repeated clicks: 
      $form.find('.submit').prop('disabled', true); 

      // Request a token from Stripe: 
      Stripe.card.createToken($form, stripeResponseHandler); 

      // Prevent the form from being submitted: 
      return false; 
      }); 
     }); 
     </script> 
    </head> 
    <body> 
     <form action="charge.php" method="POST" id="payment-form"> 
      <span class="payment-errors"></span> 

      <div class="form-row"> 
      <label> 
       <span>Card Number</span> 
       <input type="text" size="16" data-stripe="number"> 
      </label> 
      </div> 

      <div class="form-row"> 
      <label> 
       <span>Expiration (MM/YY)</span> 
       <input type="text" size="2" data-stripe="exp_month"> 
      </label> 
      <span>/</span> 
      <input type="text" size="4" data-stripe="exp_year"> 
      </div> 

      <div class="form-row"> 
      <label> 
       <span>CVC</span> 
       <input type="text" size="3" data-stripe="cvc"> 
      </label> 
      </div> 

      <div class="form-row"> 
      <label> 
       <span>Billing Zip</span> 
       <input type="text" size="5" data-stripe="address_zip"> 
      </label> 
      </div> 

      <input type="submit" class="submit" value="Submit Payment"> 
     </form> 
    </body> 
</html> 


<?php 
    include('stripe/init.php'); 
    \Stripe\Stripe::setApiKey("sk_test_otherkeyidontwanttoshare"); 

    // Get the credit card details submitted by the form 
    $token = $_POST['stripeToken']; 

    // Create a Customer 
    $customer = \Stripe\Customer::create(array(
     "source" => $token, 
     "description" => "Donation customer") 
    ); 

    // Charge the Customer instead of the card 
    \Stripe\Charge::create(array(
     "amount" => 1000, // Amount in cents 
     "currency" => "usd", 
     "customer" => $customer->id) 
    ); 
?> 

それは私に、このエラーを与える:

Fatal error: Uncaught exception 'Stripe\Error\Card' with message 'Cannot charge a customer that has no active card' in /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php:114 from API request 'req_9SlHeDVEeYFup4'
Stack trace:
#0 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php(266): Stripe\ApiRequestor->handleApiError('{\n "error": {\n...', 402, Array, Array)
#1 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php(65): Stripe\ApiRequestor->_interpretResponse('{\n "error": {\n...', 402, Array)
#2 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiResource.php(120): Stripe\ApiRequestor->request('post', '/v1/charges', Array, Array)
#3 /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiResource.php(160): Stripe\ApiResource::_staticRequest('post', '/v1/charges', Array, NULL)
#4 /home3/blueman/public_html/assistforlife.com/stripe /lib/Charge.php(73): Stripe\ApiResource::_create(Array, NULL) #5 /home3/blueman/public_html/assistforlife.com/charge.ph in /home3/blueman/public_html/assistforlife.com/stripe/lib/ApiRequestor.php on line 114

私は自分のコードを書き、それが私のカードの値が「ヌル」 私は再度書いた、それは誰か他の人のコードを借り、それだと言いました顧客を掲載したが、請求情報は掲載しなかった。

答えて

0

サーバー側のPHPコードでにはnullの値が必要です。そのため、顧客は支払い元なしで作成されます。その後、それを使用して料金を作成しようとすると、「アクティブなカードを持たない顧客に請求できません」という要求が失敗します。

フォームのコードが正しいように見えるので、なぜ$tokenが空であるか分かりません。ブラウザの開発ツールを使用して、Stripe.jsによって作成されたトークンID("tok_...")が実際にstripeToken POSTパラメータとして送信されるようにすることをおすすめします。このラインに従って、無関係なノートで

、:

<script type="text/javascript" src="v2.js"></script> 

それはあなたがローカルStripe.jsをホストしているように見えます。 PCIに準拠するためには、ストライプ自身のサーバー上でホストされているバージョンをhttps://js.stripe.com/v2/で使用する必要があります。

関連する問題