Skip to content

mohllal/payment-transaction-data-processor

Repository files navigation

Payment Transaction Data Processor

A backend service code challenge using Golang.

The main idea of the task is to build an API that read the payment transaction data from files (JSON format) and return them in the API response as JSON format. There are two payment providers flypayA and flypayB.

You can find the full description for the task here.

NOTE: This my first time code in Golang so there may be a lot to improve.

Prerequisites:

The application was built using Golang so you should have it installed on your machine to be able to run it.

Or you can run it through Docker.

Usage:

  1. Download or clone this repository to your machine.

  2. Build the Docker image:

    docker build -t go-challenge .
  3. Create a container from the generated image:

    docker run --rm --name go-challenge -p 5000:5000 go-challenge
  4. You can run the service directly using:

    go run main.go
  5. Unit tests can be run through:

    go test -v
  6. Benchmarking can be run through:

    go test -bench=.

NOTE: A Postman Collection for the API endpoints can be found here.

Code Scalabilty:

How can we add a new payment provider like flypayC with a new schema?

  1. Add flypayC.json file to the data directory.

  2. Add new Model for flypayC.go in the models directory:

    • FlypayCTransactions struct that implements the Transactions interface.
    • FlypayCTransaction struct that implements the Transaction interface.
    • FlypayCStatusCodeMapping map that maps the statusCode for the flypayC.json schema.
  3. In the data.go file, add the following lines in the LoadAllTransactions function:

    • var flyCTransactions = models.Transactions.Load(models.FlypayCTransactions{})
    • Append flyCTransactions to the transactions slice as follows: transactions.append(transactions, flyCTransactions...).

Challanges (TO-DO):

Using Decoder to read a JSON file as input stream to reduce the huge spike in memory usage in reading large files.

Problem: Reading JSON files with a non top-level array like flypayA.json and flypayB.json.

License:

This software is licensed under the MIT License.

About

A backend service in Golang to process large payment transaction data from files.

Topics

Resources

Stars

Watchers

Forks