我使用stripe.js在codeigniter中使用Stripe支付网关。在条带支付过程中首先进行客户端验证,然后通过条带php 2.1.1库进行服务器端验证。客户端验证工作准备就绪,但服务器端验证会出错。我把条带php 2.1.1文件夹放在codeigniter库文件夹中。
我引用此链接http://code.tutsplus.com/tutorials/how-to-accept-payments-with-stripe--pre-80957
代码:
<?php
$success = "";
$error = "";
require_once(APPPATH.'libraries/stripe/lib/Stripe.php');
if ($_POST) {
Stripe::setApiKey("dm_wsdst_yJQB5mrfjpfQX2uMQHf3CbD");
$error = '';
$success = '';
try {
if (!isset($_POST['stripeToken']))
throw new Exception("The Stripe Token was not generated correctly");
Stripe_Charge::create(array("amount" => 11,
"currency" => "usd",
"card" => $_POST['stripeToken']));
$success = 'Your payment was successful.';
}
catch (Exception $e) {
$error = $e->getMessage();
}
}
echo "sucess". isset($success) ? $success : "";
echo "error".isset($error) && $success ? $error : "";
?>
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script>
Stripe.setPublishableKey('es_iksl_l5li2xygPS9cJE5MMWE8GSr');
</script>
<div class="content_white register_wrapper">
<div class="content_40" style="margin-left:350px;">
<div class="content_gray" style="margin-top: 50px;">
<form method="post" name="payment_form" id="payment_form">
<div class="error" id="payment_error"></div>
<div class="box" style="padding: 15px 0;">
<label>Card Number</label>
<input type="text" class="text_box" placeholder="Card Number" data-stripe="number" id="card_number" name="card_number" style="height: 40px;" />
<div class="error" id="form_fname_error"></div>
</div>
<div class="box" style="padding: 15px 0;">
<label>Card CVC No</label>
<input type="text" class="text_box" placeholder="CVC Number" data-stripe="cvc" id="cvc_number" name="cvc_number" style="height: 40px;" />
<div class="error" id="form_lname_error"></div>
</div>
<br>
<div class="box" style="padding: 0px">
<label>Card Expiration Month/Year (MM/YYYY)</label>
</div>
<div class="box" style="padding: 15px 0; width: 30%;float: left;">
<input type="text" class="text_box" placeholder="Month-(MM)" data-stripe="exp-month" id="exp_month" name="exp_month" style="height: 40px;" />
<div class="error" id="email_error1"></div>
</div>
<div class="box" style="padding: 15px 0; width: 50%;float: left;" >
<input type="text" class="text_box" placeholder="Year-(YYYY)" data-stripe="exp-year" id="exp_year" name="exp_year" style="height: 40px;" />
<div class="error" id="form_password_error"></div>
</div>
<div class="clear"></div>
<div class="box" style="text-align:center;">
<div class="submit_btn">
<input type="submit" class="btn_blue" id="submit_btn" value="Pay $20"/>
</div>
</div>
<div class="clear"></div>
</form>
</div>
</div>
<div class="clear"></div>
</div>
<script>
$(document).ready(function(){
$('#payment_form').submit(function(event) {
console.log("start");
var $form = $(this);
// Disable the submit button to prevent repeated clicks
$form.find('#submit_btn').prop('disabled', true);
Stripe.createToken({
number: $('#card_number').val(),
cvc: $('#cvc_number').val(),
exp_month: $('#exp_month').val(),
exp_year: $('#exp_year').val()
}, stripeResponseHandler);
// Prevent the form from submitting with the default action
return false;
});
});
// Call back function for stripe response.
function stripeResponseHandler(status, response) {
console.log("ststus"+status);
if (response.error) {
// Re-enable the submit button
$('#submit_btn').removeAttr("disabled");
// Show the errors on the form
// stripeErrorDisplayHandler(response);
$('#payment_error').text(response.error.message);
// $('.subscribe_process').hide();
} else {
var form = $("#payment_form");
// Getting token from the response json.
$('<input>', {
'type': 'hidden',
'name': 'stripeToken',
'value': response.id
}).appendTo(form);
// Doing AJAX form submit to your server.
form.get(0).submit();
return false;
}
}
</script>
当我运行此文件然后运行就绪,当我点击付款按钮然后检查卡数据和到期月份和年份如果可以,然后返回stripeToken然后重新提交表单然后它将返回错误
致命错误:未找到“Stripe”类 d:\ XAMPP \ htdocs中\ moviesaints \程序\意见\用户\ payment_precess.php 在第12行
任何想法都给我解决方案。
答案 0 :(得分:2)
@rubai是绝对正确的。这是你在表格发布时的方式,即你收集卡片信息,然后在你在控制器中这样工作的后期行动:
//代码
public function capture_payment(){
componentWillMount() {
var {rowCount, colCount, data, rowHeights={}} = this.props;
var rows = this.limitData(data, rowCount);
this.content = <table>
<tbody>{rows.map((row, i) => {
var cols = this.limitData(row, colCount);
var style = rowHeights[i] ? {height: rowHeights[i] + 'px'} : void 0;
return <tr style={style} key={i}>{cols.map((cell, i) => {
return <td key={i}>{cell}</td>
})}</tr>
})}</tbody>
</table>
}
render() {
return this.content
}
}
答案 1 :(得分:0)
请使用此FCPATH代替APPPATH
require_once(FCPATH.'libraries/stripe/lib/Stripe.php');
答案 2 :(得分:0)
您可能需要包含init.php而不是stripe.php
require_once(APPPATH.'libraries/stripe/lib/Stripe.php');
然后像这样调用条带库
\Stripe\Stripe::setApiKey('dm_wsdst_yJQB5mrfjpfQX2uMQHf3CbD');