A PHP Library for Paymongo.
This package is not affiliated with Paymongo. The package requires PHP 7.2+
You can install the package via composer:
composer require luigel/laravel-paymongo
Laravel 6 and up uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.
Put your Secret Key
and Public Key
in you .env
file.
PAYMONGO_SECRET_KEY=
PAYMONGO_PUBLIC_KEY=
Laravel-Paymongo supports Laravel 6.* and 7.*
Creates a one-time use token representing your customer's credit card details. NOTE: This token can only be used once to create a Payment. You must create separate tokens for every payment attempt.
Sample
use Luigel\Paymongo\Facades\Paymongo;
$token = Paymongo::token()->create([
'number' => '4242424242424242',
'exp_month' => 12,
'exp_year' => 25,
'cvc' => "123",
]);
Retrieve a token given an ID. The prefix for the id is tok_
followed by a unique hash representing the token. Just pass the token id to find($id)
method.
Sample
use Luigel\Paymongo\Facades\Paymongo;
$token = Paymongo::token()->find($tokenId);
To charge a payment source, you must create a Payment object. When in test mode, your payment sources won't actually be charged. You can select specific payment sources for different success and failure scenarios.
Payload
Refer to Paymongo documentation for payload guidelines.
Sample
use Luigel\Paymongo\Facades\Paymongo;
$payment = Paymongo::payment()->create([
'amount' => 100.00,
'currency' => 'PHP',
'description' => 'A testing Payment',
'statement_descriptor' => 'LUIGEL STORE',
'source' => [
'id' => 'tok_Jt7WJhH4eQaEEZqWxdXW3sz5',
'type' => 'token'
]
]);
You can retrieve a Payment by providing a payment ID. The prefix for the id is pay_
followed by a unique hash representing the payment. Just pass the payment id to find($paymentId)
method.
Sample
use Luigel\Paymongo\Facades\Paymongo;
$payment = Paymongo::payment()->find('pay_i35wBzLNdX8i9nKEPaSKWGib');
Returns all the payments you previously created, with the most recent payments returned first. Currently, all payments are returned as one batch. We will be introducing pagination and limits in the next iteration of the API.
Sample
use Luigel\Paymongo\Facades\Paymongo;
$payments = Paymongo::payment()->all();
Creates a source to let the user pay using their Gcash Accounts.
Payload
Refer to Paymongo documentation for payload guidelines.
Sample
use Luigel\Paymongo\Facades\Paymongo;
$source = Paymongo::source()->create([
'type' => 'gcash',
'amount' => 100.00,
'currency' => 'PHP',
'redirect' => [
'success' => 'https://your-domain.com/success',
'failed' => 'https://your-domain.com/failed'
]
]);
Creates a webhook.
Payload
Refer to Paymongo documentation for payload guidelines.
Sample
use Luigel\Paymongo\Facades\Paymongo;
$webhook = Paymongo::webhook()->create([
'url' => 'http://your-domain/webhook/source-chargeable',
'events' => [
'source.chargeable'
]
]);
Returns all the webhooks you previously created, with the most recent webhooks returned first.
Sample
use Luigel\Paymongo\Facades\Paymongo;
$webhook = Paymongo::webhook()->all();
Set the webhook enable or disable.
Sample
use Luigel\Paymongo\Facades\Paymongo;
// Enable webhook
$webhook = Paymongo::webhook()->find('hook_9VrvpRkkYqK6twbhuvcVTtjM')->enable();
// Disable webhook
$webhook = Paymongo::webhook()->find('hook_9VrvpRkkYqK6twbhuvcVTtjM')->disable();
Updates a specific webhook
Sample
use Luigel\Paymongo\Facades\Paymongo;
$webhook = Paymongo::webhook()->find('hook_9VrvpRkkYqK6twbhuvcVTtjM')->update([
'url' => 'https://update-domain.com/webhook'
]);
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
Made with ❤️ by Harlequin Doyon