tonoslfx
tonoslfx

Reputation: 3442

Update database after complete payment PayPal

ive got no problem with inserting the transaction after puchased is completed.
the problem is how do i update the data.

MySQL table: USERS:

  id |   email        |  credit
----------------------------
  1    [email protected]      2
  2    [email protected]     1

PayPal IPN:

$p = new paypal_class;  
if ($p->validate_ipn()) {
  if($p->ipn_data['payment_status'] == 'Completed') {
    $db->query("UPDATE users SET credit='". $p->ipn_data['custom'] . "' WHERE email='" . $p->ipn_data['payer_email'] . "'");
  }
}

PAYPAL BUTTON -> hidden(custom) = 5 credit
PAYPAL BUTTON -> hidden(custom) = 10 credit

if user 1 want to topup their credit, the remaining his credit (2)+PayPal(5)= 7.
instead replacing credit(2) to (5).

Upvotes: 0

Views: 1744

Answers (1)

Chris Baker
Chris Baker

Reputation: 50592

Ensure that credit is a numeric type field, then:

$db->query("UPDATE users SET credit= credit + ". $p->ipn_data['custom'] . " WHERE email='" . $p->ipn_data['payer_email'] . "'");

Upvotes: 1

Related Questions