PHPackages                             akawaka/sylius-soge-commerce-plugin - 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. akawaka/sylius-soge-commerce-plugin

ActiveSylius-plugin[Payment Processing](/categories/payments)

akawaka/sylius-soge-commerce-plugin
===================================

Sylius plugin for Soge commerce payment method by AKAWAKA.

v0.1.5(4d ago)1817[12 PRs](https://github.com/akawaka/sylius-soge-commerce-plugin/pulls)MITPHPPHP ^8.0CI passing

Since Mar 20Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/akawaka/sylius-soge-commerce-plugin)[ Packagist](https://packagist.org/packages/akawaka/sylius-soge-commerce-plugin)[ RSS](/packages/akawaka-sylius-soge-commerce-plugin/feed)WikiDiscussions main Synced today

READMEChangelog (6)Dependencies (108)Versions (23)Used By (0)

 [ ![](https://camo.githubusercontent.com/85157c984a2e5af70652b4857535b2efda8fa0f3ae4ad9574576e335e2d84692/68747470733a2f2f63646e2e616b6177616b612e66722f7075626c69632f696d616765732f6c6f676f2f6c6f676f2d616b6177616b612d636f756c6575722e706e67) ](https://www.akawaka.fr/)

AkawakaSyliusSogeCommercePlugin
===============================

[](#akawakasyliussogecommerceplugin)

Soge commerce payment method plugin.

Documentation
-------------

[](#documentation)

### Features

[](#features)

This plugin integrates the **SogeCommerce** payment method using ["Smart Forms"](https://sogecommerce.societegenerale.eu/doc/fr-FR/rest/V4.0/javascript/redirection/reference_smartform.html).

Unlike traditional payment gateways, **the payment form is embedded directly on the payment selection page**. This introduces unique challenges, which are detailed in the next section.

### How It Works

[](#how-it-works)

Since the payment form is available on the **payment selection page**, the user is **paying for a cart, not an order**. This differs from the standard Sylius flow, where payment typically occurs **after** the cart has been converted into an order.

#### Payment Flow

[](#payment-flow)

When a payment is made, **SogeCommerce Smart Forms** allows defining a **return URL**. The controller handling this URL performs the following actions:

1. **Verify the authenticity of the request** to prevent fraud.
2. **Retrieve the cart** and ensure the correct **payment method** is assigned.
3. **Check if the payment was successful**:
    - **If the payment fails**, the user is redirected back to the payment selection page with a flash message.
    - **If the payment succeeds**, the cart is **converted into an order**, and the user is redirected to the next checkout step.

### Differences from a Traditional Sylius Payment Gateway

[](#differences-from-a-traditional-sylius-payment-gateway)

In a standard Sylius payment gateway, the process relies on `StatusAction` and `CaptureAction`. These actions are present in this plugin as well but behave **differently** due to the fact that **payment is processed on the payment selection page** rather than after checkout.

#### `CaptureAction`

[](#captureaction)

- This class is required to work.
- **However, its `execute` method does nothing**, since payment is already processed on the payment selection page.

#### `StatusAction`

[](#statusaction)

- This action **marks the payment as captured or failed** based on the bank’s response.
- It is responsible for validating the final payment status.

### Preventing Cart Modifications After Payment

[](#preventing-cart-modifications-after-payment)

#### The Problem:

[](#the-problem)

Since payment happens **before the cart becomes an order**, the user can modify the cart **in another browser tab** after making a payment. This could lead to a mismatch between the **paid amount** and the **actual cart total**.

#### The Solution:

[](#the-solution)

- The plugin checks whether the **amount paid matches the current cart total**.
- If there is a discrepancy, the payment is **marked as failed**, and the **SogeCommerce API is used to cancel the payment**. The user can still pays for his order since the last payment is failed.

### Handling Failed Payment Cancellations

[](#handling-failed-payment-cancellations)

If the cancellation request to **SogeCommerce's API** fails (e.g., the API is disabled), the plugin **dispatches a `PaymentCancelationFailedEvent`**.

> ⚠ **Important:** The plugin does **not** listen for this event by default.

To handle this scenario, you should:

- **Listen for the event** in your Sylius project.
- **Implement appropriate actions**, such as:
    - Retrying the cancellation.
    - Sending an email notification to the administrator.
    - Logging the issue for manual review.

### Summary

[](#summary)

- Payment occurs on the payment selection page, not after checkout.
- Orders are created only after a successful payment.
- The standard Sylius `CaptureAction` is unused, while `StatusAction` validates payments.
- The plugin prevents users from modifying their cart after payment by verifying the paid amount.
- If payment cancellation fails, an event is dispatched, requiring manual handlin

Install guide
-------------

[](#install-guide)

##### 1. Run `composer require akawaka/sylius-soge-commerce-plugin`

[](#1-run-composer-require-akawakasylius-soge-commerce-plugin)

##### 2. Change your `config/bundles.php` file to add the line for the plugin :

[](#2-change-your-configbundlesphp-file-to-add-the-line-for-the-plugin-)

```
