daniil-trukhan/api_platform_payze
Installation
composer require daniil-trukhan/api_platform_payze
Ensure your project uses API Platform (api/platform-core).
Configure Payze API Key
Add your Payze API key to .env:
PAYZE_API_KEY=your_api_key_here
Basic Usage
Inject the PayzeService into a controller or command:
use DaniilTrukhan\ApiPlatformPayze\PayzeService;
public function __construct(private PayzeService $payze) {}
First Use Case: Create a Payment
$payment = $this->payze->createPayment(
amount: 1000, // in minor units (e.g., cents)
currency: 'USD',
description: 'Order #123',
email: 'customer@example.com'
);
Payment Processing
createPayment() for one-time payments.createSubscription() for recurring payments.PayzeWebhookHandler to process Payze callbacks (e.g., payment success/failure).Integration with API Platform
PayzeStateProvider to sync payment states (e.g., pending, completed).PayzePayment or PayzeSubscription to expose endpoints:
#[ApiResource(
operations: [new Get(), new Post()],
stateProvider: PayzeStateProvider::class
)]
class Payment {}
Command-Based Tasks
$this->payze->refundPayment($paymentId);
config/logging.php.PayzeService in unit tests:
$this->mock(PayzeService::class)->shouldReceive('createPayment')->once();
Currency/Amount Units
1000 for $10.00). Misconfiguration causes failed transactions.Webhook Verification
PayzeWebhookHandler::verifySignature():
if (!$handler->verifySignature($request->getContent(), $request->headers->get('X-Signature'))) {
abort(403);
}
Rate Limits
PayzeService logs for HTTP errors (e.g., 429 Too Many Requests).PAYZE_WEBHOOK_SECRET and PAYZE_WEBHOOK_URL.Custom Fields
Override PayzeService to add metadata:
$payment = $this->payze->createPayment(..., [
'custom_field' => 'value'
]);
State Transitions
Extend PayzeStateProvider to handle custom states (e.g., fraud_review).
Retry Logic
Implement exponential backoff for failed API calls in PayzeClient.
How can I help you explore Laravel packages today?