omnipay/dummy
Omnipay Dummy gateway for testing: simulates successful and failed payments without talking to real processors. Useful for local development, demos, and automated tests with predictable request/response behavior, supporting common Omnipay purchase flows.
Installation
composer require omnipay/dummy
Add the dummy gateway to your Laravel app via Omnipay’s service provider:
Omnipay::setGateway('dummy');
First Use Case: Testing Payment Flows Use the dummy driver to simulate successful/failed transactions without hitting real gateways:
$gateway = Omnipay::create('dummy');
$response = $gateway->purchase([
'amount' => '10.00',
'currency' => 'USD',
'testMode' => true, // Required for dummy driver
])->send();
Key Files
vendor/omnipay/dummy/src/Gateway.php (Core logic)vendor/omnipay/dummy/tests/ (Test cases for reference)Unit Testing Replace real gateways in tests with the dummy driver:
public function testPurchase()
{
$gateway = Omnipay::create('dummy');
$gateway->setTestMode(true);
$response = $gateway->purchase(['amount' => '5.00'])->send();
$this->assertTrue($response->isSuccessful());
}
Integration with Laravel
Bind the dummy gateway in config/services.php for test environments:
'gateways' => [
'dummy' => [
'testMode' => env('OMNIPAY_DUMMY_TEST_MODE', true),
],
],
Dynamic Responses Override default responses (success/failure) via config or runtime:
$gateway->setTestResponse(true); // Force success
// OR
$gateway->setTestResponse(false); // Force failure
authorize() with testMode to mock redirect flows.$gateway->capture(['amount' => '5.00'])->send();
$gateway->refund(['transactionId' => 'dummy_trans_id'])->send();
Test Mode Requirement
Test mode must be enabled if testMode is omitted.testMode: true in test environments.Transaction ID Handling
dummy_trans_id. Avoid hardcoding these in production logic.getTransactionReference() to extract IDs dynamically:
$transactionId = $response->getTransactionReference();
Limited Features
dd($response->getData());
$gateway->setTestResponse([
'success' => false,
'message' => 'Custom error: Insufficient funds',
]);
Custom Test Responses Override the gateway class to inject logic:
class CustomDummyGateway extends \Omnipay\Dummy\Gateway {
public function sendData($data) {
if ($data['amount'] > 100) {
return $this->createResponse(false, ['message' => 'Amount too high']);
}
return parent::sendData($data);
}
}
Laravel Service Provider
Bind the custom gateway in AppServiceProvider:
Omnipay::setGateway('custom_dummy', function() {
return new CustomDummyGateway();
});
Configuration Quirks
true for all operations (no partial test mode).USD. Override via setCurrency() if needed.How can I help you explore Laravel packages today?