"Getting started with Sylius" training sessions now available in various cities in Europe!

Blog

Welcome to our blog, where we share news related to Sylius and post about technology & eCommerce.

Bartosz Pietrzak
31.10.2018 | 3 mins read

Refund Plugin

Hello everyone!

Today is the second time I am going to talk about Sylius plugins developed by the Sylius Core Team. Since we have covered the topic of reordering a previously placed order by a customer, let’s assume that the delivered product was damaged or its variant is not the one you have ordered.

Here comes the Refund Plugin!

Introduction

Before the Refund Plugin was released, Sylius had allowed refunding an order once the customer contacted the administrator personally and had discussed every detail via e-mail or phone. What’s more, refunding whole order’s total was the only possible option. Briefly speaking, it was up to two individuals to begin, endure and complete the whole process with a negligible impact of Sylius itself.

What was wrong with that approach? Firstly, it did not offer a wide range of possibilities and business value. Secondly, Sylius purpose is Catalyze trade with technology – the previous version of refund functionality was hardly assembling any eCommerce domain elements. Hence, the necessity of extending such an essential feature as refunds was placed high in our backlog.

What is the Refund Plugin?

At first, it is another Sylius extension developed by the Sylius Core Team. Let’s see what it has to offer:

  • Refunding an order once it’s paid
  • The possibility of refunding a partial amount of an order item or a shipment
  • Refunding one order several times – once a whole order’s total is refunded the order becomes fully refunded
  • Generating a credit memo for each refund action and sending it as a PDF document to the customer via e-mail
  • Customer downloading the generated credit memos as PDF files
  • Generating a refund payment that represents shop’s will to refund a specific amount of money in favor of the customer

How does it work code-wise?

The core functionality is based on both commands and events. The business logic process, from receiving a request by a controller to displaying a successful notification, is following:

  • The controller dispatches the RefundUnits command containing payload taken from the HTTP request;
  • The command reaches the RefundUnitsCommandHandler. It is validated and then processed;
  • Each item mentioned in command’s payload is refunded separately, and the UnitRefunded event is dispatched after every successful refund;
  • Once the RefundUnits command is successfully processed the UnitsRefuned event is dispatched;
  • The UnitsRefunded event is processed by two process managers – CreditMemoProcessManager and RefundPaymentProcessManager. The first one creates a document called Credit Memo and the other one is responsible for generating a Refund Payment.

Apart from the refund feature, the plugin involves a lot of both custom and Resource-related logic. As usual, since the Refund, Credit Memo and Refund Payment entities are Sylius resources, the basic CRUD actions and grid are defined in the config.yml file. On the other hand, features such as downloading a credit memo or marking a refund payment as completed have their own related single action controllers.

How to get it?

Like any other Sylius plugin developed by the Sylius Core Team, the Refund Plugin is an open-source project available via Github, which means that cloning or forking the repository can be done anywhere, anytime, by everyone. We are elated to deliver another customizable feature to our community. Feel free to keep us up to date with your user/developer experience – our sole focus is to create software which is as developer friendly as possible and thus we are looking forward to receiving your feedback.

Happy refunding!

 

Bartosz Pietrzak
See my roles

Software developer fond of trying new technologies and challenges. A huge fan of clean code and applying multiple levels of application testing. After hours a keen alternative music listener and a guitarist - that's why you rarely see him without his headphones on. If you want to talk about programming or heavy guitar riffs - you've met a proper person.

Be the first to find out about new posts. Join to our newsletter!