PHPackages                             c975l/payment-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. c975l/payment-bundle

AbandonedArchivedSymfony-bundle[Payment Processing](/categories/payments)

c975l/payment-bundle
====================

Defines form, transactions, database store, etc. for payments using Stripe

v5.0.5(1y ago)130412MITPHPPHP &gt;=8.0

Since Jul 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/975L/PaymentBundle)[ Packagist](https://packagist.org/packages/c975l/payment-bundle)[ Docs](https://github.com/975L/PaymentBundle)[ Fund](https://buymeacoff.ee/laurentmarquet)[ Fund](https://opencollective.com/laurent-marquet)[ RSS](/packages/c975l-payment-bundle/feed)WikiDiscussions main Synced 2mo ago

READMEChangelogDependencies (14)Versions (77)Used By (2)

PaymentBundle
=============

[](#paymentbundle)

PaymentBundle does the following:

- Defines form to request payment,
- Stores the transaction in a database table with a unique order id,
- Allows the possibility to add buttons/links for pre-defined payment,
- Allows to define a free amount form for payment (Donation, Consultation, etc.),
- Sends an email, to the user, of the transaction via [c975LEmailBundle](https://github.com/975L/EmailBundle) as `c975LEmailBundle` provides the possibility to save emails in a database, there is an option to NOT do so via this Bundle,
- Sends an email, to the site, containing same information as above + fee and estimated income,
- Creates flash to inform user,
- Display information about payment after transaction.

This Bundle relies on the use of [Stripe](https://stripe.com/) and its [PHP Library](https://github.com/stripe/stripe-php). **So you MUST have a Stripe account.**It is also recomended to use this with a SSL certificat to reassure the user.

[PaymentBundle dedicated web page](https://975l.com/en/pages/payment-bundle).

[PaymentBundle API documentation](https://975l.com/apidoc/c975L/PaymentBundle.html).

Bundle installation
-------------------

[](#bundle-installation)

### Step 1: Download the Bundle

[](#step-1-download-the-bundle)

**v3.x works with Symfony 4.x. Use v2.x for Symfony 3.x**Use [Composer](https://getcomposer.org) to install the library

```
    composer require c975L/payment-bundle
```

### Step 2: Configure the Bundle

[](#step-2-configure-the-bundle)

Check dependencies for their configuration:

- [Symfony Mailer](https://github.com/symfony/mailer)
- [Doctrine](https://github.com/doctrine/DoctrineBundle)
- [KnpPaginatorBundle](https://github.com/KnpLabs/KnpPaginatorBundle)
- [c975LEmailBundle](https://github.com/975L/EmailBundle)
- [Stripe PHP Library](https://github.com/stripe/stripe-php)

c975LPaymentBundle uses [c975L/ConfigBundle](https://github.com/975L/ConfigBundle) to manage configuration parameters. Use the Route "/payment/config" with the proper user role to modify them.

### Step 3: Enable the Routes

[](#step-3-enable-the-routes)

Then, enable the routes by adding them to the `/config/routes.yaml` file of your project:

```
c975_l_payment:
    resource: "@c975LPaymentBundle/Controller/"
    type: annotation
    prefix: /
    #Multilingual website use the following
    #prefix: /{_locale}
    #defaults:   { _locale: '%locale%' }
    #requirements:
    #    _locale: en|fr|es
```

### Step 4: Create MySql table

[](#step-4-create-mysql-table)

You can use `php bin/console make:migration` to create the migration file as documented in [Symfony's Doctrine docs](https://symfony.com/doc/current/doctrine.html) OR use `/Resources/sql/payment.sql` to create the tables `stripe_payment`. The `DROP TABLE` is commented to avoid dropping by mistake.

### Step 5: copy images to web folder

[](#step-5-copy-images-to-web-folder)

Install images by running

```
php bin/console assets:install --symlink
```

It will copy content of folder `Resources/public/images/` to your web folder. They are used to be displayed on the payment form.

You can also have a look at [official badges from Stripe](https://stripe.com/about/resources?locale=fr).

### How to use

[](#how-to-use)

The process is the following:

- User selects a product,
- User clicks to pay,
- Payment is created in DB,
- User is redirected to Payment form,
- User pays,
- User is redirected to returnRoute,
- Actions are executed to deliver product (if payment successful or sends an error),
- User is redirected to final confirmation or delivery product page.

To achieve this, you have to define 2 Controller Routes and 2 Services methods (+ Interface) (while you can do all of this in Controller, Best Practices recommend to keep Controller methods skinny).

Here are the examples for those files:

```
//YourProductServiceInterface file
namespace App\Service;

use c975L\PaymentBundle\Entity\Payment;

interface YourProductServiceInterface
{
    public function validate(Payment $payment);
}
```

```
//Your ProductService file
namespace App\Service;

use Doctrine\ORM\EntityManagerInterface;
use App\Service\YourProductServiceInterface;

class YourProductService implements YourProductServiceInterface
{
    private $em;

    public function __construct(EntityManagerInterface $em)
    {
        $this->em = $em;
    }

    public function validate(Payment $payment)
    {
        /**
         * For example if `$payment->getAction()` contains the result of "json_encode(array('addCredits' => 10));"
         */
        $action = (array) json_decode($payment->getAction());
        if (array_key_exists('addCredits', $action)) {
            //Gets the user
            $user = $this->em->getRepository('c975LUserBundle:User')
                ->findOneById($payment->getUserId());

            //Adds credits to user
            $user->setCredits($user->getCredits() + $action['addCredits']);
            $this->em->persist($user);

            //Set payment as finished
            $payment->setFinished(true);
            $this->em->persist($payment);
            $this->em->flush();

            return true;
        }

        return false;
    }
}
```

```
//YourPaymentServiceInterface file
namespace App\Service;

interface YourPaymentServiceInterface
{
    public function payment($yourNeededData);
}
```

```
//Your PaymentService file
namespace App\Service;

use App\Service\YourPaymentServiceInterface;
use c975L\PaymentBundle\Service\PaymentServiceInterface;

class YourPaymentService implements YourPaymentServiceInterface
{
    public function payment(PaymentServiceInterface $paymentService, $yourNeededData)
    {
        /**
         * Except amount and currency all the fields are nullable
         * You may use the data define in `$yourNeededData`
         */
        $paymentData = array(
            'amount' => YOUR_AMOUNT, //Must be an integer in cents
            'currency' => YOUR_CURRENCY, //Coded on 3 letters or use "$paymentService->getParameter('c975LPayment.defaultCurrency')" to get your default currency
            'action' => YOUR_ACTION, //Store the action to achieve after the payment. Mainly used by `returnRoute`. As a string, you can store plain text, json, etc.
            'description' => YOUR_DESCRIPTION,
            'userId' => USER_ID,
            'userIp' => $request->getClientIp(),
            'live' => false|true, //If your product is live or not, different from live config value
            'returnRoute' => 'THE_NAME_OF_YOUR_RETURN_ROUTE', //This Route is defined in your Controller
            'vat' => 'YOUR_VAT_RATE', //Rate value without % i.e. 5.5 for 5.5%, or 20 for 20%
            );
        $paymentService->create($paymentData);
    }
}
```

```
//Your Controller file
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use c975L\PaymentBundle\Entity\Payment;
use c975L\PaymentBundle\Service\PaymentServiceInterface;
use App\Service\YourPaymentServiceInterface;

class PaymentController extends AbstractController
{
    /**
     * Route used to proceed to payment
     * @return Response
     *
     * @Route("proceed-to-payment",
     *     name="proceed_to_payment")
     */
    public function proceedToPayment(YourPaymentServiceInterface $yourPaymentService)
    {
        //Creates the Payment
        $yourPaymentService->payment();

        //Redirects to the payment form
        return $this->redirectToRoute('payment_form');
    }

    /**
     * Return Route used after payment
     * @return Redirect
     * @throws NotFoundHttpException
     *
     * @Route("/payment-done/{orderId}",
     *    name="payment_done",
     *    methods={"HEAD", "GET"})
     */
    public function paymentDone(YourProductServiceInterface $yourProductService, PaymentServiceInterface $paymentService, Payment $payment)
    {
        //Validates the Payment
        $validation = $yourProductService->validate($payment);

        //Redirects or renders
        if ($validation) {
            return $this->redirectToRoute('YOUR_ROUTE');
        }

         //Payment has been done but product was not validated
        $paymentService->error($payment);

        return $this->redirectToRoute('payment_display', array('orderId' => $payment->getOrderId()));
    }
}
```

Use the [testing cards](https://stripe.com/docs/testing) to test before going to production.

### Merchant's data

[](#merchants-data)

You need to override the template `fragments/merchantData.html.twig` in your `/templates/bundles/c975LPaymentBundle/fragments/merchantData.html.twig` and indicate there all your official data, such as address, VAT number, etc.

This template will be included in the email sent to the user after its payment.

### Mention payment system

[](#mention-payment-system)

You can mention the payment system used (i.e. in the footer) by simply include an html fragment with the following code `{% include '@c975LPayment/fragments/paymentSystem.html.twig' %}`. This will include Stripe logo and accepted cards.

### Use payment buttons/links

[](#use-payment-buttonslinks)

You can add any payment button/link, wherever you want, by using the Twig extensions with the following code:

```
{{ payment_button('YOUR_TEXT_TO_DISPLAY', AMOUNT, 'CURRENCY', 'YOUR_OPTIONAL_STYLES') }}
{{ payment_link('YOUR_TEXT_TO_DISPLAY', AMOUNT, 'CURRENCY') }}
```

`AMOUNT` is the real amount (i.e. 12.92), **NOT** the amount in cents.

Or you can use it empty, this will lead user fo fill a form to proceed to payment

```
{{ payment_button() }}
{{ payment_link() }}
```

If this project **help you to reduce time to develop**, you can sponsor me via the "Sponsor" button at the top :)

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~36 days

Recently: every ~0 days

Total

75

Last Release

550d ago

Major Versions

v1.16.2 → v2.02018-09-01

v2.1.1.2 → v3.02019-07-15

3.x-dev → 4.x-dev2021-10-11

v4.0 → v5.02024-11-05

PHP version history (4 changes)v1.0PHP &gt;=5.5.9

v2.0.3PHP ^7

v3.4PHP \*

v5.0.2PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5679e828a48e37afabd92da60ab8d78bf65a3bedc0f618ef3fddf92082840f52?d=identicon)[Laurent3170](/maintainers/Laurent3170)

---

Top Contributors

[![LaurentMarquet](https://avatars.githubusercontent.com/u/16478286?v=4)](https://github.com/LaurentMarquet "LaurentMarquet (94 commits)")

---

Tags

paymentstripesymfonysymfony-bundlesymfonybundlestripepayment

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/c975l-payment-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/c975l-payment-bundle/health.svg)](https://phpackages.com/packages/c975l-payment-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M648](/packages/sylius-sylius)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1714.8k8](/packages/2lenet-crudit-bundle)[miracode/stripe-bundle

Symfony bundle to integrate Stripe PHP SDK. Ability to save Stripe objects in database using Doctrine.

1016.1k](/packages/miracode-stripe-bundle)[easycorp/easyadmin-demo

EasyAdmin Demo Application

145.7k](/packages/easycorp-easyadmin-demo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
