Installation
composer require lonban/vcc
Add to config/app.php under providers:
Lonban\Vcc\VccServiceProvider::class,
Publish Config
php artisan vendor:publish --provider="Lonban\Vcc\VccServiceProvider" --tag="config"
Edit config/vcc.php to set your API credentials (e.g., api_key, base_uri).
First Use Case Fetch a VCC (Virtual Credit Card) number:
use Lonban\Vcc\Facades\Vcc;
$vcc = Vcc::generate();
dd($vcc); // Returns an array with card details (number, expiry, etc.)
Lonban\Vcc\Facades\Vcc (primary entry point).config/vcc.php (API settings, retries, logging).Lonban\Vcc\Exceptions\VccException (handle API errors).Generating VCCs
// Basic generation
$vcc = Vcc::generate(['type' => 'visa', 'amount' => 1000]);
// Batch generation
$vccs = Vcc::generateBatch(5, ['type' => 'mastercard']);
Validating VCCs
$isValid = Vcc::validate($vccNumber);
if (!$isValid) throw new \InvalidArgumentException("Invalid VCC");
Integration with Payments Use the generated VCC in payment gateways (e.g., Stripe, PayPal) via their SDKs:
$paymentIntent = \Stripe\PaymentIntent::create([
'amount' => 1000,
'currency' => 'usd',
'payment_method' => [
'card' => [
'number' => $vcc['number'],
'exp_month' => $vcc['expiry_month'],
'exp_year' => $vcc['expiry_year'],
'cvc' => $vcc['cvc'],
],
],
]);
Testing Transactions Simulate transactions with test VCCs:
$testVcc = Vcc::generate(['is_test' => true]);
// Use $testVcc in sandbox environments.
config/vcc.php for transient failures.log_enabled in config to debug API calls.namespace App\Services;
use Lonban\Vcc\Facades\Vcc;
class PaymentService {
public function createTestPayment() {
$vcc = Vcc::generate(['type' => 'visa', 'is_test' => true]);
// Custom logic here...
}
}
API Rate Limits
config/vcc.php for max_retries and adjust accordingly.Sensitive Data Exposure
encrypt() or a dedicated secrets manager:
$encryptedCvc = encrypt($vcc['cvc']);
Deprecated Methods
composer.json:
"require": {
"lonban/vcc": "1.0.0"
}
No Built-in Mocking
$this->mock(Vcc::class)->shouldReceive('generate')->andReturn(['number' => '4242424242424242']);
log_enabled => true in config/vcc.php to see raw API responses.try {
$vcc = Vcc::generate();
} catch (\Lonban\Vcc\Exceptions\VccException $e) {
if ($e->getCode() === 429) {
// Handle rate limiting
}
}
Custom VCC Providers Override the default provider by binding a new implementation in a service provider:
$this->app->bind(\Lonban\Vcc\Contracts\VccProvider::class, \App\Providers\CustomVccProvider::class);
Event Listeners Listen for VCC generation events (if the package emits them):
// config/listeners.php
'vcc.generated' => [
\App\Listeners\LogVccGeneration::class,
];
API Response Transformation Extend the base response class to add custom fields:
namespace App\Extensions;
use Lonban\Vcc\Responses\VccResponse;
class ExtendedVccResponse extends VccResponse {
public function getFormattedNumber() {
return preg_replace('/(\d{4})(\d{4})(\d{4})(\d{4})/', '$1-$2-$3-$4', $this->number);
}
}
How can I help you explore Laravel packages today?