bagene / ph-payments
A Package container for different PH compatible payment providers
0.2.1
2024-02-24 14:24 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- orchestra/testbench: ^8.21
- phpstan/phpstan: ^1.10
README
composer require "bagene/ph-payments"
Configuration
php artisan vendor:publish --tag="ph-payments-config"
Usage
use Bagene\PhPayments\Helpers\PaymentBuilder; PaymentBuilder::xendit(); $response = PaymentBuilder::xendit() ->invoice() ->create([ 'external_id' => 'invoice-123', 'amount' => 100000, 'payer_email' => 'test@example.org', 'description' => 'Invoice #123', 'success_redirect_url' => 'https://example.org/success', 'failure_redirect_url' => 'https://example.org/failure', ]); dump($response->getId()); dump($response->getExternalId()); return redirect()->away($response->getInvoiceUrl());
Methods
invoice() ['create', 'get'] qr() ['create'] - If supported
Webhooks
use Bagene\PhPayments\Helpers\PaymentBuilder; public function xenditWebhook(Request $request) { $gateway = PaymentBuilder::getXendidGateway(); $response = $gateway->parseWebhookPayload($request); // Do something with the response }
Alternatively, you can use the xendit-webhook
route and Controller to handle the webhook.
php artisan vendor:publish --tag=ph-payments-routes
php artisan vendor:publish --tag=ph-payments-services
After publishing the routes, you can add the route to your routes/payments.php
file and the Service folder.
You can then use the Services/WebhookService.php
to handle the webhook.
routes/payments
<?php use Bagene\PhPayments\Controllers\XenditWebhookController; use Illuminate\Support\Facades\Route; Route::post( '/webhooks/{provider}/invoice', [XenditWebhookController::class, 'parse'] )->name('xendit.invoice.create');
You can change the endpoint to you liking and register the route.
Services/WebhookService.php
<?php namespace App\Services; use Bagene\PhPayments\Xendit\XenditWebhook; use Bagene\PhPayments\Xendit\XenditWebhookInterface; use Illuminate\Http\JsonResponse; use App\Models\TestOrder; class XenditWebhookService extends XenditWebhook implements XenditWebhookInterface { public function handle(array $payload): JsonResponse { TestOrder::query() ->where('reference', $payload['external_id']) ->update([ 'status' => strtolower($payload['status']) ]); return response()->json([ 'status' => 'ok' ]); } }
Supported Gateways
- Xendit
- Supported Features:
- invoice (create, get)
- qr (create)
- Supported Features:
- Maya
- Supported Features:
- invoice (create, get)
- token (create, get)
- payment (create, get)
- Supported Features:
License
This package is open-sourced software licensed under the MIT license.