Code Monkey home page Code Monkey logo

payments's Introduction

Payments

Dummy payments gateway written with Java SpringBoot

CircleCI

Docker Hub Image: https://hub.docker.com/repository/docker/hashicorpdemoapp/payments

Usage

Currently this API has a single endpoint at POST /

See below for how to use each controller. You can override any of the default property files using external config for Spring.

The most simple option to override is place the files in the current directory.

Health Checks

Spring Actuator is enabled for health checks.

curl -s localhost:8080/actuator/health | jq
{
  "status": "UP",
  "components": {
    "db": {
      "status": "UP",
      "details": {
        "database": "H2",
        "validationQuery": "isValid()"
      }
    },
    "discoveryComposite": {
      "description": "Discovery Client not initialized",
      "status": "UNKNOWN",
      "components": {
        "discoveryClient": {
          "description": "Discovery Client not initialized",
          "status": "UNKNOWN"
        }
      }
    },
    "diskSpace": {
      "status": "UP",
      "details": {
        "total": 499963174912,
        "free": 233270890496,
        "threshold": 10485760,
        "exists": true
      }
    },
    "ping": {
      "status": "UP"
    },
    "refreshScope": {
      "status": "UP"
    }
  }
}

Controllers

There are three controllers you can configure to process a payment from the HashiCups app:

REST Controller

This REST controller is configured by default and no additional steps are required.

curl -s -X POST --header "Content-Type: application/json" --data /
'{"name": "Gerry", "type": "mastercard", "number": "1234-1234-1234-1234", "expiry": "01/23", "cvc": "123"}' localhost:8080  | jq
{
  "message": "Payment processed successfully, card details returned for demo purposes, not for production",
  "id": "5cc26d60-bc28-4a22-ab59-853ef9b0c209",
  "card_plaintext": "1234-1234-1234-1234",
  "card_ciphertext": "Encryption Disabled"
}

Redis Controller

The Redis controller will enable when the app.storage=redis property is configured. Below is an example with Vault transit encryption enabled.

vault.sh:

vault secrets enable transit
vault write -f transit/keys/payments

application.properties:

app.storage=redis
app.encryption.enabled=true
app.encryption.path=transit
app.encryption.key=payments
spring.redis.host=localhost
spring.redis.port=6379

example:

curl -s -X POST --header "Content-Type: application/json" --data '{"name": "Gerry", "type": "mastercard", "number": "1234-1234-1234-1234", "expiry": "01/23", "cvc": "123"}' localhost:8080  | jq
{
  "card_plaintext": "1234-1234-1234-1234",
  "message": "Payment processed successfully, card details returned for demo purposes, not for production",
  "id": "2de542c7-1f7f-4e81-b35a-7a099b23ca92",
  "card_ciphertext": "vault:v1:Z3HhB77mWXbJl4WaJMWq9vJ16lWGIm9TnWZ3bFsmbZ3YD7QwIx3cd6clMbSKRgM="
}

DB Controller

The DB controller will enable when the app.storage=db property is configured. Below is an example with Vault transit encryption enabled. The default database for the controller is the H2 embedded database and requires no additional configuration. The console for the database is located at /h2-console. You can login with sa & password credentials.

vault.sh:

vault secrets enable transform
vault write transform/role/payments transformations=card-number
vault write transform/transformation/card-number \
        type=fpe \
        template="builtin/creditcardnumber" \
        tweak_source=internal \
        allowed_roles=payments

application.properties:

app.storage=db
app.encryption.enabled=true
app.encryption.path=transform
app.encryption.key=payments

example:

curl -s -X POST --header "Content-Type: application/json" --data '{"name": "Gerry", "type": "mastercard", "number": "1234-1234-1234-1234", "expiry": "01/23", "cvc": "123"}' localhost:8080  | jq
{
  "card_plaintext": "1234-1234-1234-1234",
  "card_ciphertext": "9044-9922-3580-9604",
  "message": "Payment processed successfully, card details returned for demo purposes, not for production",
  "id": "1"
}

Postgres Support

Postgres is supported as an external DB. Below is an override configuration.

application.yml

spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/postgres
    username: postgres
    password: postgres
  jpa:
    hibernate:
      ddl-auto: update 
    show-sql: true
    database: postgresql
    database-platform: org.hibernate.dialect.PostgreSQLDialect
    open-in-view: false
    generate-ddl: true
    properties:
      hibernate:
        temp:
          use_jdbc_metadata_defaults: false
management:
  endpoint:
    health:
      show-details: always
  endpoints:
    web:
      exposure:
        include: '*'

Vault Encryption

Vault encryption is available for the Redis controller leveraging transit, and the DB payment controller leveraging transform.

You will need to provide a valid bootstrap file pointing to your Vault instance to enable the Vault integration. Below is an example for token authentication. See the Spring Cloud Vault documentation for all available auth methods.

bootstrap.yaml

spring:
  cloud:
    vault:
      enabled: true
      fail-fast: true
      authentication: TOKEN
      token: root
      host: localhost
      port: 8200
      scheme: http

Tracing

The app exposes Jaeger options that are documented here.

payments's People

Contributors

lanceplarsen avatar nicholasjackson 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.