问题
I would like to ask is it possible to send the payment for login-ed user using paypal? My android app is a simple booking movie ticket system. I implement the paypal feature to top-up the current user balance. Below is my php table screenshot.
User account table
Paypal verification table
So right now, when i login the user abc, and i top-up using paypal. After the payment is done, the payment suppose to send to the user abc but it would not send, so what should i do in order to send the payment to the user? Furthermore, how do i able get the Acc_ID from user account table and update in paypal verification table, mean that when i click the Acc_ID 1 in user account table it will link to paypal verification table. As you can see that the Acc_ID in paypal verification table are 0, i do not know how to achieve that.
In-case if anyone want to see my php code, here it is or if you want my java code i can update as well. Can someone please help, i will be very appreciated!
token.php
<?php
include_once 'save.php';
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST)){
$payment_id = $_POST['PAYMENT_ID'];
$state = $_POST['STATE'];
$amount = $_POST['AMOUNT'];
$saveObject = new Save();
$saveObject->savePaymentDetail($payment_id, $state, $amount);
}
?>
save.php
<?php
include_once 'db.php';
class Save{
private $db;
public function __construct(){
$this->db = new DbConnect();
}
public function savePaymentDetail($payment_id, $state, $amount){
$query = "INSERT INTO paypal_verification(payment_id, state, amount) VALUES ('$payment_id', '$state', '$amount')";
$inserted = mysqli_query($this->db->getDb(), $query);
if($inserted == 1){
$json = Array('success' => '1');
}else{
$json = Array('success' => '0');
}
mysqli_close($this->db->getDb());
echo json_encode($json, JSON_PRETTY_PRINT);
}
}
?>
Working
$query = "INSERT INTO paypal_verification (acc_id, payment_id, state, amount)
SELECT acc_id, '$payment_id', '$state', '$amount' FROM account_details WHERE Username='abc'";
Not Working
$query = "INSERT INTO paypal_verification (acc_id, payment_id, state, amount)
SELECT acc_id, '$payment_id', '$state', '$amount' FROM account_details WHERE Username='$Username'";
回答1:
If the payment is successful like here
$json = Array('success' => '1');
then you need to update User Account Table like this
get the current balance from the user table
add the new amount to current balance and update the user row.
回答2:
I manage to get it working but is only partially, meaning that right now i can update my user account table balance from paypal_verification amount and can set the acc_id as well, i'm not sure how do i explain well but i can show the picture of the updated mysql table and also the php code.
User account table
paypal_verification table
php file
<?php
include_once 'db.php';
class Save{
private $db;
public function __construct(){
$this->db = new DbConnect();
}
public function savePaymentDetail($payment_id, $state, $amount){
$query = "INSERT INTO paypal_verification (acc_id, payment_id, state, amount)
SELECT acc_id, '$payment_id', '$state', '$amount' FROM account_details WHERE account_details.Acc_ID=account_details.Acc_ID;";
$amount = $amount + amount;
$query .= "UPDATE account_details SET account_details.Acc_Balance = (SELECT SUM(paypal_verification.amount)
FROM paypal_verification WHERE account_details.Acc_ID = paypal_verification.Acc_ID)
WHERE account_details.Acc_ID=account_details.Acc_ID";
$inserted = mysqli_multi_query($this->db->getDb(), $query);
if($inserted == 1){
$json = Array('success' => '1');
}else{
$json = Array('success' => '0');
}
mysqli_close($this->db->getDb());
echo json_encode($json, JSON_PRETTY_PRINT);
echo $query;
}
}
?>
Right now when i pay, it will pay for both users. How do i specifically pay just for the login-ed user from my android app?
How to know that this paypal is pay for a specific user?
来源:https://stackoverflow.com/questions/45784545/android-paypal-send-payment-for-login-user