akawaka / sylius-soge-commerce-plugin
Sylius plugin for Soge commerce payment method by AKAWAKA.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 2
Type:sylius-plugin
Requires
- php: ^8.0
- sylius/sylius: ^1.12
- symfony/webpack-encore-bundle: ^1.15
Requires (Dev)
- behat/behat: ^3.6.1
- behat/mink-selenium2-driver: ^1.4
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink: ^1.8
- friends-of-behat/mink-browserkit-driver: ^1.4
- friends-of-behat/mink-debug-extension: ^2.0.0
- friends-of-behat/mink-extension: ^2.4
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.1
- friends-of-behat/variadic-extension: ^1.3
- friendsofsymfony/oauth-server-bundle: ^1.6 || >2.0.0-alpha.0 ^2.0@dev
- phpspec/phpspec: ^7.2
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^1.8.1
- phpstan/phpstan-doctrine: 1.3.16
- phpstan/phpstan-phpunit: *
- phpstan/phpstan-strict-rules: ^1.3.0
- phpstan/phpstan-webmozart-assert: ^1.2.0
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- psalm/plugin-symfony: *
- robertfausk/behat-panther-extension: ^1.1
- sensiolabs/security-checker: ^6.0
- sylius-labs/coding-standard: ^4.2
- sylius-labs/suite-tags-extension: ^0.2.0
- symfony/browser-kit: ^5.4
- symfony/debug-bundle: ^5.4
- symfony/dotenv: ^5.4
- symfony/flex: ^2.2.2
- symfony/intl: ^5.4
- symfony/web-profiler-bundle: ^5.4
- vimeo/psalm: 4.27.0
This package is auto-updated.
Last update: 2025-05-21 12:29:29 UTC
README
AkawakaSyliusSogeCommercePlugin
Soge commerce payment method plugin.
Documentation
Features
This plugin integrates the SogeCommerce payment method using "Smart Forms".
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
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
When a payment is made, SogeCommerce Smart Forms allows defining a return URL. The controller handling this URL performs the following actions:
- Verify the authenticity of the request to prevent fraud.
- Retrieve the cart and ensure the correct payment method is assigned.
- 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
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
- This class is required to work.
- However, its
execute
method does nothing, since payment is already processed on the payment selection page.
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
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 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
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
- Payment occurs on the payment selection page, not after checkout.
- Orders are created only after a successful payment.
- The standard Sylius
CaptureAction
is unused, whileStatusAction
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
1. Run composer require akawaka/sylius-soge-commerce-plugin
2. Change your config/bundles.php
file to add the line for the plugin :
<?php return [ // ... Akawaka\SyliusSogeCommercePlugin\AkawakaSyliusSogeCommercePlugin::class => ['all' => true], // ... ];
3. Import routing in your config/routes.yaml
file:
# config/routes.yaml akawaka_sylius_soge_commerce_plugin_shop: resource: "@AkawakaSyliusSogeCommercePlugin/config/shop_routing.yml" prefix: /{_locale} requirements: _locale: ^[a-z]{2}(?:_[A-Z]{2})?$ akawaka_sylius_soge_commerce_plugin_api_shop: resource: "@AkawakaSyliusSogeCommercePlugin/config/api_shop_routing.yml"
4. Update sylius templates:
cp -R vendor/akawaka/sylius-soge-commerce-plugin/tests/Application/templates/* templates/
You might want to override this plugin templates:
cp -R vendor/akawaka/sylius-soge-commerce-plugin/templates/* templates/bundles/AkawakaSyliusSogeCommercePlugin/
NOTE: The content in
tests/Application/templates/bundles/SyliusShopBundle/_scripts.html.twig
should be adapted to your theme and moved to an asset file.
5. That's it !
Quickstart Installation
Please refer to https://github.com/Sylius/PluginSkeleton/tree/1.14.