HEX
Server: Apache
System: Linux www3.pit.tblive.com 5.14.0-687.38.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 12 17:19:12 EDT 2026 x86_64
User: awaldron (1020)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/awaldron/_domains/api.alanwaldron.com/v1/payments.php
<?php

//**********************************************************************************************************//
// Method: POST
// Endpoint: order/intent
// Params:

// NOTES: THIS IS HERE FOR KNOWTIFI TESTING
function post_v1_payments_intent( $args, $body, $uid, $is_admin, $db ) {
    // This is your real test secret API key.
    \Stripe\Stripe::setApiKey('sk_test_l3WnGc2TV9png7a0s7DnW90q');

    header('Content-Type: application/json');
    try {
        $paymentIntent = \Stripe\PaymentIntent::create([
            'amount' => $body['amount'],
            'currency' => 'usd',
        ]);
        $output = [
            'clientSecret' => $paymentIntent->client_secret,
        ];
        echo json_encode($output);

    } catch (Error $e) {
        http_response_code(500);
        echo json_encode(['error' => $e->getMessage()]);
    }

    exit;
}


function get_v1_payments_intent( $args, $body, $uid, $is_admin, $db ) {

	echo 'hi';

    exit;
}



//**********************************************************************************************************//
// Method: GET
// Endpoint: payments/log
// Description: Get the list of payments
// Params: body array
function get_v1_payments_log( $args, $body, $uid, $is_admin, $db ) {
    validate_token( $uid );
    validate_admin( $is_admin );

    $sql = "SELECT p.*, u.lname as log_lname, u.fname as log_fname FROM payments as p ";
    $sql .= "LEFT JOIN users as u ON p.logged_by=u.user_id ";
    //$sql .= "LEFT JOIN group_member as gm ON p.group_id=gm.group_id ";
    //$sql .= "LEFT JOIN members as m ON gm.member_id=m.member_id ";
    $sql .= "ORDER BY p.pay_date DESC, p.pay_id DESC";

    $payments = qSet( $db, $sql );

    $pays = [];
    foreach ($payments as $p) {
        $sql = "SELECT m.fname, m.lname, m.member_id  FROM group_member as gm ";
        $sql .= "LEFT JOIN members as m ON gm.member_id=m.member_id ";
        $sql .= "WHERE gm.group_id=".$p['group_id'];

        $names = qSet( $db, $sql );
        $members = '';
        $i = 0;
        foreach ($names as $n) {
            $p['mid'] = $n['member_id'];
            $members = ($i > 0 ? $members.', ' : '') . $n['fname'] . ' ' . $n['lname'];
            $i++;
        }
        $p['members'] = $members;
        $pays[] = $p;
    }

    response(200, ['success'=>true, 'payments'=>$pays]);

}


//**********************************************************************************************************//
// Method: POST
// Endpoint: payments/renewal
// Description: Log a payment into the database
// Params: body array
function post_v1_payments_renewal( $args, $body, $uid, $is_admin, $db ) {
    validate_token( $uid );
    //validate_admin( $is_admin );

    $ins = "INSERT INTO payments ";
    $ins .= "(group_id, user_id, pay_date, pay_amount, pay_method, pay_type, logged_by, pay_details, pay_data) ";
    $ins .= "VALUES (";
    $ins .= $body['group_id'].", ";
    $ins .= $body['user_id'].", ";
    $ins .= $body['pay_date'].", ";
    $ins .= $body['pay_amount'].", ";
    $ins .= "'".addslashes($body['pay_method'])."', ";
    $ins .= "'".addslashes($body['pay_type'])."', ";
    $ins .= $body['logged_by'].", ";
    $ins .= "'".addslashes($body['pay_details'])."', ";
    $ins .= "'".serialize($body['pay_data'])."'";
    $ins .= ")";

    $upd = "UPDATE groups SET paid_thru=".$body['year_applied']." WHERE group_id=".$body['group_id'];

    $upd_result = $db->query($upd);
    $ins_result = $db->query($ins);

    if ($ins_result && $upd_result) {
        response(200, ['success'=>true]);
    } else {
        response(400, ['success'=>false,'errors'=>[$db->error]]);
    }
}



//**********************************************************************************************************//
// Method: POST
// Endpoint: payments/renewal
// Description: Log a payment into the database
// Params: body array
function post_v1_payments_donation( $args, $body, $uid, $is_admin, $db ) {

    $ins = "INSERT INTO donations ";
    $ins .= "(name, email, phone, project, amount, metadata) ";
    $ins .= "VALUES (";
    $ins .= "'".addslashes($body['name'])."', ";
    $ins .= "'".$body['email']."', ";
    $ins .= "'".$body['phone']."', ";
    $ins .= "'".$body['project']."', ";
    $ins .= "'".$body['amount']."', ";
    $ins .= "'".serialize($body['metadata'])."'";
    $ins .= ")";

    $ins_result = $db->query($ins);

    if ($ins_result) {
        response(200, ['success'=>true]);
    } else {
        response(400, ['success'=>false,'errors'=>[$ins,$db->error]]);
    }
}




//**********************************************************************************************************//
// Method: POST
// Endpoint: payments/charge
// Description: Submit a Charge to Stripe
// Params:
function post_v1_payments_charge( $args, $body, $uid, $is_admin, $db ) {

    $charge = \Stripe\Charge::create([
        'amount' => $body['amount'],
        'currency' => 'usd',
        'description' => $body['description'],
        'source' => $body['token'],
        'receipt_email' => $body['email'],
        'metadata' => $body['metadata']
    ]);

    response(200, ['success'=>true, 'chargeResponse'=>$charge, ]);

}