我正在从事付款意向订阅,但是它只收费一次,它不能作为订阅使用,任何人都可以检查我的整个代码并帮助我解决此问题吗?这是我的代码,我不知道为什么它只能运行一次,请问,我在哪里做错了?有人可以帮我吗
index.php
$.ajax({
type : 'POST',
url : '" . $site_url . "/setup_payment_intent.php',
data : 'amount='+amount_value+'&amount_other='+amount_other+'&amount_once='+amount_once,
dataType: 'json',
crossDomain:true,
success :function(msg) {
//console.log(msg);
var clientSecret = msg.client_secret; //client_secret_id
stripe.confirmCardSetup(
clientSecret,
{
payment_method: {
card: card,
billing_details: {name: 'Test'}
}
}
).then(function(result) {
if (result.error) {
$('.loader').hide();
alert(result.error.message);
return false;
} else {
console.log(result);
var payment_method = result.setupIntent.payment_method;
$.ajax({
type : 'POST',
url : '" . $site_url . "/subsciption.php',
data : $('form').serialize()+'&payment_method_id='+payment_method,
dataType: 'json',
crossDomain:true,
success :function(msg) {
var customer_id = msg.customer_id;
//alert('sdsdsdsd123');
stripe.confirmCardPayment(msg.client_secret, {
//payment_method: intent.last_payment_error.payment_method.id,
payment_method : 'pm_card_visa',
setup_future_usage: 'off_session',
save_payment_method : true,
}).then(function(result) {
if (result.error) {
$('.loader').hide();
console.log(result.error.message);
alert(result.error.message);
return false;
} else {
if (result.paymentIntent.status === 'succeeded') {
//alert('sdsdsd');
$.ajax({
type : 'POST',
url : '" . $site_url . "/save_card.php',
data : $('form').serialize()+'&payment_method_id='+payment_method+'&customer_id='+customer_id,
dataType: 'json',
crossDomain:true,
success :function(msg) {
$('.loader').hide();
document.location.href='".$site_url."/success.php';
}
});
}
}
});
}
});
}
});
},
error :function(msg) {
$('.loader').hide();
}
setup_payment_intent.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once $_SERVER['DOCUMENT_ROOT'] . '/App/Payment/Controller.php';
$obj_payment = new Payment();
$data = array();
$data['payment_method_types'] = ["card"];
$data['usage'] = 'off_session';
$response = $obj_payment->call($data, 'setup_intents');
if (!empty($response) && (isset($response['id']) && $response['id'] != '')) {
$payment_intent_id = $response['id'];
$client_secret = $response['client_secret'];
echo json_encode(array('status' => 1, 'id' => $payment_intent_id,'client_secret'=>$client_secret));
} else {
echo json_encode(array('status' => 0,'msg'=>$response['error']['message']));
}
die;
?>
subscription.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once $_SERVER['DOCUMENT_ROOT'] . '/App/Payment/Controller.php';
$obj_payment = new Payment();
$payment_method_id = $_POST['payment_method_id'];
$data = array();
$data['description'] = 'Customer for Hiraiser';
$data['payment_method'] = $payment_method_id;
$response = $obj_payment->call($data, 'customers');
$is_recurring = 1;
if (isset($_POST['amount']) && $_POST['amount'] > 0) {
$amount = $_POST['amount'];
$is_recurring = 1;
} else if (isset($_POST['amount_once']) && $_POST['amount_once'] > 0) {
$amount = $_POST['amount_once'];
$is_recurring = 0;
} else if (isset($_POST['amount_other']) && $_POST['amount_other'] > 0) {
$amount = $_POST['amount_other'];
$is_recurring = 1;
}
if (!empty($response) && (isset($response['id']) && $response['id'] != '')) {
$customer_id = $response['id'];
$data = array();
$data['amount'] = $amount*100;
$data['currency'] = 'usd';
$data['customer'] = $customer_id;
$data['payment_method'] = $payment_method_id;
$data['payment_method_types'][] = 'card';
$response = $obj_payment->call($data, 'payment_intents');
if (!empty($response) && (isset($response['id']) && $response['id'] != '')) {
echo json_encode(array('status'=>1,'id'=>$response['id'],'client_secret'=>$response['client_secret'],'customer_id'=>$customer_id));
} else {
echo json_encode(array('status'=>0,'msg'=>$response['error']['message']));
}
} else {
echo json_encode(array('status'=>0));
}
die;
save_card.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once $_SERVER['DOCUMENT_ROOT'] . '/App/DB/db.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/App/Payment/Controller.php';
$obj_payment = new Payment();
$db_obj = new DB();
$con = $db_obj->connection();
$payment_method_id = $_POST['payment_method_id'];
$customer_id = $_POST['customer_id'];
$is_recurring = 1;
if (isset($_POST['amount']) && $_POST['amount'] > 0) {
$amount = $_POST['amount'];
$is_recurring = 1;
} else if (isset($_POST['amount_once']) && $_POST['amount_once'] > 0) {
$amount = $_POST['amount_once'];
$is_recurring = 0;
} else if (isset($_POST['amount_other']) && $_POST['amount_other'] > 0) {
$amount = $_POST['amount_other'];
$is_recurring = 1;
}
$transaction_id = $payment_method_id;
$sql = " INSERT INTO donations (date,name_first,name_last,email,address,city,region,zip,country,state,phone,phone_mobile,info_string,amount,customer_id) VALUES
('" . mysqli_real_escape_string($con, date("Y-m-d H:i:s")) . "','" . mysqli_real_escape_string($con, $_POST['name_first']) . "','" . mysqli_real_escape_string($con, $_POST['name_last']) . "','" . mysqli_real_escape_string($con, $_POST['email']) . "','" . mysqli_real_escape_string($con, $_POST['address']) . "'
,'" . mysqli_real_escape_string($con, $_POST['city']) . "','" . mysqli_real_escape_string($con, $_POST['region']) . "','" . mysqli_real_escape_string($con, $_POST['zip']) . "','" . mysqli_real_escape_string($con, $_POST['country']) . "','" . mysqli_real_escape_string($con, $_POST['state']) . "'
,'" . mysqli_real_escape_string($con, $_POST['phone']) . "','" . mysqli_real_escape_string($con, $_POST['phone_mobile']) . "','" . mysqli_real_escape_string($con, $_POST['info_string']) . "','" . mysqli_real_escape_string($con, $amount) . "',''
)
";
if ($db_obj->insert($con, $sql)) {
$donor_id = mysqli_insert_id($con);
$sql = " INSERT INTO transactions (donor_id,transaction_id,raw_data,created_date)
VALUES (".$donor_id.",'".$transaction_id."','','".date("Y-m-d H:i:s")."')
";
if($db_obj->insert($con, $sql)) {
echo json_encode(array('status'=>1));
} else {
echo json_encode(array('status'=>0));
}
} else {
echo json_encode(array('status'=>0));
}
die;