Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Dummy Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require omnipay/dummy
    

    Add the dummy gateway to your Laravel app via Omnipay’s service provider:

    Omnipay::setGateway('dummy');
    
  2. 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();
    
  3. Key Files

    • vendor/omnipay/dummy/src/Gateway.php (Core logic)
    • vendor/omnipay/dummy/tests/ (Test cases for reference)

Implementation Patterns

Workflow: Mocking Payments in Tests

  1. 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());
    }
    
  2. Integration with Laravel Bind the dummy gateway in config/services.php for test environments:

    'gateways' => [
        'dummy' => [
            'testMode' => env('OMNIPAY_DUMMY_TEST_MODE', true),
        ],
    ],
    
  3. Dynamic Responses Override default responses (success/failure) via config or runtime:

    $gateway->setTestResponse(true); // Force success
    // OR
    $gateway->setTestResponse(false); // Force failure
    

Common Patterns

  • Simulate 3D Secure: Use authorize() with testMode to mock redirect flows.
  • Refunds/Voids: Test reversal logic without real transactions:
    $gateway->capture(['amount' => '5.00'])->send();
    $gateway->refund(['transactionId' => 'dummy_trans_id'])->send();
    

Gotchas and Tips

Pitfalls

  1. Test Mode Requirement

    • Error: Test mode must be enabled if testMode is omitted.
    • Fix: Always set testMode: true in test environments.
  2. Transaction ID Handling

    • Dummy driver generates IDs like dummy_trans_id. Avoid hardcoding these in production logic.
    • Tip: Use getTransactionReference() to extract IDs dynamically:
      $transactionId = $response->getTransactionReference();
      
  3. Limited Features

    • No real webhooks or IPN support. Use for flow testing only.
    • Workaround: Mock webhook handlers separately.

Debugging Tips

  • Response Inspection: Dump raw responses to verify mock behavior:
    dd($response->getData());
    
  • Custom Responses: Extend the gateway for edge cases:
    $gateway->setTestResponse([
        'success' => false,
        'message' => 'Custom error: Insufficient funds',
    ]);
    

Extension Points

  1. 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);
        }
    }
    
  2. Laravel Service Provider Bind the custom gateway in AppServiceProvider:

    Omnipay::setGateway('custom_dummy', function() {
        return new CustomDummyGateway();
    });
    
  3. Configuration Quirks

    • Test Mode: Must be true for all operations (no partial test mode).
    • Currency: Defaults to USD. Override via setCurrency() if needed.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky