我正在使用条带支付网关。
流程 -
1。生成令牌
2。创建付款
生成令牌 - 根据以下代码,所有内容都很好并且它会生成令牌。
现在我想在生成令牌时阻止或检查该卡是否有效。
例如 - cvc有效并为此生成令牌,因此它肯定会得到付款。
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);
}
}