<?php

session_start();
include "include.php";
include "session.php";
// include "../session.php";


if ($_POST['username'] > 0) {
    if ($_POST['username'] > 0) {
        $o1->wallet_balance = "Main";
        $o1->parent_id = 0;
        $o1->api_id = 0;
        $o1->api_old_balance = 0;
        $o1->api_amount = 0;
        $o1->api_new_balance = 0;
        $o1->api_name = "";
        $o1->provider_id = "0";
        $o1->provider_name = "0";
        $o1->user_id = $_POST['username'];
        $o1->user_1_id = '1';
        $o1->user_1_name = 'Paytm';
        $o1->cash_credit = 'Add';
        $o1->transfer_type = "Credit";
        if ($o1->user_id > 0) {
            $o2 = $factory->get_object($o1->user_id, "users", "user_id");

            $o1->user_old_balance = $o2->amount_balance;
            $o1->user_name = $o2->user_name . " " . $o2->name;
        }
        $o1->total_amount = $_POST['amount'];
        $o1->amount = $_POST['amount'];
       if ($o1->transfer_type == "Credit") {
            $o1->transaction_type = 'Add Money Paytm';
            $o1->user_new_balance = $o1->user_old_balance + $_POST['amount'];
        }
        $o1->transaction_details = "Rs. " . $o1->amount . " " . $o1->transaction_type . "  By Self";
        $o1->transaction_date = todaysDate();
        $o1->created_at = todaysDate();
        $o1->updated_at = todaysDate();
        $o1->ref_number = "";
        $o1->api_number = reference_number();
        $o1->opid = $_POST['order_id'];
        $o1->api_response = "";
        $o1->commission_ret = "0";
        $o1->gst = "0";
        $o1->tds = "0";
        $o1->recharge_path = "App";
        $o1->ip_address = $_SERVER['REMOTE_ADDR'];
        $o1->request_url = "";
        $o1->request_url_api = "";
        $o1->callback_reponse = "";
        $o1->callback_reponse_api = "";
        $o1->payment_mode = "Paytm";
        $o1->comment = "Add by it self Paytm";
        $o1->provider_type = $o1->transaction_type;
        $o1->circle_id = 0;
        $o1->circle_name = "";
        $o1->mobile_number = "";
        $o1->status = "Success";
        $o1->disputed = "No";
        $o1->disputed = "No";
        $o1->is_active = "1";
        $o1->send_user_type = "Retailer";
        $o1->month_year = date("F") . "-" . date('Y');
        
        $o1->wallet_id = $insertor->insert_object($o1, "wallet");
        $o1->ref_number = "NP" . $o1->wallet_id;
        $o1->wallet_id = $updater->update_object($o1, "wallet");
        
            $o2->amount_balance = $o1->user_new_balance;
            $amount_balance = $o2->amount_balance;
        

        $o2->user_id = $updater->update_object($o2, "users");
        insert_notifications($o2->user_id, $o1->transaction_details, 'Send Money');
        
        $message = "Your wallet have been " . $o1->transfer_type . "ed with Rs. " . $o1->amount . " by Paytm. Your new Acpl balance is Rs. " . $amount_balance . "";
  $result['error_msg'] = "Information Saved Successfully";
        $result['error'] = '0';
    } else {
        $result['error_msg'] = "Please Select User";
        $result['error'] = 1;
    }
} else {
    $result['error_msg'] = "Something went wrong please try again";
    $result['error'] = 1;
}


echo json_encode($result);
?>