Paypal Payment top up the accout with less 1 zero

58 views
Skip to first unread message

acpan22

unread,
Apr 4, 2019, 8:03:27 AM4/4/19
to as...@googlegroups.com
Hi,

I am using version 3.5.

Just being alerted that the customer paid via paypal $1K and the invoice shows $100. And actaul amount topped up is $100.

Checked /var/log/astpp/astpp_payment.log, yes, paypal sent IPN post to be $1K.

But astpp system update only $100. 

Scatching my head, where should i fix it? 

Thank you.

ACP


acpan22

unread,
Apr 4, 2019, 9:03:09 AM4/4/19
to ASTPP
Just got more info, 

The actual top up amount is $1 not $100. But the invoice showed $100.
So anyone can tell me what the files to check? 

ACP

acpan22

unread,
Apr 4, 2019, 2:40:16 PM4/4/19
to ASTPP

I see the web's astpp log with this:

[04/Apr/2019:09:36:59 +0000] "GET /login/paypal_response/?amt=......

Anyone can tell me where to locate the  /login/paypal_response in the GET URL above, i see if i can trace the logic in that file.

Thanks.
ACP

acpan22

unread,
Apr 5, 2019, 1:05:57 AM4/5/19
to ASTPP
I might have found the issue but not sure if my fix is correct ( i put my fix at the bottom for your comment):

In the database table - payment_transaction, the 3 fields to store key payment info:

transaction_details = {"mc_gross":"1045.00","protection_eligibility":"Eligible","payer_id":"XXX","payment_date":"02:39:45 Apr 04, 2019 PDT","payment_status":"Completed","charset":"gb2312","first_name":"XXX","mc_fee":"46.28","notify_version":"3.9","custom":"1,000.00000","payer_status":"verified","business":"x...@xxx.xxx","quantity":"1","verify_sign":"xxx","payer_email":"Y...@YYY.YYY","txn_id":"YYY","payment_type":"instant","payer_business_name":"XXXXX","last_name":"XXX","receiver_email":"XX...@XXXX.XXX","payment_fee":"46.28","shipping_discount":"0.00","receiver_id":"XXX","insurance_amount":"0.00","txn_type":"web_accept","item_name":"Billing Store","discount":"0.00","mc_currency":"USD","item_number":"8","residence_country":"XE","shipping_method":"Default","transaction_subject":"","payment_gross":"1045.00","ipn_track_id":"XXXX"}

amount = $1045 

actual_amount =1 (This is wrong should be 1000)

Now, I found the file to handle paypal IPN post @ /var/www/html/astpp/application/modules/login/controllers/login.php :  

1. Refer to the code below, there is a weird line:

$balance_amt = $actual_amount = $response_arr ["custom"];  // (Should this cause problem?)

Note: $response_arr ["custom"]  is the value from IPN, i.e. 1000, that we want to update the account balance with.

2. The part to update the "actual_amount" in "payment_transaction" table  (which updated to 1 instead of 1000):

$payment_trans_array = array (
"accountid" => $response_arr ["item_number"],

"amount" => $response_arr ["payment_gross"],  (value = 1045.00 ** this is correct)

"tax" => "1",

"payment_method" => "Paypal",
"actual_amount" => $actual_amount,   ( value = 1 ** this is  wrong, should be 1000, the $response_arr ["custom"] value from IPN, it seems the value assignment caused problem )

"paypal_fee" => $paypalfee,
"user_currency" => $currency ["currency"],
"currency_rate" => $currency ["currencyrate"],
"transaction_details" => json_encode ( $response_arr ),
"date" => $date 

3. The part to update the "credit" field in "payments" table  (which updated to 1 instead of 1000):

$paymentid = $this->db->insert ( 'payment_transaction', $payment_trans_array );
$parent_id = $account_data ['reseller_id'] > 0 ? $account_data ['reseller_id'] : '-1';
$payment_arr = array (
"accountid" => $response_arr ["item_number"],
"payment_mode" => "1",
"credit" => $balance_amt,       ( value = 1 ** this is  wrong, should be 1000)
"type" => "PAYPAL",
"payment_by" => $parent_id,
"notes" => "Payment Made by Paypal on date:-" . $date,
"paypalid" => $paymentid,
"txn_id" => $response_arr ["txn_id"],
'payment_date' => gmdate ( 'Y-m-d H:i:s', strtotime ( $response_arr ['payment_date'] ) ) 
);


file: /var/www/html/astpp/application/modules/login/controllers/login.php
function paypal_response() {
if (count ( $_POST ) > 0) {
$response_arr = $_POST;
$logger = ( array ) $this->db->get_where ( "system", array (
"name" => "log_path",
"group_title" => "global" 
) )->first_row ();
$logger_path = $logger ['value'];
$fp = fopen ( $logger_path . "astpp_payment.log", "a+" );
$date = date ( "Y-m-d H:i:s" );
fwrite ( $fp, "====================" . $date . "===============================\n" );
foreach ( $response_arr as $key => $value ) {
fwrite ( $fp, $key . ":::>" . $value . "\n" );
}
$payment_check = $this->db_model->countQuery ( "txn_id", "payments", array (
"txn_id" => $response_arr ['txn_id'] 
) );
if (($response_arr ["payment_status"] == "Pending" || $response_arr ["payment_status"] == "Complete" || $response_arr ["payment_status"] == "Completed") && $payment_check == 0) {
$paypal_tax = ( array ) $this->db->get_where ( "system", array (
"name" => "paypal_tax",
"group_title" => "paypal" 
) )->first_row ();
$paypal_tax = $paypal_tax ['value'];
$balance_amt = $actual_amount = $response_arr ["custom"];
$paypal_fee = ( array ) $this->db->get_where ( "system", array (
"name" => "paypal_fee",
"group_title" => "paypal" 
) )->first_row ();
$paypal_fee = $paypal_fee ['value'];
$paypalfee = ($paypal_fee == 0) ? '0' : $response_arr ["mc_gross"];
$account_data = ( array ) $this->db->get_where ( "accounts", array (
"id" => $response_arr ["item_number"] 
) )->first_row ();
$currency = ( array ) $this->db->get_where ( 'currency', array (
"id" => $account_data ["currency_id"] 
) )->first_row ();
$date = date ( 'Y-m-d H:i:s' );
$payment_trans_array = array (
"accountid" => $response_arr ["item_number"],
"amount" => $response_arr ["payment_gross"],
"tax" => "1",
"payment_method" => "Paypal",
"actual_amount" => $actual_amount,
"paypal_fee" => $paypalfee,
"user_currency" => $currency ["currency"],
"currency_rate" => $currency ["currencyrate"],
"transaction_details" => json_encode ( $response_arr ),
"date" => $date 
);
$paymentid = $this->db->insert ( 'payment_transaction', $payment_trans_array );
$parent_id = $account_data ['reseller_id'] > 0 ? $account_data ['reseller_id'] : '-1';
$payment_arr = array (
"accountid" => $response_arr ["item_number"],
"payment_mode" => "1",
"credit" => $balance_amt,
"type" => "PAYPAL",
"payment_by" => $parent_id,
"notes" => "Payment Made by Paypal on date:-" . $date,
"paypalid" => $paymentid,
"txn_id" => $response_arr ["txn_id"],
'payment_date' => gmdate ( 'Y-m-d H:i:s', strtotime ( $response_arr ['payment_date'] ) ) 
);
$this->db->insert ( 'payments', $payment_arr );
$this->db->select ( 'invoiceid' );
$this->db->order_by ( 'id', 'desc' );
$this->db->limit ( 1 );
$last_invoice_result = ( array ) $this->db->get ( 'invoices' )->first_row ();
$last_invoice_ID = isset ( $last_invoice_result ['invoiceid'] ) && $last_invoice_result ['invoiceid'] > 0 ? $last_invoice_result ['invoiceid'] : 1;
$reseller_id = $account_data ['reseller_id'] > 0 ? $account_data ['reseller_id'] : 0;
$where = "accountid IN ('" . $reseller_id . "','1')";
$this->db->where ( $where );
$this->db->select ( '*' );
$this->db->order_by ( 'accountid', 'desc' );
$this->db->limit ( 1 );
$invoiceconf = $this->db->get ( 'invoice_conf' );
$invoiceconf = ( array ) $invoiceconf->first_row ();
$invoice_prefix = $invoiceconf ['invoice_prefix'];
$due_date = gmdate ( "Y-m-d H:i:s", strtotime ( gmdate ( "Y-m-d H:i:s" ) . " +" . $invoiceconf ['interval'] . " days" ) );
$invoice_id = $this->generate_receipt ( $account_data ['id'], $balance_amt, $account_data, $last_invoice_ID + 1, $invoice_prefix, $due_date );
$details_insert = array (
'created_date' => $date,
'credit' => $balance_amt,
'debit' => '-',
'accountid' => $account_data ["id"],
'reseller_id' => $account_data ['reseller_id'],
'invoiceid' => $invoice_id,
'description' => "Payment Made by Paypal on date:-" . $date,
'item_type' => 'PAYMENT',
'before_balance' => $account_data ['balance'],
'after_balance' => $account_data ['balance'] + $balance_amt 
);
$this->db->insert ( "invoice_details", $details_insert );
$this->db_model->update_balance ( $balance_amt, $account_data ["id"], "credit" );
/*
* if($parent_id > 0){
* $reseller_ids=$this->common->get_parent_info($parent_id,0);
* $reseller_ids=rtrim($reseller_ids,",");
* $reseller_arr=explode(",",$reseller_ids);
* if(!empty($reseller_arr)){
* foreach($reseller_arr as $key=>$reseller_id){
* $account_data = (array)$this->db->get_where("accounts", array("id" => $reseller_id))->first_row();
* $this->db->select('invoiceid');
* $this->db->order_by('id','desc');
* $this->db->limit(1);
* $last_invoice_result=(array)$this->db->get('invoices')->first_row();
* $last_invoice_ID=$last_invoice_result['invoiceid'];
* $reseller_id=$account_data['reseller_id'] > 0 ? $account_data['reseller_id'] : 0;
* $where="accountid IN ('".$reseller_id."','1')";
* $this->db->where($where);
* $this->db->select('*');
* $this->db->order_by('accountid', 'desc');
* $this->db->limit(1);
* $invoiceconf = $this->db->get('invoice_conf');
* $invoiceconf = (array)$invoiceconf->first_row();
* $invoice_prefix=$invoiceconf['invoice_prefix'];
* $due_date = gmdate("Y-m-d H:i:s",strtotime(gmdate("Y-m-d H:i:s")." +".$invoiceconf['interval']." days"));
* $invoice_id=$this->generate_receipt($account_data['id'],$balance_amt,$account_data,$last_invoice_ID+1,$invoice_prefix,$due_date);
* $parent_id=$account_data['reseller_id'] > 0 ? $account_data['reseller_id'] : -1;
* $payment_arr = array("accountid"=> $account_data["id"],
* "payment_mode"=>"1",
* "credit"=>$balance_amt,
* "type"=>"PAYPAL",
* "payment_by"=>$parent_id,
* "notes"=>"Your account has been credited due to your customer account recharge done by paypal",
* "paypalid"=>$paymentid,
* "txn_id"=>$response_arr["txn_id"],
* 'payment_date'=>gmdate('Y-m-d H:i:s',strtotime($response_arr['payment_date'])));
* $this->db->insert('payments', $payment_arr);
* $details_insert=array(
* 'created_date'=>$date,
* 'credit'=>$balance_amt,
* 'debit'=>'-',
* 'accountid'=>$account_data['id'],
* 'reseller_id'=>$parent_id,
* 'invoiceid'=>$invoice_id,
* 'description'=>"Your account has been credited due to your customer account recharge done by paypal",
* 'item_type'=>'PAYMENT',
* 'before_balance'=>$account_data['balance'],
* 'after_balance'=>$account_data['balance']+$balance_amt,
* );
* $this->db->insert("invoice_details", $details_insert);
* $this->db_model->update_balance($balance_amt,$account_data["id"],"credit");
* }
* }
* }
*/
redirect ( base_url () . 'user/user/' );
}
}
redirect ( base_url () . 'user/user/' );
}



The update method to topup account balance is at: /var/www/html/astpp/application/models/db_model.php

function update_balance($amount, $accountid, $payment_type) {
if ($payment_type == "debit" || $payment_type == "0") {
$query = "update accounts set balance =  IF(posttoexternal=1,balance+" . $amount . ",balance-" . $amount . ") where id ='" . $accountid . "'";
return $this->db->query ( $query );
} else {
$query = "update accounts set balance =  IF(posttoexternal=1,balance-" . $amount . ",balance+" . $amount . ") where id ='" . $accountid . "'";
return $this->db->query ( $query );
}
}


My propose fix:

Change 

$balance_amt = $actual_amount = $response_arr ["custom"];  

to 

$balance_amt = $response_arr ["custom"];  
$actual_amount = $response_arr ["custom"];  

But i am not sure. Any comment will be helpful, as there maybe other part needs to be fixed,
and this may also happen in verion 3.6.

ACP
Reply all
Reply to author
Forward
0 new messages