I am working with stripe payment gateway.
Flow -
1 . Generating token
2 . Creating payment
Generating Token - as per below code all is good and token it generating.
Now i would like to block or check the card is valid for payment while generating token.
For example - cvc is valid and generate token for that so it will get payment for sure.
if ($this->request->is('post') && $this->request->getData('gtoken') == 'gtoken') {
$planId = $this->request->getData('planid');
$amount = $this->request->getData('finalamount');
$cc = $this->request->getData('cc');
$cardHolder = $this->request->getData('cardHolder');
$expiryMonth = $this->request->getData('expiryMonth');
$expiryYear = $this->request->getData('expiryYear');
$cvc = $this->request->getData('cvc');
// validate data and generate token
if($cc) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.stripe.com/v1/tokens");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "card[number]=".$cc."&card[exp_month]=".$expiryMonth."&card[exp_year]=".$expiryYear."&card[cvc]=".$cvc);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, STRIPE_SECRET_KEY. ":" . "");
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$tokendata = json_decode(curl_exec($ch), true);
if(@$tokendata["error"]) {
if(@$tokendata['error']['param'] =='invalid_number'){
$this->Flash->error("Please Enter a Valid Card Number.");
} elseif(@$tokendata['error']['param']=='exp_month'){
$this->Flash->error("Please Enter a Valid Month.");
}
else {
$this->Flash->error($tokendata['error']['message'] );
}
}
else{
$token = $tokendata['id'];
$this->request->session()->write('payment',$this->request->getData());
$this->request->session()->write('paymenttoken',$token);
// flush save coupon onsession
$this->request->session()->write('isapplycoupon', false);
$this->savePayment();
return $this->redirect(['controller'=>'venues', 'action'=>'add']);
}
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
}
}
</div>