SyliusCon 2025 in Lyon
Join Us!
LogoLogo
🛣️ Roadmap💻 Sylius Demo💬 Community Slack
  • Sylius Documentation
  • Sylius Plugins
  • Sylius Stack
  • 📖Sylius Documentation
  • Organization
    • Sylius Team
  • Release Cycle
    • Backwards Compatibility Promise
  • Getting Started with Sylius
    • Installation
    • Basic Configuration
    • Shipping & Payment
    • First Product
    • Customizing the Shop
    • Customizing Business Logic
    • Using API
    • Installing Plugins
    • Deployment
    • Summary
  • The Book
    • Introduction to Sylius
    • Installation
      • System Requirements
      • Sylius CE Installation
        • Sylius CE Installation with Docker
      • ➕Sylius Plus Installation
      • Upgrading Sylius CE
      • Upgrading Sylius Plus
    • Architecture
      • Architecture Overview
      • Architectural Drivers
      • Resource Layer
      • State Machine
      • Translations
      • E-Mails
      • Contact
      • Fixtures
      • Events
    • Configuration
      • Channels
      • Locales
      • Currencies
    • Customers
      • Customer & ShopUser
      • ➕Customer Pools
      • AdminUser
      • Addresses
        • Countries
        • Zones
        • Addresses
        • Address Book
    • Products
      • Products
      • Product Reviews
      • Product Associations
      • Attributes
      • Pricing
      • Catalog Promotions
      • Taxons
      • Inventory
      • ➕Multi-Source Inventory
      • Search
    • Carts & Orders
      • Orders
      • Cart flow
      • Taxation
      • Adjustments
      • Cart Promotions
      • Coupons
      • Payments
      • 🧩Invoices
      • Shipments
    • 🎨Frontend & Themes
    • Support
    • Contributing
      • Contributing Code
        • Submitting a Patch
        • ⚠️Security Issues
        • Coding Standards
        • Conventions
        • Sylius License and Trademark
      • Contributing Translations
      • Key Contributors
  • The Customization Guide
    • Customizing Models
      • How to add a custom model?
      • How to add a custom translatable model?
    • Customizing Forms
      • How to add a live form for a custom model?
    • Customizing Templates
    • Customizing Styles
    • Customizing Dynamic Elements
    • Customizing Validation
    • Customizing Menus
    • Customizing Translations
    • Customizing Flashes
    • Customizing State Machines
    • Customizing Grids
    • Customizing Fixtures
    • Customizing API
    • Customizing Serialization of API
    • Customizing Payments
      • How to integrate a Payment Gateway as a Plugin?
  • 🧑‍🍳The Cookbook
  • How to resize images?
  • How to add one image to an entity?
  • How to add multiple images to an entity?
  • How to add a custom cart promotion action?
  • How to add a custom cart promotion rule?
  • Sylius 1.X Documentation
    • 📓Sylius 1.x Documentation
Powered by GitBook
LogoLogo

Developer

  • Community
  • Online Course

About

  • Team

© 2025 Sylius. All Rights Reserved

On this page
  • Payment
  • Creating a Payment Programmatically
  • Payment State Machine
  • Payment Methods
  • Creating a Payment Method Programmatically:
  • Payment Gateway Configuration

Was this helpful?

Edit on GitHub
  1. The Book
  2. Carts & Orders

Payments

Sylius has a flexible payment management system that integrates with various gateways through the Payum library. Payum handles operations like capturing, refunds, and recurring payments, while Sylius manages payments within the checkout and tracks related payment data.

Payment

Every payment, whether successful or failed, is represented by the Payment model in Sylius. This model includes essential details and links to the related order.

Creating a Payment Programmatically

Payments must be linked to an order. To create a new payment:

$payment = $this->container->get('sylius.factory.payment')->createNew();
$payment->setOrder($order);
$payment->setCurrencyCode('USD');
$this->container->get('sylius.repository.payment')->add($payment);

Payment State Machine

Payments in Sylius have a state machine with states such as: cart, new, processing, completed, failed, cancelled, and refunded.

The available transitions between these states are:

transitions:
    create:
        from: [cart]
        to: new
    process:
        from: [new]
        to: processing
    authorize:
        from: [new, processing]
        to: authorized
    complete:
        from: [new, processing, authorized]
        to: completed
    fail:
        from: [new, processing]
        to: failed
    cancel:
        from: [new, processing, authorized]
        to: cancelled
    refund:
        from: [completed]
        to: refunded

You can add custom states and transitions to fit your workflow. Transitions trigger changes to the payment state.

Payment Methods

PaymentMethod defines how customers pay during checkout and is linked to a payment gateway with custom configurations.

Creating a Payment Method Programmatically:

$paymentMethod = $this->container->get('sylius.factory.payment_method')->createWithGateway('offline');
$paymentMethod->setCode('ALFA1');
$this->container->get('sylius.repository.payment_method')->add($paymentMethod);

Ensure you add the payment method to a channel to make it available:

$paymentMethod->addChannel($channel);

Payment Gateway Configuration

To add a custom gateway, create a configuration form type and tag it with sylius.gateway_configuration_type. Check out examples like PayPal and Stripe for guidance. If you're unsure, refer to the Payum documentation.

Troubleshooting

Sylius saves payment data in the details column of sylius_payment, which can be helpful for debugging.

PayPal Error Code 10409

If you receive the error "Checkout token was issued for a merchant account other than yours," You have most likely changed the PayPal credentials during the checkout process, clear the cache:

bin/console cache:clear

Payment Complete Events

Events such as sylius.payment.pre_complete and sylius.payment.post_complete are dispatched during certain admin actions. Note that these events don’t cover payments completed by gateways. For that, consider adding a callback to the sylius_order_payment state machine for the pay transition.

PreviousCouponsNextInvoices

Last updated 7 months ago

Was this helpful?