Download the PHP package emmo00/mock-paystack-laravel without Composer
On this page you can find all versions of the php package emmo00/mock-paystack-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mock-paystack-laravel
mock-paystack-laravel
PHP package for mocking Paystack responses and webhooks.
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
Prerequisites
- PHP 8.2 or higher
- Laravel 9.x or higher
- Composer
Installation Steps
-
Add the package to your Laravel project using Composer:
- Use trait in test class
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
andIlluminate\Http\Client
.
Example
Here's a basic example of using the MockPaystack package:
Usage
Trait: MockPaystack
This trait provides utility methods for handling HTTP requests, responses and webhook.
Initialize Payment Handler
methods to simulate and validate Paystack payment initialization requests.
Methods
fakeInitializePayment()
Description: Simulates an initialize payment request, ensuring required properties like email
, amount
, currency
, and Authorization
header are present.
Usage:
fakeInitializePaymentSuccess()
Description: Simulates a successful initialize payment request.
Usage:
fakeInitializePaymentFailure()
Description: Simulates a failed initialize payment request.
Usage:
fakeInitializePaymentInvalidKey()
Description: Simulates a request with an invalid Authorization key.
Usage:
fakeInitializePaymentInvalidRequest()
Description: Simulates a request with invalid payload or headers.
Usage:
fakeInitializePaymentInvalidCurrency()
Description: Simulates a request with an unsupported or missing currency field.
Usage:
fakeInitializePaymentInvalidAmount()
Description: Simulates a request with an invalid or missing amount field.
Usage:
fakeInitializePaymentInvalidEmail()
Description: Simulates a request with an invalid or missing email field.
Usage:
Charge Success Webhook Handler
MockPaystack
also provides methods to simulate Paystack webhook notifications, like for the charge.success
event.
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:
Contributing
- Fork the repository.
-
Create a new branch for your feature or bug fix:
-
Commit your changes:
-
Push to the branch:
- Open a pull request.
License
This package is open-source software licensed under the MIT license.
Contact
For questions or support, please reach out to Emmanuel Nwafor.
All versions of mock-paystack-laravel with dependencies
guzzlehttp/guzzle Version ^7.0
guzzlehttp/psr7 Version ^2.0
illuminate/http Version ^11.36