Download the PHP package devinweb/laravel-youcan-pay without Composer
On this page you can find all versions of the php package devinweb/laravel-youcan-pay. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devinweb/laravel-youcan-pay
More information about devinweb/laravel-youcan-pay
Files in devinweb/laravel-youcan-pay
Package laravel-youcan-pay
Short Description YouCanPay packages for Laravel that provides an easy way to reach the best experience.
License MIT
Homepage https://github.com/devinweb/laravel-youcan-pay
Informations about the package laravel-youcan-pay
Laravel YouCayPay
- Introduction
- Installation
- Database Migrations
- Configuration
- Billable Model
- YouCanPay Keys
- Usage
- Customers
- Retrieving Customers
- Generate Token
- Generate Payment URL
- Tokenization
- Get Token id
- Get Payment url
- Customer info
- Metadata
- Generate Payment form
- Handling YouCanPay Webhooks
- Webhooks URl
- Webhook Events
- Verify webhook signature manually
- Validate webhook signature manually
- Commands
- Testing and test cards
Introduction
Laravel YouCanPay provides an easy experience, to generate the payment form, and process all the operations related to the payment.
Installation
You can install the package via composer:
Database Migrations
LaravelYouCanPay package provides its own database to manage the user transactions in different steps, the migrations will create a new transactions
table to hold all your user's transactions.
If you need to overwrite the migrations that ship with LaravelYouCanPay, you can publish them using the vendor:publish Artisan command:
Configuration
To publish the config file you can use the command
then you can find the config file in config/youcanpay.php
Billable Model
If you want the package to manage the transactions based on the user model, add the Billable
trait to your user model.
This trait provides various methods to perform transaction tasks, such as creating a transaction, getting paid
, failed
and pending
transactions.
LaravelYouCanPay assumes your user model will be App\Models\User
, if you use a different user model namespace you should specify it using the method useCustomerModel
method.
This method should typically be called in the boot method of your AppServiceProvider
class
If you need in each transaction the package uses the billing data for each user, make sure to include a getCustomerInfo()
method in your user model, which returns an array that contains all the data we need.
YouCanPay Keys
Next, you should configure your environment in your application's .env
Customers
Retrieving Customers
You can retrieve a customer by their YouCanPay ID using the findBillable
method. This method will return an instance of the billable model:
Generate Token
If you need to generate the token form the user model the cutomer info will be attached directly from getCustomerInfo
method
If you need to add the metadata you can use
If you need to get the payment url as well from the user model you can use getPaymentURL
method with the same parameters below.
Generate Payment URL
Usage
Before starting using the package make sure to update your config/youcanpay.php
with the correct values provided by YouCanPay.
Tokenization
Get Token id
The first step we need is to create a token based on the credentails get it from YouCanPay dashboard using getId()
method.
Note
The amount should be 100, Exemple if your Product price=20$ you should send
amount = 20100 = 200 with currency='USD'
Get payment url
Standalone Integration, you can generate the payment url using the method getPaymentUrl()
Then you can put that url in your html page
Customer info
If you need to add the customer data during the tokenization, Please keep these array keys(name
, address
, zip_code
, city
, state
, country_code
, phone
and email
). you can use
Metadata
You can use the metadata to send data that can be retrieved after the response or in the webhook.
Generate Payment form
At this point we receive the token from our backend, so in our blade or any other html page, you can put at the head
this script
Then to display the form your logic it's will be looks like the code below
To start the payment you need an action, you can use a button
For more information please check this link.
Handling YouCanPay Webhooks
YouCan Pay uses webhooks to notify your application when an event happens in your account. Webhooks are useful for handling reactions to asynchronous events on your backend, such as successful payments, failed payments, successful refunds, and many other real time events. A webhook enables YouCan Pay to push real-time notifications to your application by delivering JSON payloads over HTTPS.
Webhooks and CSRF Protection
YouCanPay webhooks need to reach your URI without any obstacle, so you need to disable CSRF protection for the webhook URI, to do that make sure to add your path to the exception array in your application's
App\Http\Middleware\VerifyCsrfToken
middleware.
Webhooks URL
To ensure your application can handle YouCanPay webhooks, be sure to configure the webhook URL in the YouCanPay control panel. By default the package comes with a webhook build-in
using the URL youcanpay/webhook
you can find it by listing all the routes in your app using php artisan route:list
,
This webhook validates the signature related to the payload received, and dispatches an event.
Webhooks Middleware
If you need to attempt the webhook signature validation before processing any action, you can use the middleware verify-youcanpay-webhook-signature
, that validates the signature related to the payload received from YouCanPay.
Webhook Events
LaravelYouCanPay handles the common YouCanPay webhook events, if you need to handle the webhook events that you need you can listen to the event that is dispatched by the package.
- Devinweb\LaravelYouCanPay\Events\WebhookReceived
You need to register a listener that can handle the event:
Once your listener has been defined, you may register it within your application's EventServiceProvider
Verify webhook signature Manually
The webhook data received from YouCanPay looks like
But the interesting part is in the header request you can find the signature value using the key x-youcanpay-signature
.
To verify the webhook signature before processing any logic or action.
Validate webhook signature Manually
The validation has the same impact as the verification, but the validation throws an exception that you can inspect it in the log file.
Commands
If you need to clean the pending transactions, there's a command
You can add it to the scheduler that can run the command every single time, so the clean will be automatic and depend on the tolerance
value that is defined in the youcanpay
config file.
Testing and test cards
CARD | CVV | DATE | BEHAVIOUR |
---|---|---|---|
4242 4242 4242 4242 |
112 | 10/24 | No 3DS - Success |
4000 0000 0000 3220 |
112 | 10/24 | 3DS - Success |
4000 0084 0000 1629 |
112 | 10/24 | 3DS - Card Rejected |
4000 0000 0000 0077 |
112 | 10/24 | No 3DS - No Funds |
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email imad@devinweb.com instead of using the issue tracker.
Credits
- DARBAOUI Imad
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel YouCanPay Boilerplate
This package was generated using the Laravel YouCanPay Boilerplate.
All versions of laravel-youcan-pay with dependencies
illuminate/support Version ^7.0|^8.0|^9.0|^10.0
laravel/framework Version 8.*|9.*|10.*
youcanpay/payment-sdk Version *
spatie/laravel-enum Version ^2.0|^3.0