如何防止条带支付网关上的decliened卡的令牌生成?

时间:2018-01-08 08:29:24

标签: php stripe-payments

我正在使用条带支付网关。

流程 -

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);
                }
            }

1 个答案:

答案 0 :(得分:0)

是的,你肯定可以在创建令牌的同时通过在创建令牌时传递0.1 $的金额来验证CVC。

条带文档

中没有记录此功能

请参阅这些博客文章和条带邮件列表以获取更多详细信息

link 1

link 2

您的更新代码应如下所示,并使用Stripe.js创建令牌

Stripe.card.createToken({
  number: '4242424242424242',
  exp_month: '12',
  exp_year: '2022',
  cvc: '987'
}, 100, stripeResponseHandler);