Download the PHP package sebdesign/laravel-viva-payments without Composer
On this page you can find all versions of the php package sebdesign/laravel-viva-payments. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-viva-payments
Viva Payments for Laravel
This package provides an interface for the Viva Wallet Payment API. It handles the Smart Checkout integration, the ISV Payment API, and Webhooks.
Check out the official Viva Wallet Developer Portal for detailed instructions on the APIs and more: https://developer.vivawallet.com
Note: This project is not a official package, and I'm not affiliated with Viva Payments in any way.
Setup
Installation
Install the package through Composer.
This package requires PHP 8.1 and Laravel 9.0 or higher, and uses Guzzle 7.0 to make API calls. Use the appropriate version according to your dependencies.
Viva Payments for Laravel | Guzzle | Laravel |
---|---|---|
^6.0 | ^7.0 | ^9.0 |
^5.2 | ^7.0 | ^9.0 |
^5.1 | ^7.0 | ^8.0 |
^5.0 | ^6.0|^7.0 | ^7.0 |
^4.3 | ^6.0|^7.0 | ^7.0 |
~4.1 | ~6.0 | ~7.0 |
~4.0 | ~6.0 | ~6.0 |
~3.0 | ~6.0 | ~5.5 |
~2.0 | ~6.0 | ~5.0 |
~1.0 | ~5.0 | ~5.0 |
Service Provider
The package will automatically register its service provider.
Configuration
Add the following array in your config/services.php
.
The api_key
and merchant_id
can be found in the Settings > API Access section of your profile.
The client_id
and client_secret
are needed for the Smart Checkout. You can generate the Smart Checkout Credentials in the Settings > API Access section of your profile.
The isv_partner_id
and isv_partner_api_key
are required for using the ISV Payment API with Basic authentication.
Read more about API authentication on the Developer Portal: https://developer.vivawallet.com/getting-started/find-your-account-credentials/client-smart-checkout-credentials/
The environment
can be either production
or demo
.
Smart Checkout
Read more about the Smart Checkout process on the Developer portal: https://developer.vivawallet.com/smart-checkout/
The \Sebdesign\VivaPayments\Facades\Viva
facade provides all the methods needed to interact with the Smart Checkout integration.
The following guide will walk you through the necessary steps:
Create the payment order
The amount requested in cents is required. All the other parameters are optional. Check out the request body schema.
Redirect to Smart Checkout
Verify payment
Full example
Handling Webhooks
Viva Payments supports Webhooks, and this package offers a controller which verifies and handles incoming notification events.
Read more about the Webhooks on the Developer Portal: https://developer.vivawallet.com/webhooks-for-payments/
Define the route
In your routes/web.php
define the following route for each webhook you have in your profile, replacing the URI(s) and your controller(s) accordingly.
Exclude from CSRF protection
Don't forget to add your webhook URI(s) to the $except
array on your VerifyCsrfToken
middleware.
Handle webhook events
To handle any request from Viva Wallet, you may listen to the WebhookEvent
.
According to the EventTypeId
, you can handle any event.
The EventData
property contains an object with the actual notification.
The class of the object depends on the notification type:
Event | Class |
---|---|
Transaction Payment Created | TransactionPaymentCreated |
Transaction Failed | TransactionFailed |
All other events | stdClass |
In addition, the TransactionPaymentCreated
and TransactionFailed
events are dispatched. You can listen to these specific events instead of listening to the WebhookEvent
.
Payment API reference
All methods accept a $guzzleOptions
array argument as their last parameter. This argument is entirely optional, and it allows you to specify additional request options to the Guzzle
client.
Orders
Create a payment order
Get the redirect URL
Transactions
Retrieve a transaction
Create a recurring transaction
OAuth
Request access token
See: https://developer.vivawallet.com/authentication/#step-2-request-access-token
You don't need to call this method, because the client requests the access token automatically when needed. However, you can specify the client credentials at runtime if you want.
If you need to request access tokens manually, you can use the requestToken
method.
This method returns the token as an AccessToken
object.
Use an existing access token
If you are storing the token somewhere, e.g. in your database or in the cache, you can set the access token string on the client to be used as a Bearer token.
Cards
Create card token
Webhooks
Get an authorization code
See: https://developer.vivawallet.com/webhooks-for-payments/#generate-a-webhook-verification-key
ISV Payment API Reference
The ISV Payment API methods are available through the Viva::isv()
service.
Orders
Create a payment order
Transactions
Retrieve a transaction
Create a recurring transaction
Exceptions
When the VivaPayments API returns an error, a Sebdesign\VivaPayments\VivaException
is thrown.
For any other HTTP error a GuzzleHttp\Exception\ClientException
is thrown.
Tests
Unit tests are triggered by running phpunit --group unit
.
To run functional tests you have to include a .env
file in the root folder, containing the credentials (VIVA_API_KEY
, VIVA_MERCHANT_ID
, VIVA_CLIENT_ID
, VIVA_CLIENT_SECRET
), in order to hit the VivaPayments demo API. Then run phpunit --group functional
to trigger the tests.
All versions of laravel-viva-payments with dependencies
guzzlehttp/guzzle Version ^7.2
illuminate/config Version ^9.0 | ^10.0 | ^11.0
illuminate/routing Version ^9.0 | ^10.0 | ^11.0
illuminate/support Version ^9.0 | ^10.0 | ^11.0
spatie/laravel-data Version ^2.0 | ^3.0 | ^4.0