Hi, for PHP integration with PayPal I found this very useful, clear, and simple tutorial https://serverguy.com/learn/paypal-integration-in-php/ It is very interesting because it allows you to pass parameters to PayPal in a "hidden" way, without having to put them in hidden fields. However, I have problems with the section of code used to read the response from PayPal. Here it is.
// Handle the PayPal response.
// Create a connection to the database.
$db = new mysqli($dbConfig['host'], $dbConfig['username'], $dbConfig['password'], $dbConfig['name']);
// Assign posted variables to local data array.
$data = [
'item_name' => $_POST['item_name'],
'item_number' => $_POST['item_number'],
'payment_status' => $_POST['payment_status'],
'payment_amount' => $_POST['mc_gross'],
'payment_currency' => $_POST['mc_currency'],
'txn_id' => $_POST['txn_id'],
'receiver_email' => $_POST['receiver_email'],
'payer_email' => $_POST['payer_email'],
'custom' => $_POST['custom'],
];
// We need to verify the transaction comes from PayPal and check we've not
// already processed the transaction before adding the payment to our
// database.
if (verifyTransaction($_POST) && checkTxnid($data['txn_id'])) {
if (addPayment($data) !== false) {
// Payment successfully added.
}
}
I added a very simple INSERT, but there is no way to make it work: the data is not saved in the database.
// We need to verify the transaction comes from PayPal and check we've not
// already processed the transaction before adding the payment to our
// database.
if (verifyTransaction($_POST) && checkTxnid($data['txn_id'])) {
if (addPayment($data) !== false) {
// Payment successfully added.
$sql = "INSERT INTO prenotazioni_date (id_prenotazione, tariffa_notte) VALUES ('1', '102.00')";
$db->query($sql);
}
}
}
I also tried to move the INSERT to other parts of the code, outside the IF, but nothing to do. I want to specify that the records in the payments table are inserted without any problem.
It was 7 years that I hadn't programmed anymore and I'm afraid I got a little rusty.