2015-06-10 11 views
10

से अधिक स्ट्रिप टोकन का उपयोग नहीं कर सकता है, मैं अपने पट्टी डैशबोर्ड पर त्रुटि कोड 400 प्राप्त करता रहता हूं। ऐसा लगता है कि एक ही पट्टी टोकन का उपयोग एक से अधिक बार किया जाता है और इससे कोई त्रुटि उत्पन्न होती है। नीचे मेरा कोड है।स्ट्रिप त्रुटि 400 - एक बार

जे एस:

<script src="https://checkout.stripe.com/checkout.js"></script> 
    <script> 

    var handler = StripeCheckout.configure({ 
     key: 'pk_test_******************', 
     image: '/img/documentation/checkout/marketplace.png', 
     token: function(token) { 
      /*$.post("php/charge.php",{stripeToken:token.id},function(data,status){ 
       console.log("Data: "+ data+"\nStatus: "+status); 
      });*/ 
      alert(token.used);//alerts false 
      $.post("php/charge.php",{stripeToken:token.id}); 
      alert(token.used);// still alerts false 
     } 
     }); 

     $('#myButton').on('click', function(e) { 
     // Open Checkout with further options 
     handler.open({ 
      name: 'Demo Site', 
      description: '2 widgets', 
      currency: "cad", 
      amount: 2000 
     }); 
     e.preventDefault(); 
     }); 

     // Close Checkout on page navigation 
     $(window).on('popstate', function() { 
     handler.close(); 
     }); 
    </script> 

Php:

<?php 
    require_once('config.php'); 

    $token = $_POST['stripeToken']; 

    $customer = \Stripe\Customer::create(array(
     'email' => '[email protected]', 
     'card' => $token 
)); 

    //try { 
    $charge = \Stripe\Charge::create(array(
     "amount" => 1000, // amount in cents, again 
     "currency" => "cad", 
     "source" => $token, 
     "description" => "Example charge") 
    ); 
    //}catch(\Stripe\Error\Card $e) { 
     // The card has been declined 
    //} 
?> 

किसी को भी मेरी वजह है कि मैं नहीं कर सकते एक ग्राहक चार्ज बता सकते हैं? मैं कई बार एक कुंजी का उपयोग कैसे कर रहा हूँ?

उत्तर

28

आप टोकन का दो बार उपयोग करते हैं।

सबसे पहले, ग्राहक बनाते समय। दूसरा, कार्ड चार्ज करने का प्रयास करते समय।

बजाय, आप एक ग्राहक और बना सकते हैं और उसके बाद धारी को $customer->id पारित जब आप प्रभारी बनाने के लिए:

$charge = \Stripe\Charge::create(array(
    "amount" => 1000, // amount in cents, again 
    "currency" => "cad", 
    "customer" => $customer->id, 
    "description" => "Example charge") 
); 
+0

आपने इसे हल किया ..... धन्यवाद @ तुषार – alaboudi

+4

शायद पट्टी तब से एपीआई बदल दी, लेकिन एन यदि आप ग्राहक आईडी का उपयोग करना चाहते हैं तो आपको "ग्राहक" और "स्रोत" नहीं देना होगा। तो सरणी होगी: सरणी ('amout' => 1000, 'मुद्रा' => 'कैड', 'ग्राहक' => $ ग्राहक-> आईडी, 'विवरण' => 'उदाहरण चार्ज') – WoodyDRN

1

तुम उसे कई बार चार्ज करने के लिए ग्राहक बनाने के लिए है।

1) ग्राहक को क्रेडिट कार्ड टोकन जोड़ें और ग्राहक

2 बनाने) उन

if (isset($_POST['stripeToken'])){ 

     $token = $_POST['stripeToken']; 

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

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

और अधिक मदद की यात्रा के लिए चार्ज करने के लिए ग्राहक आईडी का उपयोग: https://stripe.com/docs/tutorials/charges

संबंधित मुद्दे