Giter VIP home page Giter VIP logo

paymentprocessorapi's Introduction

PaymentProcessorAPI

The API Controller has function that responds for POST request which is useful for processing the payment, inserting the state of the payment and transaction details in the database table by receiving the credit card details.

Problem Statement

Write a WebAPI with only 1 method called “ProcessPayment” that receives a request like this:

  • CreditCardNumber (mandatory, string, it should be a valid CCN)
  • CardHolder: (mandatory, string)
  • ExpirationDate (mandatory, DateTime, it cannot be in the past)
  • SecurityCode (optional, string, 3 digits)
  • Amount (mandatoy decimal, positive amount)

Write a Payment domain/entity with the same properties as the request and a second entity to store the payment state (pending, processed, failed). Use Entity framework code first approach, write entity configurations and generate the migrations. The response of this method should be 1 of the followings based on

  • Payment is processed: 200 OK
  • The request is invalid: 400 bad request
  • Any error: 500 internal server error
  • The request should be validated before processed.

The payment could be processed using different payment providers (external services) called:

  • IExpensivePaymentGateway or
  • ICheapPaymentGateway.

The payment gateway that should be used to process each payment follows the next set of business rules

  1. If the amount to be paid is less than £20, use ICheapPaymentGateway.
  2. If the amount to be paid is £21-500, use IExpensivePaymentGateway if available. Otherwise, retry only once with ICheapPaymentGateway.
  3. If the amount is > £500, try only PremiumPaymentService and retry up to 3 times in case payment does not get processed
  4. Store/update the payment and payment state entities created previously once the processing is completed.

DB Creation

  • Set db connection string in appsettings.json
  • Open Package Manager Console
  • Set project to Entity.
  • Set Startup project to WebApi.
  • Run command:
update-database

This should set up database according to the Entity Migrations. Once the database and tables are created, We are all set to run the application.

Example of POSTMAN call

Note: 44374 is the port number

POST

Example 1

Call URL https://localhost:44374/api/pay with POST with JSON:

{
    "creditCardNumber": "5555 5555 5555 4444",
    "cardHolder": "Rajesh G",
    "expirationDate": "2021-06-02",
    "securityCode": "123",
    "amount": 600
}

Response:

{
    "isProcessed": true,
    "paymentState": {
        "paymentState": 1,
        "paymentStateDate": "2021-05-17T03:12:16.861417Z"
    }
}

POST

Example 2

Call URL https://localhost:44374/api/pay with POST with JSON:

{
    "creditCardNumber": "4012 8888 8888 1881",
    "cardHolder": "Rajesh G",
    "expirationDate": "2021-06-02",
    "securityCode": "125",
    "amount": 15
}

The post call should return a response like this if it is successful:

{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.6.1",
    "title": "An error occured while processing your request.",
    "status": 500,
    "traceId": "|c699ec21-4e0dd363dcff01cb."
}

If it is faild:

{
    "error": "Payment could not be processed"
}

GET

Call URL https://localhost:44374/api/pay with GET
This Should return the following response if the application is online

Payment Processor is online

paymentprocessorapi's People

Contributors

rajeshreddyg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.