<script>
function makePayment() {
const txRef = `shayonix-${new Date().getTime()}-${Math.random().toString(36).substring(2, 15)}`;
let price = document.getElementById("price").value;
const user_email = document.getElementById("user_email").value;
const username = document.getElementById("username").value;
var store_id = document.getElementById("store_id").value;
var plan_id = document.getElementById("plan_id").value;
var start_date = document.getElementById("start_date").value;
var end_date = document.getElementById("end_date").value;
var status = 'active';
var data = {
store_id: store_id,
plan_id: plan_id,
start_date: start_date,
end_date: end_date,
status: status,
price: price,
};
console.log(data);
FlutterwaveCheckout({
public_key: "FLWPUBK_TEST-7dfa27ed7558780e7b90be30246599b0-X",
tx_ref: txRef,
amount: price,
currency: "TZS",
payment_options: "card, ussd",
callback: function(payment) {
console.log(data);
if (payment.status === "successful") {
$.ajax({
type: "POST",
url: "<?php echo admin_url('membership/insert_payment')?>",
data: $.param(data),
success: function(response) {
document.getElementById("createForm").submit();
},
error: function(xhr, status, error) {
console.error("Error:", xhr.responseText);
document.querySelector("#payment-failed").style.display = 'block';
}
});
} else {
document.querySelector("#payment-failed").style.display = 'block';
}
},
onclose: function() {
console.log("Payment popup closed");
document.querySelector("#payment-failed").style.display = 'block';
},
meta: {
consumer_id: document.getElementById("user_id").value,
consumer_mac: "92a3-912ba-1192a",
},
customer: {
email: user_email,
name: username,
},
customizations: {
title: "Shayonix Membership POS",
description: "Shayonix Membership POS Payment",
logo: "",
},
});
}
</script>
public function insert_payment() {
$post_data = file_get_contents("php://input");
// Decode the JSON data
$data = json_decode($post_data, true);
$store_id = $this->input->post('store_id');
$plan_id = $this->input->post('plan_id');
$start_date = $this->input->post('start_date');
$end_date = $this->input->post('end_date');
$status = $this->input->post('status');
$price = $this->input->post('price');
$data = array(
'store_id' => $store_id,
'plan_id' => $plan_id,
'start_date' => $start_date,
'end_date' => $end_date,
'status' => $status,
'price' => $price,
);
var_dump($data);
$insert = $this->db->insert('user_memberships', $data);
$response = array('status' => $insert ? 'success' : 'error');
echo json_encode($response);
}
i am that on successful payment the data should enter in the database and the data is displaying in the console tab but its not showing in the controller when i redirect to the controller the data is showing null
New contributor
shayonix is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.