This project aims to make it as easy as possible to implement a payment providers into large projects. Inspired by the
laravel/cashier
package, which is limited to stripe at the moment, we try to bring in more flexibility into the
topic by allowing multiple payment providers to coexist.
Require the package through composer.
compsoer require marqant-lab/marqant-pay
Create the migrations for at least one billable model.
php artisan marqant-pay:migrations App\\User
# or
php artisan marqant-pay:migrations "App\User"
For each payment provider that you want to connect to, you will first have to pull in a payment gateway through composer. For example here we pull in the stripe gateway. Make sure to checkout the documentation of the provider package you want to pull in.
composer require marqant-lab/marqant-pay-stripe
Then you will have to add it to the marqant-pay.php
config file. Create it if it doesn't exist yet.
return [
/*
|--------------------------------------------------------------------------
| Gateways
|--------------------------------------------------------------------------
|
| In this section you can define all payment gateways that you need for
| your project.
|
*/
'gateways' => [
'stripe' => \Marqant\MarqantPayStripe\StripePaymentGateway::class,
],
];
Next you will have to create an entry for it in the database. To do so you can call the following command.
php artisan marqant-pay:providers:update
If you also want to remove the providers that are no longer listed in your configuration, then you can add the --delete
flag to the command.
php artisan marqant-pay:providers:update --delete
A billable in the context of this package is every model that is prepared to be used as customer - because customers are billable 😉
The setup consists of the database table columns needed to store provider related data and the usage of the Billable
trait on the billable model.
To create the needed migrations run the following command but replace the User
model if you want another model to
be used as customer, eg. a Company
model.
php artisan marqant-pay:migrations App\\User
# or
php artisan marqant-pay:migrations "App\User"
Then you can just run the migrations as usual to apply the migrations.
php artisan migrate
Note that you might need to do the same for the payment gateway package that you pull in, so make sure to checkout the documentation of it.
Check out the marqant-lab/marqant-pay-subscriptions package on how to pull in subscriptions functionality into your project.
To run tests, you first need to set up a sqlite database that we use to get snapshots of the database state. Run the following command from within your project root to create the sqlite database.
touch database/database.sqlite
Next you will have to add the tests of this package to the phpunit test suite in the phpunit.xml
file in the root
of your Laravel project.
<testsuites>
...
<testsuite name="MarqantPay">
<directory suffix="Test.php">./vendor/marqant-lab/marqant-pay/tests</directory>
</testsuite>
</testsuites>
Then you should be able to just run your tests with the following commands.
phpunit
# or
./vendor/bin/phpunit
If you want to just run a specific test or a method on a test, then you can filter them out like shown below.
phpunit --filter=<class or method>
If you need to perserve a snapshot of what is going on in the test database, then you can comment out the following
line in your phpunit.xml
file.
<!--<server name="DB_DATABASE" value=":memory:"/>-->
With this line commented out, Laravel will use the database/database.sqlite
file to store values.
TODO: Explain setup of development environment.
TODO: Add section for creating new payment providers.
To extend the MarqantPayService
class, which is what you use behind the scenes when using the MarqantPay facade
, you can create a Macro and attach it in the service provider of your package though the mixin
method provided by
the Macroable trait.
Note that you have to take care of your extensions, so only one macro of a kind is required. For example if two
extensions would provide the macro for MarqantPayService::subscribe
method, only one of those would be registered.