samedi 18 avril 2015

Stripe Custom Field

I have a problem with Stripe. Everything works fine when I write in Cardnumber, CVC etc.


But I need to add a custom field so it can work when I write $_POST['ImeiNum'] in charge.php.


Here's my code for the HTML and JQUERY (index.html)



<script type="text/javascript">
// this identifies your website in the createToken call below
Stripe.setPublishableKey('pk_test_d34534');


function processStripeResponse(status, response){
var form = $('#payment-form<?php echo $row['product_id']; ?>');

if(response.error){
form.find('.errors').text(response.error.message);
form.find('button').prop('disabled', false);
}else{
var token = response.id;
form.append($('<input type="hidden" name="stripeToken" />').val(token));
form.get(0).submit();
}
};

$(function(){
$('#payment-form<?php echo $row['product_id']; ?>').submit(function(event) {
var form = $(this);
form.find('button').prop('disabled', true);

Stripe.card.createToken(form, processStripeResponse);

return false;
});
});
</script>


<form action="charge.php" method="POST" id="payment-form<?php echo $row['product_id']; ?>">


<input type="hidden" name="ImeiNum" value="0987654321">


<div>
<label for="card-number">Card Number</label>
<input type="text" size="20" data-stripe="number" id="card-number" name="card-number">
</div>

<div>
<label for="cvc">Security Code</label>
<input type="text" size="4" data-stripe="cvc" id="cvc" name="cvc">
</div>

<div>
<label>Expiration (MM/YYYY)</label>
<input type="text" data-stripe="exp-month" name="exp-month">
<span> / </span>
<input type="text" data-stripe="exp-year" name="exp-year"/>
</div>

<input type="submit" name="pay" value="Pay">

<div class="errors"></div>

</form>


And here is my code for PHP (charge.php)



<?php
require_once('/storage/content/88/200388/vendor/autoload.php');

\Stripe\Stripe::setApiKey('pk_test_APId34534');

$token = $_POST['stripeToken'];

$IMEI = $_POST['ImeiNum'];

try {
$charge = \Stripe\Charge::create(array(
"amount" => 1000,
"currency" => "usd",
"source" => $token,
"description" => $email),
"metadata" => array("IMEI" => $IMEI)
);

print_r($charge);
}catch(\Stripe\Error\Card $e){
echo $e->getMessage();
}


?>


How do I send a custom field to charge.php?


Aucun commentaire:

Enregistrer un commentaire