PHPackages                             carlosupreme/cep-query-payment - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. carlosupreme/cep-query-payment

ActiveLibrary[Payment Processing](/categories/payments)

carlosupreme/cep-query-payment
==============================

Laravel package for querying and verifying SPEI payment status from Banco de México's CEP system using automated browser scraping

v2.0.0(7mo ago)4581MITPHPPHP ^8.2

Since Nov 10Pushed 7mo agoCompare

[ Source](https://github.com/carlosupreme/cep-query-payment)[ Packagist](https://packagist.org/packages/carlosupreme/cep-query-payment)[ RSS](/packages/carlosupreme-cep-query-payment/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (7)Versions (3)Used By (0)

CEP Query Service
=================

[](#cep-query-service)

A PHP library for querying Banco de México's CEP (Comprobantes Electrónicos de Pago / Electronic Payment Receipts) system using Guzzle HTTP client.

Overview
--------

[](#overview)

This library provides a simple interface to query the SPEI payment system through Banco de México's CEP website. It uses Guzzle HTTP client to make direct API requests to the CEP system.

Features
--------

[](#features)

- ✅ Query payment status using tracking key or reference number
- ✅ Retrieve available bank options from CEP system
- ✅ Automatic form validation and data sanitization
- ✅ Lightweight HTTP-based approach (no browser required)
- ✅ Comprehensive error handling and logging
- ✅ Framework-agnostic with Laravel integration
- ✅ Date format normalization
- ✅ Bank code lookup by name

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Laravel 11.x or 12.x
- Guzzle HTTP client (installed automatically via composer)

Installation
------------

[](#installation)

### For Laravel Projects

[](#for-laravel-projects)

1. The package is available in composer. Run composer install:

```
composer require carlosupreme/cep-query-payment
```

2. The service provider is already registered via Laravel's package auto-discovery.
3. Run:

```
composer dump-autoload
```

Usage
-----

[](#usage)

### Basic Usage (Framework-Agnostic)

[](#basic-usage-framework-agnostic)

```
use Carlosupreme\CEPQueryPayment\CEPQueryService;

// Create service instance
$cepService = new CEPQueryService();

// Prepare form data
$formData = [
    'fecha' => '15-01-2024',           // Payment date (dd-mm-yyyy)
    'tipoCriterio' => 'T',             // 'T' for tracking key, 'R' for reference
    'criterio' => '1234567890',        // Tracking key or reference number
    'emisor' => '40012',               // Sender bank code
    'receptor' => '40002',             // Receiver bank code
    'cuenta' => '012345678901234567',  // Beneficiary CLABE (18 digits)
    'monto' => '1500.00',              // Amount
];

// Query payment
try {
    $result = $cepService->queryPayment($formData);

    if ($result !== null) {
        // Payment found
        print_r($result);
    } else {
        // Payment not found
        echo "Payment not found";
    }
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
```

### Laravel Usage

[](#laravel-usage)

```
use Carlosupreme\CEPQueryPayment\CEPQueryService;

class PaymentController extends Controller
{
    public function __construct(
        private CEPQueryService $cepService
    ) {}

    public function verifyPayment(Request $request)
    {
        $formData = [
            'fecha' => CEPQueryService::formatDate($request->payment_date),
            'tipoCriterio' => 'T',
            'criterio' => $request->tracking_key,
            'emisor' => $request->sender_bank,
            'receptor' => $request->receiver_bank,
            'cuenta' => $request->clabe,
            'monto' => $request->amount,
        ];

        $result = $this->cepService->queryPayment($formData);

        return response()->json([
            'found' => $result !== null,
            'data' => $result,
        ]);
    }
}
```

### Get Available Banks

[](#get-available-banks)

```
$banks = $cepService->getBankOptions();

// Returns array like:
// [
//     '40002' => 'BANAMEX',
//     '40012' => 'BBVA BANCOMER',
//     ...
// ]
```

### Bank Code Lookup

[](#bank-code-lookup)

```
// Find bank code by name (case-insensitive)
$bankCode = $cepService->getBankCodeByName('BBVA');
// Returns: '40012'
```

### Date Formatting

[](#date-formatting)

```
use Carlosupreme\CEPQueryPayment\CEPQueryService;

// From DateTime object
$date = new DateTime('2024-01-15');
$formatted = CEPQueryService::formatDate($date);
// Returns: '15-01-2024'

// From Y-m-d string
$formatted = CEPQueryService::formatDate('2024-01-15');
// Returns: '15-01-2024'

// From dd/mm/yyyy
$formatted = CEPQueryService::formatDate('15/01/2024');
// Returns: '15-01-2024'
```

### Custom Logger

[](#custom-logger)

```
use Carlosupreme\CEPQueryPayment\CEPQueryService;

$logger = function(string $level, string $message, array $context = []) {
    // Custom logging implementation
    error_log("[$level] $message " . json_encode($context));
};

$cepService = new CEPQueryService(null, $logger);
```

### Timeout Options

[](#timeout-options)

```
$options = [
    'timeout' => 60,  // 60 second timeout
];

$result = $cepService->queryPayment($formData, $options);
```

Form Data Structure
-------------------

[](#form-data-structure)

### Required Fields

[](#required-fields)

FieldTypeDescriptionExample`fecha`stringPayment date in dd-mm-yyyy format`'15-01-2024'``tipoCriterio`stringSearch criteria type: 'T' (tracking) or 'R' (reference)`'T'``criterio`stringTracking key (max 30) or reference (max 7)`'1234567890'``emisor`stringSender bank code (numeric)`'40012'``receptor`stringReceiver bank code (numeric)`'40002'``cuenta`stringBeneficiary CLABE account (18 digits)`'012345678901234567'``monto`stringPayment amount`'1500.00'`### Validation Rules

[](#validation-rules)

- **fecha**: Must be dd-mm-yyyy or dd/mm/yyyy format
- **tipoCriterio**: Must be 'T' or 'R'
- **criterio**: Max 30 chars for tracking key, max 7 for reference
- **emisor/receptor**: Must be numeric bank codes
- **cuenta**: Must be 18 digits for CLABE format
- **monto**: Must be numeric (commas allowed)

Response Format
---------------

[](#response-format)

### Successful Query (Payment Found)

[](#successful-query-payment-found)

```
[
    'type' => 'table',
    'headers' => ['Header1', 'Header2', ...],
    'rows' => [
        ['value1', 'value2', ...],
        ['value1', 'value2', ...],
    ]
]
```

### Payment Not Found

[](#payment-not-found)

```
[
    'type' => 'text',
    'content' => 'Operación no encontrada...',
    'html' => '...'
]
```

### No Result

[](#no-result)

```
null
```

Error Handling
--------------

[](#error-handling)

The library throws `Exception` for various error conditions:

```
try {
    $result = $cepService->queryPayment($formData);
} catch (Exception $e) {
    // Handle errors:
    // - Missing required fields
    // - Invalid data format
    // - HTTP request failures
    // - Timeout errors
    // - Invalid response format

    echo "Error: " . $e->getMessage();
}
```

Common exceptions:

- `Required field missing: {field}`
- `Invalid tipoCriterio. Must be 'T' or 'R'`
- `Invalid date format. Use dd-mm-yyyy or dd/mm/yyyy`
- `Invalid CLABE format. Must be 18 digits`
- `CEP HTTP request failed: {message}`

Configuration
-------------

[](#configuration)

### Timeout

[](#timeout)

Default timeout is 60 seconds.

### Custom HTTP Client

[](#custom-http-client)

You can provide a custom Guzzle HTTP client:

```
use GuzzleHttp\Client;
use Carlosupreme\CEPQueryPayment\CEPQueryService;

$httpClient = new Client([
    'timeout' => 120,
    'verify' => true,
]);

$cepService = new CEPQueryService($httpClient);
```

Security Considerations
-----------------------

[](#security-considerations)

- Form data is sanitized before logging (sensitive fields are masked)
- CLABE accounts show only last 4 digits in logs
- Tracking keys/references show only last 3 characters in logs
- Use environment variables for sensitive configuration
- Consider rate limiting to avoid overloading CEP system

Performance Tips
----------------

[](#performance-tips)

1. **Cache Bank Options**: Bank codes rarely change, cache them
2. **Adjust Timeouts**: Reduce for faster failures, increase for slow networks
3. **Queue Jobs**: For Laravel, use queues for CEP queries
4. **Error Monitoring**: Log failures for debugging

Troubleshooting
---------------

[](#troubleshooting)

### HTTP Request Fails

[](#http-request-fails)

- Check network connectivity
- Verify CEP website is accessible
- Consider server location (latency)
- Review logs for detailed error messages

### Timeout Errors

[](#timeout-errors)

- Increase timeout in options
- Check network connectivity
- Verify CEP website is accessible

### Invalid Response

[](#invalid-response)

- CEP website may have changed structure
- Verify form data is correct

### No Results Found

[](#no-results-found)

- Verify payment date is correct
- Check tracking key/reference number
- Ensure bank codes are correct
- Confirm CLABE account matches
- Payment may not exist in system

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
# Install dev dependencies
composer install --dev

# Run tests
./vendor/bin/pest
```

License
-------

[](#license)

MIT License - See LICENSE file for details

Support
-------

[](#support)

For issues, questions, or contributions, please feel free to open a GitHub issue.

Credits
-------

[](#credits)

Developed for Carlos Sosa.

Changelog
---------

[](#changelog)

### Version 1.0.0 (2025)

[](#version-100-2025)

- Initial release
- Support for payment queries
- Bank options retrieval
- Laravel integration
- Comprehensive validation

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance65

Regular maintenance activity

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~19 days

Total

2

Last Release

215d ago

Major Versions

v1.0.0 → v2.0.02025-11-30

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/78663955?v=4)[Carlos Sosa](/maintainers/carlosupreme)[@carlosupreme](https://github.com/carlosupreme)

---

Top Contributors

[![carlosupreme](https://avatars.githubusercontent.com/u/78663955?v=4)](https://github.com/carlosupreme "carlosupreme (8 commits)")[![gogl92](https://avatars.githubusercontent.com/u/1505641?v=4)](https://github.com/gogl92 "gogl92 (6 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (3 commits)")

---

Tags

laravelpaymentcepverificationscrapingmexicobanxicospei

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/carlosupreme-cep-query-payment/health.svg)

```
[![Health](https://phpackages.com/badges/carlosupreme-cep-query-payment/health.svg)](https://phpackages.com/packages/carlosupreme-cep-query-payment)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k95.4M305](/packages/laravel-horizon)[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[mollie/laravel-cashier-mollie

Laravel Cashier provides an expressive, fluent interface to Mollie's subscription billing services.

178204.3k1](/packages/mollie-laravel-cashier-mollie)[linkxtr/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

3720.4k](/packages/linkxtr-laravel-qrcode)[sebdesign/laravel-viva-payments

A Laravel package for integrating the Viva Payments gateway

4851.0k](/packages/sebdesign-laravel-viva-payments)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
