This project demonstrates the strategy/provider pattern using Symfony 4 service tagging feature.
git clone git@github.com:smtlab/symfony4-project.git
cd symfony-test-ecommerce.git
composer install
php bin/console create-product Phone
php bin/console create-payment paypal Phone
./bin/phpunit
- Create App\PaymentProvider\Custom.php
<?php
// src/PaymentProvider/Custom.php
declare(strict_types=1);
namespace App\PaymentProvider;
class Custom implements PaymentProviderInterface
{
public function pay(): void
{
// @TODO call your payment gateway
}
}
- Tag your payment provider service and set an unique key
# config/services.yaml
services:
App\PaymentProvider\Custom:
tags:
- { name: 'app.payment_provider', key: 'custom' }
- Pay using custom payment privider
php bin/console custom Phone