<?php

class payment {

    public static function paymentInit($data): void
    {
        $payload = [
            'payment_id'  => $data['id'],
            'create_date' => date("Y-m-d H:i:s")
        ];

        query::Insert(TABLE_PAYMENT, $payload);
    }

    public static function paymentUpdate($data): void
    {
        $payload = [
            'payment_id'   => $data['payment_intent'],
            'account_id'   => util::extractAID($data['customer_details']['email']),
            'package_id'   => util::extractPID($data['customer_details']['email']),
            'pay_amount'   => $data['amount_total']/100,
            'total_amount' => $data['amount_subtotal']/100,
            'pay_date'     => date("Y-m-d H:i:s")
        ];

        query::Update(TABLE_PAYMENT, $payload, ['payment_id' => $payload['payment_id']]);

        $user_info = query::Get(TABLE_USER,['account_id' => $payload['account_id']]);

        $pack_data = [
            'account_id'  => $payload['account_id'],
            'package_id'  => $payload['package_id'],
            'payment_id'  => $payload['payment_id'],
            'userid'      => $user_info['userid'],
            'charid'      => util::extractCID($data['customer_details']['email']),
        ];

        self::sendtoItem($pack_data);
    }

    public static function sendtoItem($data): void
    {
        item::receivedData($data);
    }
}

?>