The instructions for the assessment can be found here.
- PHP 8.1 or later
- Docker
- Clone this repository with
git clone [email protected]:shineability/ticketr.git
- Run
composer install
to install the dependencies - Run
./vendor/bin/sail up
- Wait for it ☕
- Run
./vendor/bin/sail composer setup
to run the migrations - Visit
http://localhost
to run the app and view sent emails using Mailhog athttp://localhost:8025
Run tests with ./vendor/bin/sail test
.
To be able to receive webhook requests when running the project locally, Expose will be used to share the local URL. Run ./vendor/bin/sail share
and copy the public URL (use the HTTP one) to your .env
file, e.g.:
SHARE_URL=http://foobar.laravel-sail.site:8080
This will make webhooks available for the Mollie implementation, since the webhook URL can be sent along as a parameter when creating a payment using the Mollie API.
For the Stripe implementation the webhook URL needs to be configured in the Stripe backend, so send me the share URL if you want to see it in action or change the STRIPE_SECRET_KEY
and set up the webhook in your own Stripe test environment.
Currently three payment providers are available for Ticketr: Mollie, Stripe and Free.
This application implements the Strategy pattern to be able to switch between different payment provider implementations at runtime.
Each payment provider should implement the App\Payment\Contracts\PaymentProvider
interface:
interface PaymentProvider
{
public function name(): string;
public function checkout(Order $order): PaymentResponse;
public function getPayment(string $transactionId): Payment;
}
The PaymentProvider::checkout()
method returns a PaymentResponse
which has a Payment
and a checkout URL.
The Payment
will be used to update its initial state to the associated Order
.
After that, the customer will be redirected to the provider's checkout page URL, as defined by PaymentResponse::getCheckoutUrl()
.
The PaymentProvider::getPayment()
is used in the respective webhook controllers to fetch the payment and its updates from the provider by using the $transactionId
which was initially saved on the Order
.
Custom providers can be added using App\Payment\PaymentProviderFactory
. The factory can be easily accessed by its facade PaymentProvider
.
PaymentProvider::extend('stripe', function ($config, $app) {
$client = new \Stripe\StripeClient($config['secret_key']);
return new \App\Payment\Stripe\PaymentProvider($client);
});
The MIT License. Please see the license file for more information.