Skip to content

Commit ee946ab

Browse files
committed
Document Paystack terminal
1 parent de16b1b commit ee946ab

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ FLW_SECRET_HASH=hash-123xxxxxxxxxxxxxxxxxxx-X
9292

9393
```env
9494
PAYSTACK_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxxxxxxx
95+
PAYSTACK_TERMINAL_ID=xxxxxxxxxxxxxxxxxxxxx
9596
```
9697

98+
> The `PAYSTACK_TERMINAL_ID` is only required if you intend to use [Paystack Terminal](https://paystack.com/terminal/) for payment processing.
99+
97100
- Remita: Ensure to set the following environment variables:
98101

99102
```env
@@ -174,6 +177,105 @@ If you need webhook notifications from payment providers, use the webhook endpoi
174177

175178
If there are additional steps you want to take upon successful payment, listen for `SuccessfulLaravelMultipayPaymentEvent`. This event will be fired whenever a successful payment occurs, with its corresponding `Payment` model.
176179

180+
## Paystack Terminal
181+
182+
[Paystack Terminal](https://paystack.com/terminal/) allows you to process payments on physical payment terminals. This feature is useful for point-of-sale (POS) systems and retail environments.
183+
184+
### Prerequisites
185+
186+
1. Ensure you have `PAYSTACK_SECRET_KEY` configured in your `.env` file
187+
2. Obtain your Terminal ID from [Paystack Dashboard](https://dashboard.paystack.co/#/settings/terminals)
188+
3. Set the `PAYSTACK_TERMINAL_ID` in your `.env` file:
189+
190+
```env
191+
PAYSTACK_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxxxxxxx
192+
PAYSTACK_TERMINAL_ID=xxxxxxxxxxxxxxxxxxxxx
193+
```
194+
195+
Alternatively, you can set the Terminal ID dynamically in your session:
196+
197+
```php
198+
session(['multipay::paystack_terminal_id' => 'your_terminal_id']);
199+
```
200+
201+
### Usage
202+
203+
The Paystack Terminal functionality is provided via the `Terminal` class:
204+
205+
```php
206+
use Damms005\LaravelMultipay\Services\PaymentHandlers\PaystackTerminal\Terminal;
207+
208+
$terminal = app(Terminal::class);
209+
```
210+
211+
### Creating a Payment Request
212+
213+
Create a payment request that can be pushed to a terminal:
214+
215+
```php
216+
$payment = $terminal->createPaymentRequest(
217+
model: 'App\Models\User',
218+
modelId: 123,
219+
email: 'customer@example.com',
220+
description: 'Product purchase',
221+
amount: 50000 // Amount in kobo (50,000 kobo = 500 NGN)
222+
);
223+
```
224+
225+
This creates a payment record and returns a `Payment` model instance with the payment details stored in metadata.
226+
227+
### Checking Terminal Status
228+
229+
Verify that the terminal hardware is online and ready before pushing payments:
230+
231+
```php
232+
try {
233+
$status = $terminal->waitForTerminalHardware();
234+
// Terminal is online
235+
} catch (\Exception $e) {
236+
// Terminal is offline or not configured
237+
}
238+
```
239+
240+
### Pushing Payment to Terminal
241+
242+
Send a payment request to the terminal for processing:
243+
244+
```php
245+
try {
246+
$eventId = $terminal->pushToTerminal($payment);
247+
// Payment has been pushed to terminal
248+
} catch (\Exception $e) {
249+
// Failed to push to terminal
250+
}
251+
```
252+
253+
The returned `$eventId` can be used to track the payment request delivery status.
254+
255+
### Verifying Terminal Receipt
256+
257+
Confirm that the terminal received the payment request (within 48 hours of creation):
258+
259+
```php
260+
try {
261+
$result = $terminal->terminalReceivedPaymentRequest($eventId);
262+
// Terminal has received the payment request
263+
} catch (\Exception $e) {
264+
// Could not verify receipt
265+
}
266+
```
267+
268+
### Error Handling
269+
270+
The Terminal class throws `\Exception` on failures. Common scenarios include:
271+
272+
- Terminal ID not configured
273+
- Terminal hardware offline
274+
- Invalid payment request data
275+
- Network errors communicating with Paystack API
276+
277+
Always wrap Terminal method calls in try-catch blocks for proper error handling.
278+
177279
## Testing
178280

179281
```bash

0 commit comments

Comments
 (0)