Continuo a ricevere il codice di errore 400 sul mio dashboard stripe. Sembra che io stia usando lo stesso token stripe più di una volta e questo produce un errore. Di seguito è il mio codice.Errore righe 400 - Impossibile utilizzare il token stripe più di una volta
Js:
<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
//}
?>
Qualcuno può dire a mia perché non posso scongiuro un cliente? Come sto usando una chiave più volte?
l'hai risolto ..... Grazie @Tushar – alaboudi
Forse le stripe hanno cambiato l'API da allora, ma n devi fornire "cliente" e non "fonte" se desideri utilizzare l'ID cliente. Quindi la matrice sarebbe: array ('amout' => 1000, 'currency' => 'cad', 'customer' => $ customer-> id, 'description' => 'example charge') – WoodyDRN