Develop Spring Boot based Emojis to Increase Engagement in Digital Transactions

Develop Spring Boot based Emojis to Increase Engagement in Digital Transactions

Everybody like using emoji in social media and my recent article on social payments explained about growing trends of emojis in broadcasting payments. As an example, 'Asking friends or family for money can be awkward, but when you can do it with a smiley face and a winged dollar bill, it seems to make it better'-according to Reuters.

This newsletter focuses on technical implementation possibilities using simple Spring Boot Back-end code development to use three great emojis in broadcasting: ? ????

Economically, the presence of emojis increases the average number of likes by 72% and the average number of comments by 70% in comparison to posts without any emojis

What is Social Payments?

If someone making a donation online for a global cause, broadcasting these payments as opportunities to attract friends and family to donate to take part in these events. Similar social recognitions attract possible increase in engagement to users when the money transfer is for a genuine causes such as donation to cancer research, children wellbeing and many more.


At least 43% of transactions of USA's popular social media payment app, shows that either emoji or emoji in combination of texts being used while posting about respective money transactions!

How long it takes to build such incredible engagement using Emojis do we think? In fact, it is not that long to build a simple Spring Boot based web services for this need! Let us take a look at these steps below.

Introduction

Among the popular technologies, NodeJS and Spring Boot remains a popular choice by developers and my today's choice is Spring Boot since it is easy and scalable to build backend services using Spring Boot.

According to Stackshare, the top 3 pros of Spring Boot have been voted to be:

  • powerful and handy;
  • easy setup;
  • operates on Java (which is highly popular).

Please refer to the latest popular newsletter on Spring Boot to learn about further benefits/advantages of Spring Boot:


Web Service to broadcast transactions with Emojis

? ???? are built as records to integrate to transactions of different senders using backend webservices in this sample service-please feel free to fork here: https://github.com/narayananpalani/emoji-rest-web-services

POM.XML with Spring Dependencies

Update name and description along with dependencies to the pom file to reflect the details of spring boot application:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.1.1</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.pluralsight.springboot</groupId>
	<artifactId>transactions</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>emoji based payment broadcasting</name>
	<description>Spring Boot 3 sample webservice to use emoji in transactions</description>
	<properties>
		<java.version>17</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-validation</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.jetbrains</groupId>
			<artifactId>annotations</artifactId>
			<version>RELEASE</version>
			<scope>compile</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

</project>
        

Application

Use springboot annotations such as @ SpringBootApplication at class to reflect the main class of TransactionApplication to get executed at run time:

package com.socialpay.springboot.transactions;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TransactionsApplication {

	public static void main(String[] args) {
		SpringApplication.run(TransactionsApplication.class, args);
	}

}
        

Spring Boot Records for Payment Broadcasting

Use a record when an object’s only purpose is to contain public data. On other hand, use a class if your object has unique logic. Classes are mutable so even if they have the same data, doesn’t mean they are the same.

For example, if we think about a class that represents a Citizen . Two citizens on a screen can look the same, and have the same name and country, but they are not the same.

Emoji Records

Create record for emoji with respective objects such as name, promotion of such emojis to track the usage patterns.

package com.socialpay.springboot.transactions.emojis;

import java.time.LocalDate;

public record Emoji(
        int id,
        String emojiName,
        Sender sender,
        Mode mode,
        LocalDate promoStartDate,
        LocalDate promoEndDate) {
}
        


Spring Boot Records for Mode of Payment

Creating records with payment modes help in tracking emoji usage from particular payment modes along with send currency and receive currency types to understand where the engagement has been strong and weak to focus on marketing campaigns.

package com.socialpay.springboot.transactions.emojis;

public record Mode(
        int id,
        String payType,
        String duration,
        String sendCCY,
        String receiveCCY) {
}
        

Spring Boot Records for Payment Products

Including records with different payment products such as current accounts, savings accounts help in getting clear insights of engagement patters based on product types.

package com.socialpay.springboot.transactions.emojis;

import java.math.BigDecimal;

public record PaymentProduct(
        int id,
        int payId,
        String paymentType,
        String description,
        BigDecimal transferFee) {
}
        

Spring Boot Records for Senders

Tracking senders records with emoji usages will help locating user demographies and respective engagement patterns:

package com.socialpay.springboot.transactions.emojis;

public record Sender(
        int id,
        String senderName,
        String description) {
}
        

Send Money as Records

Tracking transactions part of webservices as basic core feature to link senders, payment products, emojis and product types:

package com.socialpay.springboot.transactions.sendmoney;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

public record SendMoney(
        Integer id,
        @NotNull(message = "Payment Id is required") Integer paymentId,
        String transactionCode,
        @NotBlank(message = "Sender name is required") String senderName) {
}
        

Repository Creation

Once records are created, focusing on building internal repository of data would be helpful to populate REST responses. Ideal state is to use DB for a data management but it has been simplified using respository for a sample usage.

Emoji Repository

package com.socialpay.springboot.transactions.emojis;

import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

@Repository
public class EmojiRepository {

    private final List<Emoji> emojis = List.of(
            new Emoji(501, "Check Mark Button",
                    new Sender(101, "David", "Sending Money for Family needs"),
                    new Mode(201, "faster pay", "2 seconds", "GBP", "INR"),
                    LocalDate.of(2023, 10, 2), LocalDate.of(2023, 10, 4)),
            new Emoji(502, "Fire",
                    new Sender(101, "George", "Sending money to own account"),
                    new Mode(201, "faster pay", "1 sec", "GBP", "INR"),
                    LocalDate.of(2024, 1, 10), LocalDate.of(2024, 1, 10)),
            new Emoji(503, "Smiling Face",
                    new Sender(102, "Jamilia", "Donations"),
                    new Mode(202, "future pay", "3 days", "GBP", "CAD"),
                    LocalDate.of(2024, 2, 29), LocalDate.of(2024, 2, 29)));

    public List<Emoji> findBySenderId(int senderId) {
        return emojis.stream().filter(emoji -> emoji.sender().id() == senderId).toList();
    }

    public Optional<Emoji> findById(int id) {
        return emojis.stream().filter(emoji -> emoji.id() == id).findAny();
    }
}
        

Mode of Payment Repository

package com.socialpay.springboot.transactions.emojis;

import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public class ModeRepository {

    private final List<Mode> modes = List.of(
            new Mode(201, "faster pay", "10 seconds", "GBP", "INR"),
            new Mode(202, "future pay", "3 days", "GBP", "CAD"));

    public Optional<Mode> findById(int id) {
        return modes.stream().filter(mode -> mode.id() == id).findAny();
    }
}
        

Payment Product Repository

package com.socialpay.springboot.transactions.emojis;

import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public class PaymentProductRepository {

    private final List<PaymentProduct> paymentProducts = List.of(
            new PaymentProduct(801, 501, "Classic", "current account", new BigDecimal("10.00")),
            new PaymentProduct(802, 501, "Premium", "Premium account", new BigDecimal("8.00")),
            new PaymentProduct(803, 502, "Gold", "Gold account", new BigDecimal("1.50")),
            new PaymentProduct(804, 503, "Silver", "Silver Account", new BigDecimal("1.00")),
            new PaymentProduct(805, 503, "Platinum", "Platinum Account", new BigDecimal("0.00")));

    public List<PaymentProduct> findByEmojiId(int emojiId) {
        return paymentProducts.stream().filter(paymentProduct -> paymentProduct.payId() == emojiId).toList();
    }
}
        

Sender Repository

package com.socialpay.springboot.transactions.emojis;

import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SenderRepository {

    private final List<Sender> senders = List.of(
            new Sender(101, "David", "Current Acc Setup"),
            new Sender(102, "George", "Savings Acc Setup"));

    public List<Sender> findAll() {
        return senders;
    }
}
        

Send Money as Repository

package com.socialpay.springboot.transactions.sendmoney;

import org.springframework.stereotype.Repository;

import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

@Repository
public class SendMoneyRepository {

    private static final AtomicInteger ID_GENERATOR = new AtomicInteger();

    private final Map<String, SendMoney> registrationByTransactionCode = new ConcurrentHashMap<>();

    public SendMoney create(SendMoney sendmoney) {
        int id = ID_GENERATOR.incrementAndGet();
        String transactionCode = UUID.randomUUID().toString();

        var saved = new SendMoney(id, sendmoney.paymentId(), transactionCode, sendmoney.senderName());
        registrationByTransactionCode.put(transactionCode, saved);
        return saved;
    }

    public Optional<SendMoney> findByTransactionCode(String transactionCode) {
        return Optional.ofNullable(registrationByTransactionCode.get(transactionCode));
    }

    public SendMoney update(SendMoney sendmoney) {
        String transactionCode = sendmoney.transactionCode();

        var opt = findByTransactionCode(transactionCode);
        if (opt.isPresent()) {
            var existing = opt.get();

            var saved = new SendMoney(existing.id(), existing.paymentId(), existing.transactionCode(), sendmoney.senderName());
            registrationByTransactionCode.put(transactionCode, saved);
            return saved;
        } else {
            throw new NoSuchElementException("Send money with transaction code " + transactionCode + " not found");
        }
    }

    public void deleteByTransactionCode(String transactionCode) {
        registrationByTransactionCode.remove(transactionCode);
    }
}
        


Controllers

Once records and repository build, linking them via controllers help in buiding the RESTful services with endpoints

The concept of the Front Controller in the typical Spring Model View Controller architecture is simple.

At a very high level, the main responsibilities include:

  • intercepting incoming requests
  • converting the payload of the request to the internal structure of the data
  • sending the data to Model for further processing
  • getting processed data from the Model, and advancing that data to the View for rendering

Emoji Controller

package com.socialpay.springboot.transactions.emojis;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.NoSuchElementException;

@RestController
public class EmojiController {

    private final SenderRepository senderRepository;
    private final EmojiRepository emojiRepository;
    private final PaymentProductRepository paymentProductRepository;

    public EmojiController(SenderRepository senderRepository,
                           EmojiRepository emojiRepository,
                           PaymentProductRepository paymentProductRepository) {
        this.senderRepository = senderRepository;
        this.emojiRepository = emojiRepository;
        this.paymentProductRepository = paymentProductRepository;
    }

    @GetMapping(path = "/senders")
    public List<Sender> getSenders() {
        return senderRepository.findAll();
    }

    @GetMapping(path = "/emojis")
    public List<Emoji> getEmojisBySender(@RequestParam("senderId") int senderId) {
        return emojiRepository.findBySenderId(senderId);
    }

    @GetMapping(path = "/emojis/{id}")
    public Emoji getEmojiById(@PathVariable("id") int emojiId) {
        return emojiRepository.findById(emojiId)
                .orElseThrow(() -> new NoSuchElementException("Event with id " + emojiId + " not found"));
    }

    @GetMapping(path = "/PaymentProducts")
    public List<PaymentProduct> getPaymentProductsByEmoji(@RequestParam("emojiId") int emojiId) {
        return paymentProductRepository.findByEmojiId(emojiId);
    }
}
        

SendMoney Controller

package com.socialpay.springboot.transactions.sendmoney;

import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.NoSuchElementException;

@RestController
@RequestMapping(path = "/SendMoney")
public class SendMoneyController {

    private final SendMoneyRepository sendmoneyRepository;

    public SendMoneyController(SendMoneyRepository sendmoneyRepository) {
        this.sendmoneyRepository = sendmoneyRepository;
    }

    @PostMapping
    public SendMoney create(@RequestBody @Valid SendMoney sendmoney) {
        return sendmoneyRepository.create(sendmoney);
    }

    @GetMapping(path = "/{transactionCode}")
    public SendMoney get(@PathVariable("transactionCode") String transactionCode) {
        return sendmoneyRepository.findByTransactionCode(transactionCode)
                .orElseThrow(() -> new NoSuchElementException("Send money with transaction code " + transactionCode + " not found"));
    }

    @PutMapping
    public SendMoney update(@RequestBody SendMoney sendmoney) {
        return sendmoneyRepository.update(sendmoney);
    }

    @DeleteMapping(path = "/{transactionCode}")
    public void delete(@PathVariable("transactionCode") String transactionCode) {
        sendmoneyRepository.deleteByTransactionCode(transactionCode);
    }
}
        

Exception Handlers

Exception handling is a very important part of developing applicationsIn this section, will introduce how to use RestControllerAdvice and ExceptionHandler to handle Exception

Once records, repository and controllers are developed, handing exceptions at centre of the webservice will help in managing negative scenarios:

package com.socialpay.springboot.transactions;

import org.springframework.http.HttpStatus;
import org.springframework.web.ErrorResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.NoSuchElementException;

@RestControllerAdvice
public class ControllerExceptionHandler {

    @ExceptionHandler(NoSuchElementException.class)
    public ErrorResponse notFound(NoSuchElementException ex) {
        return ErrorResponse.create(ex, HttpStatus.NOT_FOUND, ex.getMessage());
    }
}
        

Rest API Calls

Now the application has been built and let us take a look at some of the REST end point usage for the REST responses using emojis:

Identify Payments with Emojis using Senders

Request:

GET localhost:8080/emojis?senderId=101        

Response:

Response:

[
    {
        "id": 501,
        "emojiName": "Check Mark Button",
        "sender": {
            "id": 101,
            "senderName": "David",
            "description": "Sending Money for Family needs"
        },
        "mode": {
            "id": 201,
            "payType": "faster pay",
            "duration": "2 seconds",
            "sendCCY": "GBP",
            "receiveCCY": "INR"
        },
        "promoStartDate": "2023-10-02",
        "promoEndDate": "2023-10-04"
    },
    {
        "id": 502,
        "emojiName": "Fire",
        "sender": {
            "id": 101,
            "senderName": "George",
            "description": "Sending money to own account"
        },
        "mode": {
            "id": 201,
            "payType": "faster pay",
            "duration": "1 sec",
            "sendCCY": "GBP",
            "receiveCCY": "INR"
        },
        "promoStartDate": "2024-01-10",
        "promoEndDate": "2024-01-10"
    }
]        

Identify Senders List

localhost:8080/senders        

Response:


[
    {
        "id": 101,
        "senderName": "David",
        "description": "Current Acc Setup"
    },
    {
        "id": 102,
        "senderName": "George",
        "description": "Savings Account Setup"
    }
]        

Identify Payments Usage of particular Emoji

Endpoint:

GET localhost:8080/emojis/501        

Response:


{
    "id": 501,
    "emojiName": "Check Mark Button",
    "sender": {
        "id": 101,
        "senderName": "David",
        "description": "Sending Money for Family needs"
    },
    "mode": {
        "id": 201,
        "payType": "faster pay",
        "duration": "2 seconds",
        "sendCCY": "GBP",
        "receiveCCY": "INR"
    },
    "promoStartDate": "2023-10-02",
    "promoEndDate": "2023-10-04"
}        

Identify Payment Products that used selective Emojis

Endpoint

localhost:8080/PaymentProducts?emojiId=501        

Response:


[
    {
        "id": 801,
        "payId": 501,
        "paymentType": "Classic",
        "description": "current account",
        "transferFee": 10.00
    },
    {
        "id": 802,
        "payId": 501,
        "paymentType": "Premium",
        "description": "Premium account",
        "transferFee": 8.00
    }
]        

Update a Payment with Sender details

Endpoint:

localhost:8080/SendMoney        

Response:


{
    "id": 2,
    "paymentId": 801,
    "transactionCode": "ea8cd4fc-f757-487d-bb16-a08a734f9b38",
    "senderName": "Jesper de Jong"
}        


Delete a Payment Transaction

Endpoint:

localhost:8080/SendMoney/06804b2e-3e75-4efb-9594-8cedadb33ec9        

Response:

Summary

Broadcasting any transactions with emoji are super cool features to digital apps and websites; If it is served via webservice, will be easy to control and manage on availability, scalability and maintainability when user demand increases at peak times.

Credits: Unsplash

How do you find this article on technical development of emoji based transaction broadcasting using Spring Boot? Please leave your comments.


Keywords: #FinancialServices #FinTech #innovation #technology #digitalmarketing #management #creativity #future #socialmedia #socialnetworking #socialentrepreneurship #customerrelations


Disclaimer: Contents, posts and media used in this account of the author do not represent any organisation of any sort. Under no circumstances will the author be held responsible or liable in any way for any claims, loss, expenses or liabilities whatsoever.


Like this article? Subscribe to Engineering Leadership , Digital Accessibility and Digital Payments Hub to enjoy reading useful articles. Press SHARE and REPOST button to help sharing the content with your network.

#LinkedInNewsUK #FinanceLeadership


Lian Wee ?? LOO

Business Operations Strategist | Digital Transformation Evangelist | AI Enthusiast | Tech Gadgets Lover | Foodie | Kindness

4 个月

Great perspective!

Aaron Spence

International Business Coach and Mentor | Every business owner deserves to have a successful and profitable business

4 个月

Inspiring!

Prosper Daniel

Using Softr and Airtable to help streamlining business workflows, automation for empowering data-driven insights for profitability in Website, Client Portal, Job Board and internal tools. Let's talk about Your Business.

4 个月

Good points

Dr. Nasir Bukhari

Emergency, Orthopedic & Trauma Surgery Doctor | Professional Crypto Trader & Analyst | Hedge Funds Manager | English Mentor On YouTube

4 个月

Useful insights on Spring Boot usage

要查看或添加评论,请登录

NARAYANAN PALANI的更多文章

社区洞察

其他会员也浏览了