blupay / sdk-laravel
BluPay service provider and payment webhook middleware for Laravel
Requires
- php: ^8.2
- blupay/sdk-php: ^0.1
- illuminate/http: ^12.0 || ^13.0
- illuminate/support: ^12.0 || ^13.0
Requires (Dev)
- laravel/framework: ^12.0 || ^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Version 0.1.1. Requires Laravel 12 (PHP 8.2+) or Laravel 13 (PHP 8.3+), cURL and Composer 2. Uses BluPay's public v1 API at https://blupay.me/api.
Install
Install the tagged release from GitHub:
composer config repositories.blupay-php vcs https://github.com/blupay-dev/blupay-php.git
composer config repositories.blupay-laravel vcs https://github.com/blupay-dev/blupay-laravel.git
composer require 'blupay/sdk-laravel:0.1.1'
With the 0.1.1 source directory unpacked alongside your project:
composer config repositories.blupay-php '{"type":"path","url":"./blupay-php","options":{"versions":{"blupay/sdk-php":"0.1.1"}}}' composer config repositories.blupay-laravel path ./blupay-laravel composer require 'blupay/sdk-laravel:@dev'
Distribution and registry status are listed in the BluPay integration docs.
Create a test invoice
Configure BLUPAY_API_KEY in the server environment using a key for a Sandbox shop with invoices:write and invoices:read. Persist a distinct SAVED_ATTEMPT_KEY with the order and request body before the first call. Use an enabled quote currency.
Publish config with php artisan vendor:publish --tag=blupay-config. Put BLUPAY_WEBHOOK_SECRET in server configuration and add the middleware to the dedicated server-to-server route. Read the verified event from $request->attributes->get('blupay.event'). Register the example from examples/console-route.php in routes/console.php before running the command. For a local source install, keep both PHP and Laravel ZIPs alongside the consuming app. The framework integration suite uses Laravel itself.
From the SDK checkout with its dependencies installed:
php artisan blupay:invoice 49.00 USD order-1024 "$SAVED_ATTEMPT_KEY"
The command prints the invoice link and hosted payment URL. Save the link with the order. A merchant-hosted page reads the checkout from its own authenticated backend, posts a returned currency-network ID, and renders the exact instructions returned by BluPay.
Methods
Inject BluPay\\Sdk\\Client for the five payment methods. Add VerifyBluPayWebhook middleware to the signed webhook route.
| Operation | API path | Permission |
|---|---|---|
| Create invoice | POST /v1/invoices/ |
invoices:write |
| Read invoice | GET /v1/invoices/{link}/ |
invoices:read |
| Read checkout | GET /v1/invoices/{link}/checkout/ |
invoices:read |
| Select asset and network | POST /v1/invoices/{link}/checkout/select-currency/ |
invoices:write |
| Read receipt | GET /v1/invoices/{link}/received/ |
invoices:read |
All amounts are handled as decimal strings. The SDK unwraps the success envelope and exposes the HTTP status and request ID on API errors. Defaults to 10 seconds (BLUPAY_TIMEOUT_MS). Supply API keys from server configuration and keep them out of client bundles and logs.
Reconcile and confirm
- On a timed-out invoice creation, use the same saved attempt key and identical body. A 409 can mean the first request is still in progress or the key was reused with a different body.
- On selection timeout or 409, read the checkout again to reconcile its current quote before retrying. Use
paymentInstructions.amountand handle a missing instruction by checking checkout state. - The browser return is a status view. Look up the invoice on your server and compare stored link, order ID, decimal amount, currency and environment. Fulfill a production order once after authoritative
Paid. - For webhooks pass the exact raw request body,
X-BluPay-Timestamp,X-BluPay-SignatureandX-BluPay-Event-Idto the verifier. It authenticates HMAC-SHA256 and a five-minute timestamp window. Persist events in a durable inbox keyed by event ID and make order fulfillment idempotent. A verification result is an authentication check. - Use the receipt to reconcile the confirmed received amount and any overpayment separately.
Tests
composer install && composer test
Run the tests against the included isolated fixture. The contract suite uses loopback endpoints and fixture credentials. For version changes compare routes, scopes, envelopes and signatures with the API reference, then exercise a Sandbox shop and record its outcomes before a release.
See CHANGELOG.md for compatibility changes.