PHPackages                             emmo00/mock-paystack-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. emmo00/mock-paystack-laravel

ActiveLibrary[Testing &amp; Quality](/categories/testing)

emmo00/mock-paystack-laravel
============================

PHP package for mocking Paystack responses and webhooks in your Laravel Test suite

v1.0.0(1y ago)4120MITPHPPHP ^8.2

Since Jan 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Emmo00/mock-paystack-laravel)[ Packagist](https://packagist.org/packages/emmo00/mock-paystack-laravel)[ Docs](https://github.com/emmo00/mock-paystack-laravel)[ RSS](/packages/emmo00-mock-paystack-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (2)Used By (0)

mock-paystack-laravel
=====================

[](#mock-paystack-laravel)

PHP package for mocking Paystack responses and webhooks.

Overview
--------

[](#overview)

MockPaystack is a Laravel package designed to simplify testing and development involving Paystack integrations. The MockPaystack package is a tool designed for developers to test and simulate interactions with Paystack APIs in a controlled environment. It provides utility classes, traits, and constants to handle various Paystack API operations, including webhooks, payment initialization, and response simulation.

This package includes utilities for handling HTTP requests and responses, and it offers support for both `Illuminate\Http\Client` (Laravel HTTP client) and `GuzzleHttp` clients, ensuring compatibility with a wide range of use cases.

---

Installation
------------

[](#installation)

### Prerequisites

[](#prerequisites)

- PHP 8.2 or higher
- Laravel 9.x or higher
- Composer

### Installation Steps

[](#installation-steps)

1. Add the package to your Laravel project using Composer:

    ```
    composer require --dev emmo00/mock-paystack-laravel
    ```
2. Use trait in test class

    ```
    use Emmo00\MockPaystack\MockPaystack;

    class TransactionControllerTest extends TestCase
    {
         use MockPaystack;
    }
    ```

---

Features
--------

[](#features)

- Simulate Paystack API responses
- Mock webhooks and payment interactions, such as successful payments, failed transactions, and more.
- Validate request payloads and headers
- Utilities to work seamlessly with `GuzzleHttp` and `Illuminate\Http\Client`.

---

### Example

[](#example)

Here's a basic example of using the MockPaystack package:

```
 use Emmo00\MockPaystack\MockPaystack;

class ExampleTest extends TestCase
{
    use MockPaystack;

    public function testInitializePayment()
    {
        $this->fakeInitializePayment(); // this catches any request made to the paystack api and returns a mock response

        // make request to endpoint that calls paystack
        $response = $this->get(route('subscriptions.pay'));

        // Assert
        $response->assertStatus(200);
        $response->assertJsonStructure([
            'message',
            'data' => [
                'authorization_url',
            ],
        ]);
    }
}
```

Usage
-----

[](#usage)

### Trait: `MockPaystack`

[](#trait-mockpaystack)

This trait provides utility methods for handling HTTP requests, responses and webhook.

### Initialize Payment Handler

[](#initialize-payment-handler)

methods to simulate and validate Paystack payment initialization requests.

#### Methods

[](#methods)

##### `fakeInitializePayment()`

[](#fakeinitializepayment)

**Description**: Simulates an initialize payment request, ensuring required properties like `email`, `amount`, `currency`, and `Authorization` header are present.

**Usage:**

```
$this->fakeInitializePayment();
```

---

##### `fakeInitializePaymentSuccess()`

[](#fakeinitializepaymentsuccess)

**Description**: Simulates a successful initialize payment request.

**Usage:**

```
$this->fakeInitializePaymentSuccess();
```

---

##### `fakeInitializePaymentFailure()`

[](#fakeinitializepaymentfailure)

**Description**: Simulates a failed initialize payment request.

**Usage:**

```
$this->fakeInitializePaymentFailure();
```

---

##### `fakeInitializePaymentInvalidKey()`

[](#fakeinitializepaymentinvalidkey)

**Description**: Simulates a request with an invalid Authorization key.

**Usage:**

```
$this->fakeInitializePaymentInvalidKey();
```

---

##### `fakeInitializePaymentInvalidRequest()`

[](#fakeinitializepaymentinvalidrequest)

**Description**: Simulates a request with invalid payload or headers.

**Usage:**

```
$this->fakeInitializePaymentInvalidRequest();
```

---

##### `fakeInitializePaymentInvalidCurrency()`

[](#fakeinitializepaymentinvalidcurrency)

**Description**: Simulates a request with an unsupported or missing currency field.

**Usage:**

```
$this->fakeInitializePaymentInvalidCurrency();
```

---

##### `fakeInitializePaymentInvalidAmount()`

[](#fakeinitializepaymentinvalidamount)

**Description**: Simulates a request with an invalid or missing amount field.

**Usage:**

```
$this->fakeInitializePaymentInvalidAmount();
```

---

##### `fakeInitializePaymentInvalidEmail()`

[](#fakeinitializepaymentinvalidemail)

**Description**: Simulates a request with an invalid or missing email field.

**Usage:**

```
$this->fakeInitializePaymentInvalidEmail();
```

---

### Charge Success Webhook Handler

[](#charge-success-webhook-handler)

`MockPaystack` also provides methods to simulate Paystack webhook notifications, like for the `charge.success` event.

#### `fakeWebHookChargeSuccess()`

[](#fakewebhookchargesuccess)

**Description**: Sends a fake webhook `charge.success` notification to your Paystack webhook handler route.

**Parameters:**

- `string $route`: The webhook handler route.
- `string $secret_key`: The secret key for webhook validation.
- `array $metadata`: Additional metadata for the webhook.
- `int $amount`: Transaction amount (default: 10000).
- `string $currency`: Transaction currency (default: 'NGN').
- `string $reference`: Transaction reference (default: 'reference').
- `string $channel`: Payment channel (default: 'card').
- `string $ip_address`: IP address of the transaction source (default: '0.0.0.0').
- `array $customer`: Customer details.
- `array $authorization`: Authorization details.
- `bool $reusable_authorization`: Indicates if the authorization is reusable (default: true).

**Returns:**`\Illuminate\Testing\TestResponse`: The response from your webhook handler route.

**Usage:**

```
$response = $this->fakeWebHookChargeSuccess(
    '/webhook-route',
    'your-secret-key',
    ['custom-key' => 'custom-value'],
    5000,
    'USD',
    'unique-reference',
    'bank',
    '192.168.1.1',
    ['email' => 'test@example.com'],
    ['card' => 'visa'],
    false
);

$response->assertStatus(200);
```

---

---

Contributing
------------

[](#contributing)

1. Fork the repository.
2. Create a new branch for your feature or bug fix:

    ```
    git checkout -b feature/my-new-feature
    ```
3. Commit your changes:

    ```
    git commit -m "Add some feature"
    ```
4. Push to the branch:

    ```
    git push origin feature/my-new-feature
    ```
5. Open a pull request.

---

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](LICENSE).

---

Contact
-------

[](#contact)

For questions or support, please reach out to [Emmanuel Nwafor](https://github.com/Emmo00).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance42

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

490d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ebf221c44e7519c7d036969b7f67cce0337a14dc1799d5f362c7ca61c3c3a24?d=identicon)[emmo00](/maintainers/emmo00)

---

Top Contributors

[![Emmo00](https://avatars.githubusercontent.com/u/88244468?v=4)](https://github.com/Emmo00 "Emmo00 (21 commits)")

---

Tags

composerlaravelmockpaystackphptesttestinglaravelmockpaystack

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/emmo00-mock-paystack-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/emmo00-mock-paystack-laravel/health.svg)](https://phpackages.com/packages/emmo00-mock-paystack-laravel)
```

###  Alternatives

[blastcloud/guzzler

Supercharge your app or SDK with a testing library specifically for Guzzle.

272419.3k35](/packages/blastcloud-guzzler)[sti3bas/laravel-scout-array-driver

Array driver for Laravel Scout

971.5M3](/packages/sti3bas-laravel-scout-array-driver)[code-distortion/adapt

A Laravel package that builds databases for your tests, improving their speed.

2835.5k](/packages/code-distortion-adapt)[aeris/guzzle-http-mock

A mock library for verifying requests made with the Guzzle Http Client, and mocking responses.

2613.1k1](/packages/aeris-guzzle-http-mock)[lastzero/test-tools

Increases testing productivity by adding a service container and self-initializing fakes to PHPUnit

2244.3k13](/packages/lastzero-test-tools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
