epay_invoices
table with a user_id
foreign id.$user->charge()
to create an invoice for a user, and $user->invoices()
to get all user’s invoices..env
fileCHARGILY_EPAY_BACK_URL
and CHARGILY_EPAY_WEBHOOK_URL
should be real URLs, so you can’t put http://127.0.0.1:8000
, use Ngrok.
Epayable
trait to your User model:
Make()
function from the Epay_Invoice
model:
Make()
function returns the checkout URL, where the user should be redirected to make a payment, If any error occurs, it will return to the home page, so make sure to check this before redirecting the user.
The Make()
also creates an invoice in your database using the info from the provided $configurations array, so if you added columns to the migration file of the invoices table that comes with the package, you have to add the corresponding values as a second array, example:
product_id
, that’s because you may be added product_id
field in the migration file.
charge()
custom model method which is provided by the Epayable
trait, this method will automatically add the name of the client, the email of the client, and the client_id
foreign key:
charge()
method calls the Make()
static function at a certain point, so they act the same way, it returns the checkout URL, or the home page URL if any error occurs.
Just like the Make()
function, you can add a second array to pass any added columns to the invoices
table.
POST
Route (ex: “/webhook”), by the way, this is the URL you should add to the CHARGILY_EPAY_WEBHOOK_URL
key in the .env
file.
Important: You have to exclude this URL from CSRF verification, to do so, add it to the except
method in your applications’s App\Http\Middleware\VerifyCsrfToken
middleware:
$webhookHandler -> invoice['invoice_number']
Here is an example of the data that comes with the post request from Chargily Pay:
/epay-webhook-tester
, navigate to it, put the ID of the invoice you want to simulate its payment and click on PAY.
**Important: ** When you run your application using the local server php artisan serve
, it will work on a single thread, so making post requests to itself will give you a timeout error, on a server, this is not a problem because it will use Apache or Nginx, the solution is to start another local server on another port (ex: 8001) and use this feature from there.
Example:
php artisan serve
so you will have your app on http://127.0.0.1:8000
.php artisan serve --port=8001
then visit http://127.0.0.1:8001/epay-webhook-tester
, not http://127.0.0.1:8000/epay-webhook-tester
APP_ENV=local
), and am sure it’s not needed in production.