{"id":23898875,"url":"https://github.com/emmo00/mock-paystack-laravel","last_synced_at":"2025-04-15T09:34:08.421Z","repository":{"id":270673704,"uuid":"893544163","full_name":"Emmo00/mock-paystack-laravel","owner":"Emmo00","description":"PHP package for mocking Paystack responses and webhooks in your Laravel Test Suite","archived":false,"fork":false,"pushed_at":"2025-01-04T17:15:51.000Z","size":164,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-04T22:16:30.062Z","etag":null,"topics":["composer","laravel","mock","paystack","php","test"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/emmo00/mock-paystack-laravel","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Emmo00.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-24T18:01:28.000Z","updated_at":"2025-01-05T19:41:36.000Z","dependencies_parsed_at":"2025-01-03T07:31:33.321Z","dependency_job_id":null,"html_url":"https://github.com/Emmo00/mock-paystack-laravel","commit_stats":null,"previous_names":["emmo00/mock-paystack","emmo00/mock-paystack-laravel"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emmo00%2Fmock-paystack-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emmo00%2Fmock-paystack-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emmo00%2Fmock-paystack-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Emmo00%2Fmock-paystack-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Emmo00","download_url":"https://codeload.github.com/Emmo00/mock-paystack-laravel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240288513,"owners_count":19777673,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","laravel","mock","paystack","php","test"],"created_at":"2025-01-04T18:14:09.941Z","updated_at":"2025-02-23T08:23:42.899Z","avatar_url":"https://github.com/Emmo00.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mock-paystack-laravel\n\nPHP package for mocking Paystack responses and webhooks.\n\n## Overview\n\nMockPaystack 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.\n\nThis 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.\n\n---\n\n## Installation\n\n### Prerequisites\n\n- PHP 8.2 or higher\n- Laravel 9.x or higher\n- Composer\n\n### Installation Steps\n\n1. Add the package to your Laravel project using Composer:\n\n   ```bash\n   composer require --dev emmo00/mock-paystack-laravel\n   ```\n\n2. Use trait in test class\n\n   ```php\n   use Emmo00\\MockPaystack\\MockPaystack;\n\n   class TransactionControllerTest extends TestCase \n   {\n        use MockPaystack;\n   }\n   ```\n\n---\n\n## Features\n\n- Simulate Paystack API responses\n- Mock webhooks and payment interactions, such as successful payments, failed transactions, and more.\n- Validate request payloads and headers\n- Utilities to work seamlessly with `GuzzleHttp` and `Illuminate\\Http\\Client`.\n\n---\n\n### Example\n\nHere's a basic example of using the MockPaystack package:\n\n```php\n use Emmo00\\MockPaystack\\MockPaystack;\n\nclass ExampleTest extends TestCase\n{\n    use MockPaystack;\n\n    public function testInitializePayment()\n    {\n        $this-\u003efakeInitializePayment(); // this catches any request made to the paystack api and returns a mock response\n\n        // make request to endpoint that calls paystack\n        $response = $this-\u003eget(route('subscriptions.pay'));\n\n\n        // Assert\n        $response-\u003eassertStatus(200);\n        $response-\u003eassertJsonStructure([\n            'message',\n            'data' =\u003e [\n                'authorization_url',\n            ],\n        ]);\n    }\n}\n```\n\n## Usage\n\n### Trait: `MockPaystack`\n\nThis trait provides utility methods for handling HTTP requests, responses and webhook.\n\n### Initialize Payment Handler\n\nmethods to simulate and validate Paystack payment initialization requests.\n\n#### Methods\n\n##### `fakeInitializePayment()`\n\n**Description**: Simulates an initialize payment request, ensuring required properties like `email`, `amount`, `currency`, and `Authorization` header are present.\n\n**Usage:**\n\n```php\n$this-\u003efakeInitializePayment();\n```\n\n---\n\n##### `fakeInitializePaymentSuccess()`\n\n**Description**: Simulates a successful initialize payment request.\n\n**Usage:**\n\n```php\n$this-\u003efakeInitializePaymentSuccess();\n```\n\n---\n\n##### `fakeInitializePaymentFailure()`\n\n**Description**: Simulates a failed initialize payment request.\n\n**Usage:**\n\n```php\n$this-\u003efakeInitializePaymentFailure();\n```\n\n---\n\n##### `fakeInitializePaymentInvalidKey()`\n\n**Description**: Simulates a request with an invalid Authorization key.\n\n**Usage:**\n\n```php\n$this-\u003efakeInitializePaymentInvalidKey();\n```\n\n---\n\n##### `fakeInitializePaymentInvalidRequest()`\n\n**Description**: Simulates a request with invalid payload or headers.\n\n**Usage:**\n\n```php\n$this-\u003efakeInitializePaymentInvalidRequest();\n```\n\n---\n\n##### `fakeInitializePaymentInvalidCurrency()`\n\n**Description**: Simulates a request with an unsupported or missing currency field.\n\n**Usage:**\n\n```php\n$this-\u003efakeInitializePaymentInvalidCurrency();\n```\n\n---\n\n##### `fakeInitializePaymentInvalidAmount()`\n\n**Description**: Simulates a request with an invalid or missing amount field.\n\n**Usage:**\n\n```php\n$this-\u003efakeInitializePaymentInvalidAmount();\n```\n\n---\n\n##### `fakeInitializePaymentInvalidEmail()`\n\n**Description**: Simulates a request with an invalid or missing email field.\n\n**Usage:**\n\n```php\n$this-\u003efakeInitializePaymentInvalidEmail();\n```\n\n---\n\n### Charge Success Webhook Handler\n\n`MockPaystack` also provides methods to simulate Paystack webhook notifications, like for the `charge.success` event.\n\n#### `fakeWebHookChargeSuccess()`\n\n**Description**: Sends a fake webhook `charge.success` notification to your Paystack webhook handler route.\n\n**Parameters:**\n\n- `string $route`: The webhook handler route.\n- `string $secret_key`: The secret key for webhook validation.\n- `array $metadata`: Additional metadata for the webhook.\n- `int $amount`: Transaction amount (default: 10000).\n- `string $currency`: Transaction currency (default: 'NGN').\n- `string $reference`: Transaction reference (default: 'reference').\n- `string $channel`: Payment channel (default: 'card').\n- `string $ip_address`: IP address of the transaction source (default: '0.0.0.0').\n- `array $customer`: Customer details.\n- `array $authorization`: Authorization details.\n- `bool $reusable_authorization`: Indicates if the authorization is reusable (default: true).\n\n**Returns:**\n`\\Illuminate\\Testing\\TestResponse`: The response from your webhook handler route.\n\n**Usage:**\n\n```php\n$response = $this-\u003efakeWebHookChargeSuccess(\n    '/webhook-route',\n    'your-secret-key',\n    ['custom-key' =\u003e 'custom-value'],\n    5000,\n    'USD',\n    'unique-reference',\n    'bank',\n    '192.168.1.1',\n    ['email' =\u003e 'test@example.com'],\n    ['card' =\u003e 'visa'],\n    false\n);\n\n$response-\u003eassertStatus(200);\n```\n\n---\n---\n\n## Contributing\n\n1. Fork the repository.\n2. Create a new branch for your feature or bug fix:\n\n   ```bash\n   git checkout -b feature/my-new-feature\n   ```\n\n3. Commit your changes:\n\n   ```bash\n   git commit -m \"Add some feature\"\n   ```\n\n4. Push to the branch:\n\n   ```bash\n   git push origin feature/my-new-feature\n   ```\n\n5. Open a pull request.\n\n---\n\n## License\n\nThis package is open-source software licensed under the [MIT license](LICENSE).\n\n---\n\n## Contact\n\nFor questions or support, please reach out to [Emmanuel Nwafor](https://github.com/Emmo00).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmo00%2Fmock-paystack-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femmo00%2Fmock-paystack-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmo00%2Fmock-paystack-laravel/lists"}