Skip to content

This is a fake payment provider that simulates a payment provider. It is used for testing purposes.

Notifications You must be signed in to change notification settings

erichnascimento/fake-payment-provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fake Payment Provider

.NET

This is a fake payment provider that simulates a payment provider. It is used for testing purposes.

Table of Contents

Installation

TODO

Usage

TODO

API

POST /v1/payments

This endpoint simulates a payment request. It will return a 201 status code if the payment was successful, and a 400 status code if the payment failed.

Create a credit card payment

Request body:

{
  "amount": 100.01,
  "currency": "BRL",
  "paymentMethod": "creditcard",
  "payer": {
    "name": "John Doe",
    "email": "johndoe@example.com",
    "cellPhoneNumber": "5511999887654",
    "document": {
      "type": "CPF",
      "number": "12345678909"
    },
    "address": {
      "street": "Rua dos Bobos",
      "number": "10",
      "complement": "Sala 1",
      "neighborhood": "Centro",
      "city": "São Paulo",
      "state": "SP",
      "country": "BR",
      "zipCode": "80100200"
    },
    "card": {
      "number": "4242424242424242",
      "holderName": "John Doe",
      "expiration": "12/2023",
      "cvc": "123",
      "store": true
    }
  },
  "paymentCode": "123456",
  "postbackUrl": "https://localhost:3000/postback?t=a4577&paymentCode=123456"
}

Response:

201 Created

{
  "id": "e5a78634-6d25-43b0-8d4f-c1bc57496d4c",
  "paymentCode": "123456",
  "status": "confirmed",
  "authorizationCode": "123456",
  "cardToken": "f7b1b8b0-1b7b-4b6b-8b1b-0b1b7b4b6b8b"
}

Create a boleto payment

Request body:

{
  "amount": 100.01,
  "currency": "BRL",
  "paymentMethod": "boleto",
  "dueDate": "2021-12-31",
  "withPix": true,
  "payer": {
    "name": "John Doe",
    "email": "johndoe@example.com",
    "cellPhoneNumber": "5511999887654",
    "document": {
      "type": "CPF",
      "number": "12345678909"
    },
    "address": {
      "street": "Rua dos Bobos",
      "number": "10",
      "complement": "Sala 1",
      "neighborhood": "Centro",
      "city": "São Paulo",
      "state": "SP",
      "country": "BR",
      "zipCode": "80100200"
    }
  },
  "paymentCode": "123456",
  "postbackUrl": "https://localhost:3000/postback?t=a4577&paymentCode=123456"
}

Response:

201 Created

{
  "id": "e5a78634-6d25-43b0-8d4f-c1bc57496d4c",
  "paymentCode": "123456",
  "status": "Pending",
  "boleto": {
    "number": "12345678901234",
    "barcode": "34191510047910201500085012345678901234",
    "digitableLine": "34191.09008 63521.510047 91020.150008 5 12345678901234",
    "dueDate": "2021-12-31"
  },
  "pix": {
    "copyPaste": "00020126580014br.gov.bcb.pix0136123e4567-e12b-12d1-a456-426655440000 5204000053039865802BR5913Fulano de Tal6008BRASILIA62070503***63041D3D",
    "qrCodeBase64": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAB...",
    "dueDate": "2021-12-31"
  }
}

POST /v1/payments/{id}/confirm

Confirm a boleto payment

Request body:

{
    "paymentMethod": "boleto",
    "paidAmount": 100.01,
    "paidOn": "2021-12-31"
}

Response:

200 OK

{
  "id": "e5a78634-6d25-43b0-8d4f-c1bc57496d4c",
  "paymentCode": "123456",
  "status": "confirmed",
  "paidAmount": 100.01,
  "paidOn": "2021-12-31"
}

Development

The architecture of this project is based on the Clean Architecture principles.

The project is divided into the following layers:

  • Domain: Contains the business rules and entities of the application.
  • Infra: Contains the concrete implementation of the interfaces defined in the Domain layer.
  • WebApiApplication: Contains the web API and the presentation layer of the application.
  • Library: Contains the shared code between the layers.

Prerequisites

TODO

Running the server

dotnet run

The server will start at http://localhost:5246.

You can test the API using IntelliJ HTTP Client file at ./http-client/fake-payment-provider.http.

Create a boleto payment example:

POST http://localhost:5246/v1/payments
Content-Type: application/json

{
  "paymentMethod": "boleto",
  "amount": 100,
  "currency": "BRL",
  "dueDate": "2024-08-31"
}

Response

HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8

{
  "id": "e5a78634-6d25-43b0-8d4f-c1bc57496d4c",
  "status": "Pending",
  "boleto": {
    "number": "34191.09008 63521.510047 91020.150008 5 12345678901234",
    "barcode": "34191510047910201500085012345678901234",
    "dueDate": "2024-08-31"
  }
}

Server logs

2024-07-20 01:13:37.478 INFO  Http Request:             request={PaymentMethod=boleto, Amount=100, Currency=BRL ... }
2024-07-20 01:13:37.480 INFO  Http Request: status=201  request={PaymentMethod=boleto, Amount=100, Currency=BRL}  response={Id=e5a78634-6d25-43b0-8d4f-c1bc57496d4c, Status=pending ... }

Running the tests

dotnet test

Roadmap

  • Implements the payment boleto creation 🏁
  • Implements the payment boleto confirmation 🏁
  • Implements the payment credit card creation (in progress ⏳)
  • Implements the payment credit card confirmation
  • Implements the payment credit card cancelation
  • Implements the payment credit card refund
  • Implements error simulation

License

This project is licensed under the MIT License.