Skip to content

v1.3.0

Latest

Choose a tag to compare

@theihasan theihasan released this 23 Jun 17:16
· 1 commit to main since this release

Changelog - Laravel bKash Package

[v1.3.0] - 2025-06-23

🎉 Major Features

Multi-Tenant Support with Dynamic Cache

  • New forTenant() Method: Added tenant-aware functionality to the Ihasan\Bkash\Bkash.php class

    • Set tenant ID dynamically: Bkash::forTenant($tenantId)
    • Enables isolated token management per tenant in multi-tenant applications
  • Dynamic Cache Key Generation: Introduced getCacheKey(string $key) method

    • With Tenant: Creates cache key using tenant ID (e.g., tenant_{tenant_id}_key)
    • Without Tenant: Falls back to default bkash_token cache key
    • Ensures complete token isolation between tenants

🧪 Testing Infrastructure Overhaul

PHPUnit Integration

  • Migrated from Pest to PHPUnit: Complete testing framework transition
  • Comprehensive Token Management Tests:
    • Unit tests for single-tenant token operations
    • Unit tests for multi-tenant token isolation
    • Cache key generation validation

🔧 Technical Improvements

Enhanced Token Management

  • Tenant-Aware Caching: Each tenant maintains isolated token cache
  • Improved Cache Strategy: Smarter cache key generation prevents token conflicts
  • Backward Compatibility: Single-tenant applications continue to work without changes

📁 File Structure Changes

tests/
├── Unit/
│   ├── MultiTenantTest.php    
│   └── TokenTest.php     
└── phpunit.xml                     

🚀 Usage Examples

Multi-Tenant Usage

// Set tenant context
$payment = Bkash::forTenant('tenant_123')
    ->createPayment($paymentData);

// Each tenant gets isolated token cache
$tenant1Token = Bkash::forTenant('tenant_1')->getToken();
$tenant2Token = Bkash::forTenant('tenant_2')->getToken();

Single Tenant (Existing)

// Works exactly as before
$payment = Bkash::createPayment($paymentData);

🔄 Migration Guide

For Multi-Tenant Applications

  1. Start using tenant context:

    // Before (all tenants shared same token)
    Bkash::createPayment($data);
    
    // After (isolated per tenant)
    Bkash::forTenant($currentTenant->id)->createPayment($data);
  2. No configuration changes required - the system automatically handles cache isolation

For Single-Tenant Applications

  • No changes needed - existing code continues to work unchanged
  • The package automatically uses the default cache behavior

🧩 Internal Architecture

Cache Key Strategy

// Implementation details
protected function getCacheKey(string $key): string
{
    return $this->tenantId 
        ? "tenant_{$this->tenantId}_{$key}" 
        : 'bkash_token';
}

🧪 Testing Coverage

  • Token Management: Complete test coverage for token creation, retrieval, and caching
  • Multi-Tenant Isolation: Validates that tenants cannot access each other's tokens
  • Cache Key Generation: Ensures proper cache key formatting for different scenarios
  • Backward Compatibility: Confirms single-tenant functionality remains intact

📋 Dependencies

  • Removed: pestphp/pest and related Pest packages
  • Added: PHPUnit testing framework
  • Maintained: All existing runtime dependencies unchanged

⚠️ Breaking Changes

  • None for end users - This is a backward-compatible release
  • Development Only: Testing framework changed from Pest to PHPUnit

🔒 Security

  • Enhanced Isolation: Multi-tenant token isolation prevents cross-tenant token access
  • Cache Security: Tenant-specific cache keys eliminate token leakage between tenants

🏗️ Technical Benefits

  • Scalability: Better support for SaaS applications with multiple tenants
  • Performance: Efficient cache management per tenant
  • Maintainability: Comprehensive test suite with PHPUnit
  • Flexibility: Easy tenant switching within the same request cycle

Migration Impact: ✅ Zero Breaking Changes - Existing single-tenant applications continue to work without any modifications. Multi-tenant support is purely additive.