sudipta/vrio

Laravel package for Vrio CRM integration

Maintainers

Details

github.com/sudipt0/vrio

Source

Issues

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

pkg:composer/sudipta/vrio

1.0.6 2025-10-27 07:28 UTC

This package is auto-updated.

Last update: 2025-10-27 07:29:46 UTC


README

A Laravel package to seamlessly interact with the Vrio CRM API, allowing you to manage customers, orders, payment cards, and more โ€” directly from your Laravel application.

Supports Laravel 10, 11, and 12.

๐Ÿš€ Features

  • โœ… Create and retrieve customers
  • ๐Ÿ’ณ Add and list payment cards
  • ๐Ÿงพ Create and retrieve orders
  • ๐Ÿ“ฆ Manage products and inventory
  • ๐Ÿ”„ Handle subscriptions and recurring billing
  • โš™๏ธ Graceful error handling with structured responses
  • ๐Ÿงฑ Provides Facade and dependency injection support
  • ๐Ÿ” Automatically injects API credentials from configuration
  • ๐Ÿงฐ Easy configuration publishing and environment setup
  • ๐Ÿงช Comprehensive test suite with API mocking

๐Ÿ“ฆ Installation Guide

1. Add the Package to Your Project

If you are developing locally and have the package inside packages/sudipta/vrio, add this to your root composer.json file:

{
    "repositories": [
        {
            "type": "path",
            "url": "./packages/sudipta/vrio"
        }
    ]
}

Then require the package:

composer require "sudipta/vrio:dev-main"

๐Ÿ’ก If the package is published on Packagist, you can simply run:

composer require sudipta/vrio

2. Publish the Configuration File

After installation, publish the package configuration file using the Artisan command:

php artisan vendor:publish --tag=vrio-config

This will create a configuration file at:

config/vrio.php

3. Configure Environment Variables

Add your Vrio CRM API credentials to your .env file:

VRIO_BASE_URL=https://api.vrio.app
VRIO_API_KEY=your_api_key_here
VRIO_API_SECRET=your_api_secret_here

๐Ÿง  You can find your API credentials inside your Vrio CRM dashboard.

4. Verify Configuration

Check the generated config/vrio.php file to ensure proper setup:

return [
    'base_url' => env('VRIO_BASE_URL', 'https://api.vrio.app'),
    'api_key' => env('VRIO_API_KEY'),
    'api_secret' => env('VRIO_API_SECRET'),
    
    // Optional: Default timeout for API requests (seconds)
    'timeout' => env('VRIO_TIMEOUT', 30),
    
    // Optional: Enable/disable debug mode
    'debug' => env('VRIO_DEBUG', false),
];

๐Ÿง  Usage Examples

Using the Facade

<?php

namespace App\Http\Controllers;

use Sudipta\Vrio\Facades\Vrio;
use Illuminate\Http\Request;

class CustomerController extends Controller
{
    public function createCustomer(Request $request)
    {
        $response = Vrio::createCustomer([
            'name' => 'John Doe',
            'email' => 'john@example.com',
            'phone' => '+1234567890',
            'address' => [
                'line1' => '123 Main St',
                'city' => 'New York',
                'state' => 'NY',
                'postal_code' => '10001',
                'country' => 'US'
            ]
        ]);

        if ($response['success']) {
            return response()->json($response['data'], 201);
        }

        return response()->json([
            'error' => $response['message']
        ], $response['status_code']);
    }

    public function getCustomer($customerId)
    {
        $customer = Vrio::getCustomer($customerId);
        return response()->json($customer);
    }
}

Using Dependency Injection

<?php

namespace App\Http\Controllers;

use Sudipta\Vrio\Vrio;
use Illuminate\Http\Request;

class OrderController extends Controller
{
    protected $vrio;

    public function __construct(Vrio $vrio)
    {
        $this->vrio = $vrio;
    }

    public function createOrder(Request $request)
    {
        $order = $this->vrio->createOrder([
            'customer_id' => $request->customer_id,
            'amount' => $request->amount,
            'currency' => $request->currency ?? 'USD',
            'items' => $request->items,
            'metadata' => $request->metadata ?? []
        ]);

        return response()->json($order);
    }

    public function getOrder($orderId)
    {
        $order = $this->vrio->getOrder($orderId);
        return response()->json($order);
    }
}

Handling Payment Cards

<?php

namespace App\Http\Controllers;

use Sudipta\Vrio\Facades\Vrio;

class PaymentController extends Controller
{
    public function addCard(Request $request)
    {
        $response = Vrio::addCard([
            'customer_id' => $request->customer_id,
            'token' => $request->token, // Payment token from your frontend
            'is_default' => $request->is_default ?? false
        ]);

        if ($response['success']) {
            return response()->json([
                'message' => 'Card added successfully',
                'card' => $response['data']
            ]);
        }

        return response()->json([
            'error' => $response['message']
        ], 400);
    }

    public function listCards($customerId)
    {
        $response = Vrio::listCards($customerId);
        return response()->json($response);
    }
}

Managing Products

<?php

namespace App\Http\Controllers;

use Sudipta\Vrio\Facades\Vrio;

class ProductController extends Controller
{
    public function createProduct(Request $request)
    {
        $response = Vrio::createProduct([
            'name' => $request->name,
            'description' => $request->description,
            'price' => $request->price,
            'currency' => $request->currency ?? 'USD',
            'sku' => $request->sku,
            'inventory' => $request->inventory ?? 0,
            'metadata' => $request->metadata ?? []
        ]);

        return response()->json($response);
    }

    public function getProducts()
    {
        $response = Vrio::getProducts([
            'page' => request('page', 1),
            'limit' => request('limit', 20)
        ]);

        return response()->json($response);
    }
}

โš ๏ธ Error Handling

All API responses are returned in a structured format:

Success Example:

[
    'success' => true,
    'data' => [
        'id' => 'cust_123456',
        'name' => 'John Doe',
        'email' => 'john@example.com',
        // ... other customer data
    ],
    'message' => 'Customer created successfully',
    'status_code' => 200
]

Error Example:

[
    'success' => false,
    'message' => 'Invalid API credentials',
    'status_code' => 401,
    'errors' => [
        'auth' => 'API key is invalid'
    ]
]

Handling Errors in Your Application

<?php

try {
    $response = Vrio::createCustomer($data);
    
    if (!$response['success']) {
        // Handle API error
        Log::error('Vrio API Error: ' . $response['message']);
        return back()->withError($response['message']);
    }
    
    // Process successful response
    $customer = $response['data'];
    
} catch (\Exception $e) {
    // Handle network or unexpected errors
    Log::error('Vrio Service Exception: ' . $e->getMessage());
    return back()->withError('Service temporarily unavailable');
}

๐Ÿงฉ Available Methods

Customer Management

Vrio::createCustomer(array $data)
Vrio::getCustomer(string $customerId)
Vrio::updateCustomer(string $customerId, array $data)
Vrio::listCustomers(array $params = [])
Vrio::searchCustomers(array $criteria)

Order Management

Vrio::createOrder(array $data)
Vrio::getOrder(string $orderId)
Vrio::updateOrder(string $orderId, array $data)
Vrio::listOrders(array $params = [])
Vrio::cancelOrder(string $orderId)

Payment Card Management

Vrio::addCard(array $data)
Vrio::getCard(string $customerId, string $cardId)
Vrio::listCards(string $customerId)
Vrio::updateCard(string $customerId, string $cardId, array $data)
Vrio::deleteCard(string $customerId, string $cardId)

Product Management

Vrio::createProduct(array $data)
Vrio::getProduct(string $productId)
Vrio::updateProduct(string $productId, array $data)
Vrio::listProducts(array $params = [])
Vrio::deleteProduct(string $productId)

Subscription Management

Vrio::createSubscription(array $data)
Vrio::getSubscription(string $subscriptionId)
Vrio::updateSubscription(string $subscriptionId, array $data)
Vrio::cancelSubscription(string $subscriptionId)
Vrio::listSubscriptions(array $params = [])

๐Ÿงช Testing

1. Install Testing Dependencies

Make sure you have PHPUnit installed in your Laravel application:

composer require --dev phpunit/phpunit

2. Create Test Configuration

Create a test case for the Vrio package:

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Sudipta\Vrio\Facades\Vrio;
use Illuminate\Support\Facades\Http;

class VrioServiceTest extends TestCase
{
    protected function setUp(): void
    {
        parent::setUp();
        
        // Mock API responses for testing
        Http::fake([
            'api.vrio.app/*' => Http::response([
                'success' => true,
                'data' => [
                    'id' => 'cust_test123',
                    'name' => 'Test Customer',
                    'email' => 'test@example.com'
                ],
                'message' => 'Customer created successfully',
                'status_code' => 200
            ], 200)
        ]);
    }

    public function test_customer_creation()
    {
        $response = Vrio::createCustomer([
            'name' => 'Test Customer',
            'email' => 'test@example.com'
        ]);

        $this->assertTrue($response['success']);
        $this->assertEquals('cust_test123', $response['data']['id']);
        $this->assertEquals('Customer created successfully', $response['message']);
    }

    public function test_invalid_credentials_handling()
    {
        Http::fake([
            'api.vrio.app/*' => Http::response([
                'success' => false,
                'message' => 'Invalid API credentials',
                'status_code' => 401
            ], 401)
        ]);

        $response = Vrio::getCustomer('invalid_id');

        $this->assertFalse($response['success']);
        $this->assertEquals(401, $response['status_code']);
    }
}

3. Run Tests

./vendor/bin/phpunit tests/Feature/VrioServiceTest.php

4. Environment Testing

For local development, you can use the Vrio sandbox environment:

VRIO_BASE_URL=https://sandbox-api.vrio.app
VRIO_API_KEY=your_sandbox_api_key
VRIO_API_SECRET=your_sandbox_api_secret

๐Ÿ› ๏ธ Development Tips

Auto-loading During Development

If you're actively developing the package:

# Update Composer autoload mappings
composer dump-autoload

# Re-publish configuration file if you make changes
php artisan vendor:publish --tag=vrio-config --force

Testing with Laravel Tinker

php artisan tinker

>>> Vrio::getCustomers();
>>> Vrio::createCustomer(['name' => 'Test', 'email' => 'test@example.com']);

Debug Mode

Enable debug mode for detailed logging:

VRIO_DEBUG=true

Then check your Laravel logs:

Log::channel('stack')->debug('Vrio API Request:', $requestData);
Log::channel('stack')->debug('Vrio API Response:', $responseData);

๐Ÿงฑ Folder Structure

Here's the complete package structure:

packages/
โ””โ”€โ”€ sudipta/
    โ””โ”€โ”€ vrio/
        โ”œโ”€โ”€ src/
        โ”‚   โ”œโ”€โ”€ VrioServiceProvider.php
        โ”‚   โ”œโ”€โ”€ Facades/
        โ”‚   โ”‚   โ””โ”€โ”€ Vrio.php
        โ”‚   โ”œโ”€โ”€ Vrio.php
        โ”‚   โ”œโ”€โ”€ Contracts/
        โ”‚   โ”‚   โ””โ”€โ”€ VrioInterface.php
        โ”‚   โ”œโ”€โ”€ Exceptions/
        โ”‚   โ”‚   โ”œโ”€โ”€ VrioException.php
        โ”‚   โ”‚   โ”œโ”€โ”€ AuthenticationException.php
        โ”‚   โ”‚   โ””โ”€โ”€ ValidationException.php
        โ”‚   โ””โ”€โ”€ Http/
        โ”‚       โ””โ”€โ”€ Responses/
        โ”‚           โ”œโ”€โ”€ ApiResponse.php
        โ”‚           โ””โ”€โ”€ ErrorResponse.php
        โ”œโ”€โ”€ config/
        โ”‚   โ””โ”€โ”€ vrio.php
        โ”œโ”€โ”€ tests/
        โ”‚   โ”œโ”€โ”€ Feature/
        โ”‚   โ”‚   โ””โ”€โ”€ VrioServiceTest.php
        โ”‚   โ””โ”€โ”€ Unit/
        โ”‚       โ””โ”€โ”€ VrioTest.php
        โ”œโ”€โ”€ composer.json
        โ”œโ”€โ”€ LICENSE.md
        โ””โ”€โ”€ README.md

๐Ÿ”ง Advanced Configuration

Custom HTTP Client

You can extend the package with custom HTTP client configuration:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Sudipta\Vrio\Vrio;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->bind(Vrio::class, function ($app) {
            return new Vrio([
                'base_url' => config('vrio.base_url'),
                'api_key' => config('vrio.api_key'),
                'api_secret' => config('vrio.api_secret'),
                'timeout' => config('vrio.timeout', 30),
                'retry' => [
                    'times' => 3,
                    'sleep' => 100,
                ]
            ]);
        });
    }
}

Event Listeners

Listen to Vrio API events:

<?php

namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Sudipta\Vrio\Events\VrioApiCalled;
use App\Listeners\LogVrioApiCall;

class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
        VrioApiCalled::class => [
            LogVrioApiCall::class,
        ],
    ];
}

๐Ÿค Contributing

We welcome contributions to make this package better! Here's how you can help:

1. Fork the Repository

2. Create Your Feature Branch

git checkout -b feature/amazing-feature

3. Commit Your Changes

git commit -m 'Add some amazing feature'

4. Push to the Branch

git push origin feature/amazing-feature

5. Open a Pull Request

Development Setup

# Clone your fork
git clone https://github.com/your-username/vrio-laravel.git

# Install dependencies
composer install

# Run tests
./vendor/bin/phpunit

# Check code style
./vendor/bin/phpcs

Coding Standards

  • Follow PSR-12 coding standards
  • Write tests for new features
  • Update documentation
  • Add type hints where possible

๐Ÿ› Troubleshooting

Common Issues

  1. API Credentials Not Working

    • Verify your API key and secret in the Vrio dashboard
    • Check that environment variables are loaded properly
    • Ensure there are no trailing spaces in your .env file
  2. SSL Certificate Issues

    // In config/vrio.php for development
    'verify_ssl' => env('VRIO_VERIFY_SSL', true),
  3. Timeout Errors

    VRIO_TIMEOUT=60

Getting Help

๐Ÿ”„ Changelog

v1.0.0

  • Initial release
  • Customer management
  • Order processing
  • Payment card handling
  • Product catalog management

๐Ÿชช License

This package is open-source and available under the MIT License. See LICENSE.md for more information.

๐Ÿ“ž Support

Made with โค๏ธ for Laravel developers by Sudipta

โญ If this package helped you, please consider giving it a star on GitHub!