# Payment Helper Functions

### function add\_payment($payment) {.....}

#### **Supported hooks**

**Filter name:**  before\_add\_payment\
**Description:** This filter would be executed before add payment into the database in add\_payment  helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘before_add_payment’, ‘before_add_payment_callback_fun’, 10, 1 );

function before_add_payment_callback_fun($payment) {
 // code
}
```

**Filter name:**  should\_add\_payment\
**Description:** This filter would be executed before add payment into database in add\_payment helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘should_add_payment’, ‘should_add_payment_callback_fun’, 10, 1 );

function should_add_payment_callback_fun($payment) {
    // code
}
```

**hook name:**  pre.add.payment\
**Description:** This hook would be executed before add payment into the database in add\_payment  helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('pre.add.payment', 'pre_add_payment_callback_fun', 10, 1);

function pre_add_payment_callback_fun($payment) {
    // code
}
```

**hook name:**  post.add.payment\
**Description:** This hook would be executed after add payment into the database in add\_payment helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('post.add.payment', 'post_add_payment_callback_fun', 10, 1);

function post_add_payment_callback_fun($payment) {
    // code
}
```

**Usage**

```php
// for use payment helper you need to add this helper on controller or
// you can autoload this helper.

$this->load->helper('includes/payment');

// add a new payment in payment table.
$payment_id = add_payment($payment);
```

**Request Parameters**

Parameters in array format includes following attributes:

<table><thead><tr><th>Param</th><th>Type</th><th width="200">Required</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td>description</td><td>Character</td><td></td><td>Null</td><td>The description of a specific payment.</td></tr><tr><td>booking_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The booking_id  for a specific payment.</td></tr><tr><td>amount</td><td>Decimal Integer</td><td>Yes</td><td>0</td><td>The amount for a specific payment.</td></tr><tr><td>is_captured</td><td>Integer</td><td></td><td>0</td><td>The is_captured for a specific charge.</td></tr><tr><td>selling_date</td><td>Date</td><td>Yes</td><td>Date</td><td>The selling_date for specific payment ( must provide date in gmdate() format).</td></tr><tr><td>user_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The user_id for a specific payment.</td></tr><tr><td>customer_id</td><td>Integer</td><td></td><td>0</td><td>The customer_id for a specific payment.</td></tr><tr><td>parent_charge_id</td><td>Integer</td><td></td><td>Null</td><td>The parent_charge_id for specific payment.</td></tr><tr><td>company_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The company_id for specific payment.</td></tr><tr><td>payment_type_id</td><td>Integer</td><td></td><td>0</td><td>The payment_type_id for a specific payment.</td></tr><tr><td>gateway_charge_id</td><td>Character</td><td>Yes</td><td>Null</td><td>The gateway charge_id for a specific payment.</td></tr><tr><td>payment_gateway_used</td><td>Character</td><td>Yes</td><td>Null</td><td>The payment gateway is used for a specific payment.</td></tr><tr><td>selected_gateway</td><td>Character</td><td>Yes</td><td>Null</td><td>The selected_gateway for a specific payment.</td></tr><tr><td>cvc</td><td>Integer</td><td>Yes</td><td>Null</td><td>The CVC of the user for a specific payment.</td></tr><tr><td>folio_id</td><td>Integer</td><td></td><td>0</td><td>The folio_id for a specific payment.</td></tr></tbody></table>

**Response**

```
Response includes the following attributes:
if data have been added successfully it would return the key of specific payment id.
```

```php
return $payment_id;
```

```
if data does not add it will return null.
```

### function get\_payment($payment\_id) {....}

#### **Supported hooks**

**Filter name:**  before\_get\_payment \
**Description:** This filter would be executed before retrieving payment  details from database in get\_payment  helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘before_get_payment’, ‘before_get_payment_callback_fun’, 10, 1 );

function before_get_payment_callback_fun($payment_id) {
 // code
}
```

**Filter name:**  should\_get\_payment\
**Description:** This filter would be executed before retrieving payment details from database in get\_payment helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘should_get_payment’, ‘should_get_payment_callback_fun’, 10, 1 );

function should_get_payment_callback_fun($payment_id) {
    // code
}
```

**hook name:**  pre.get.payment\
**Description:** This hook would be executed before retrieving payment details from database in get\_payment helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('pre.get.payment', 'pre_get_payment_callback_fun', 10, 1);

function pre_get_payment_callback_fun($payment_id) {
    // code
}
```

**hook name:**  post.get.payment\
**Description:** This hook would be executed after retrieving payment details from database in get\_payment helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('post.get.payment', 'post_get_payment_callback_fun', 10, 1);

function post_get_payment_callback_fun($payment_id) {
    // code
}
```

**Usage**

```php
// Retrieves payment data based on a payment_id.
$payment_data = get_payment($payment_id);
```

**Request Parameters**

| Param        | Type    | Required | Default | Description                                                    |
| ------------ | ------- | -------- | ------- | -------------------------------------------------------------- |
| $payment\_id | Integer | Yes      | Null    | The primary id of the payment corresponds to the payment table |

**Response**

```php
// $response array includes following attributes:
// $response['user_id'] : the user_id of specific payment.
// $response['booking_id'] : the booking_id for specific payment .
// $response['selling_date'] : the selling_date for specific payment.
// $response['company_id'] : the company_id for specific payment.
// $response['amount'] : the amount for specific payment.
// $response['customer_id'] : the customer_id for specific payment.
// $response['payment_type_id'] : the payment_type_id for specific payment.
// $response['description'] : the description for specific payment.
// $response['selected_gateway'] : the selected_gateway for specific payment.
// $response['capture_payment_type'] : the capture_payment_type for specific payment.
// and many more attributes for table payment.

// Successfully response giving you array of payment data. 

Array
(
    [payment_id] => 1
    [description] => payment
    [date_time] => 2022-01-26 17:19:53
    [booking_id] => 1
    [amount] => 100.00
    [payment_type_id] => 1
    [credit_card_id] => 1
    [selling_date] => 
    [is_deleted] => 0
    [user_id] => 1
    [customer_id] => 1
    [payment_gateway_used] => 
    [gateway_charge_id] => 
    [read_only] => 
    [payment_status] => charge
    [parent_charge_id] => 
    [is_captured] => 0
    [logs] => 
    [payment_link_id] => 
)

// if there is no payment data for any payment id provided in input or any error will return null.
```

### function update\_payment($payment, $payment\_id) {....}

**Usage**

```php
// update payment data based on payment update data and payment_id.
 update_payment($payment, $payment_id);
```

**Supported hooks**

**Filter name:**  before\_update\_payment\
**Description:** This filter would be executed before update payment into the database in update\_payment helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘before_update_payment’, ‘before_update_payment_callback_fun’, 10, 1 );

function before_update_payment_callback_fun($payment, $payment_id) {
 // code
}
```

**Filter name:**  should\_update\_payment\
**Description:** This filter would be executed before update payment into database in update\_payment helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘should_update_payment’, ‘should_update_payment_callback_fun’, 10, 1 );

function should_update_payment_callback_fun($payment, $payment_id) {
    // code
}
```

**hook name:**  pre.update.payment\
**Description:** This hook would be executed before update payment into the database in update\_payment helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('pre.update.payment', 'pre_update_payment_callback_fun', 10, 1);

function pre_update_payment_callback_fun($payment, $payment_id) {
    // code
}
```

**hook name:**  post.update.payment\
**Description:** This hook would be executed after update payment into the database in update\_payment helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('post.update.payment', 'post_update_payment_callback_fun', 10, 1);

function post_update_payment_callback_fun($payment, $payment_id) {
    // code
}
```

**Request Parameters**

Request required payment\_id and  array format data includes following attributes:

<table><thead><tr><th>Param</th><th>Type</th><th width="200">Required</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td>payment_id</td><td>Integer</td><td>Yes</td><td>Null</td><td>The primary key of the payment table for a specific payment.</td></tr><tr><td>description</td><td>Character</td><td></td><td>Null</td><td>The description of a specific payment.</td></tr><tr><td>is_captured</td><td>Integer</td><td></td><td>0</td><td>The is_captured for a specific charge.</td></tr><tr><td>payment_type_id</td><td>Integer</td><td>Yes</td><td>0</td><td>The payment_type_id for a specific payment.</td></tr><tr><td>selected_gateway</td><td>Character</td><td>Yes</td><td>Null</td><td>The selected_gateway for a specific payment.</td></tr><tr><td>payment_status</td><td>Character</td><td>Yes</td><td>Null</td><td>The payment_status for a specific payment.</td></tr><tr><td>folio_id</td><td>Integer</td><td></td><td>0</td><td>The folio_id for a specific payment.</td></tr></tbody></table>

**Response**

```
Response return mixed Either true or null if payment data is updated then true else null.
```

### function get\_payments($filter) {.....}

**Supported hooks**

**Filter name:**  before\_get\_payments\
**Description:** This filter would be executed before retrieving payment details from database in get\_payments helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘before_get_payments’, ‘before_get_payments_callback_fun’, 10, 1 );

function before_get_payments_callback_fun($filter) {
 // code
}
```

**Filter name:**  should\_get\_payments\
**Description:** This filter would be executed before retrieving payment details from database in get\_payments helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_filter( ‘should_get_payments’, ‘should_get_payments_callback_fun’, 10, 1 );

function should_get_payments_callback_fun($filter) {
    // code
}
```

**hook name:**  pre.get.payments\
**Description:** This hook would be executed before retrieving payment details from database in get\_payments helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('pre.get.payments', 'pre_get_payments_callback_fun', 10, 1);

function pre_get_payments_callback_fun($filter) {
    // code
}
```

**hook name:**  post.get.payments\
**Description:** This hook would be executed after retrieving payment details from database in get\_payments helper.\
**Usage:**

```php
// The filter callback function is based on the filter.

add_action('post.get.payments', 'post_get_payments_callback_fun', 10, 1);

function post_get_payments_callback_fun($filter) {
    // code
}
```

**Usage**

```php
// Retrieves payment data based on a filter array.
$payment_data = get_payments($filter);
```

**Request Parameters**

parameter array filter required for payment details.

| Param        | Type    | Required | Default | Description                                                     |
| ------------ | ------- | -------- | ------- | --------------------------------------------------------------- |
| payment\_id  | Integer | Yes      | Null    | The primary key id of the payment table for a specific payment. |
| booking\_id  | Integer | Yes      | Null    | The booking\_id  for specific payment.                          |
| customer\_id | Integer | Yes      | Null    | The customer\_id  for a specific payment.                       |
| folio\_id    | Integer | Yes      | Null    | The folio\_id for a specific payment.                           |

**Response**

```php
// $response array includes following attributes:
// $response['user_id'] : the user_id of specific payment.
// $response['booking_id'] : the booking_id for specific payment.
// $response['cvc'] : the cvc for specific payment.
// $daresponseta['selling_date'] : the selling_date for specific payment.
// $response['company_id'] : the company_id for specific payment.
// $response['amount'] : the amount for specific payment.
// $response['customer_id'] : the customer_id for specific payment.
// $response['payment_type_id'] : the payment_type_id for specific payment.
// $response['description'] : the description for specific payment.
// $response['is_captured'] : the is_captured for specific payment.
// $response['selected_gateway'] : the selected_gateway for specific payment.
// $response['capture_payment_type'] : the capture_payment_type for specific payment.
// $response['folio_id'] : the folio_id for specific payment.
// and many more attributes for table payment and join with customer , user_profiles table.

// Successfully response giving you array of payment data.

Array
(
    [0] => Array
        (
            [payment_id] => 2
            [is_captured] => 0
            [description] => good
            [customer_name] => vishal solanki
            [date_time] => 2022-01-26 17:23:03
            [booking_id] => 1
            [amount] => 0.00
            [payment_status] => charge
            [is_deleted] => 0
            [payment_type] => AMEX
            [payment_type_id] => 1
            [payment_gateway_used] => 
            [gateway_charge_id] => 
            [read_only] => 
            [selling_date] => 
            [user_name] => 
            [folio_id] => 
            [payment_link_id] => 
        )

)

// if there is no payment data for filter provided in input or any error will return null.
```

### **function delete\_p**aymen&#x74;**(**$payment\_i&#x64;**) {.....}**

**Usage**

```php
// delete a payment data from the payment table. it's a soft delete process only status will change data still existing in the backend database.

 delete_payment($payment_id);
```

**Request Parameters**

| Param        | Type    | Required | Default | Description                                             |
| ------------ | ------- | -------- | ------- | ------------------------------------------------------- |
| $payment\_id | Integer | Yes      | Null    | The id of the payment corresponds to the payment  table |

**Response**

```
Response return mixed Either true or null if payment data is deleted then true 
else null.
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.minical.io/coming-soon/access-minical-data-using-helpers/payment-helper-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
