Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d9e8ff8
Bump junit-platform-launcher from 1.9.2 to 1.9.3
dependabot[bot] Apr 27, 2023
c1c007d
Bump maven-failsafe-plugin from 2.22.0 to 3.1.0
dependabot[bot] May 8, 2023
d35a6e3
Inital design of PaymentsResource.
mbjones May 13, 2023
ad50e64
Modified PaymentsResource to convert JSON to Payment instance.
mbjones May 16, 2023
dcdd9e8
Log payment transaction identifier.
mbjones May 16, 2023
bb1717e
Add VS Code config files to gollow Google style standards, and launch…
mbjones May 16, 2023
bc623fd
Implement hash validation for payments. Reformat PaymentsResource.
mbjones May 16, 2023
b86cfa3
Prepare 0.6.0 release for Docker and helm upgrades.
mbjones May 16, 2023
daa56ee
Merge remote-tracking branch 'origin/dependabot/maven/develop/org.jun…
mbjones May 18, 2023
7e0460b
Merge remote-tracking branch 'origin/dependabot/maven/develop/org.apa…
mbjones May 18, 2023
9f00f0c
Upgrade embedded-pg to 0.13.4
mbjones May 18, 2023
8e2172c
Switch database test from EmbeddedPostgres to Testcontainers.
mbjones Jun 3, 2023
7e323e3
Add initial draft of payment transactions table.
mbjones Jun 3, 2023
809e1a8
Drafted PaymentStore and PaymentStoreTest.
mbjones Jun 3, 2023
3837eef
Merge branch 'develop' into feature-93-payments
mbjones Aug 8, 2024
c064f76
Continue implementation of PaymentsResource, get test running.
mbjones Aug 8, 2024
6cb20fe
Merge branch 'develop' into feature-93-payments
mbjones Aug 8, 2024
87414b0
Merge branch 'develop' into feature-93-payments
mbjones Aug 21, 2024
5095bc8
Change signature on PaymentStore.delete, and test listPayments() and …
mbjones Aug 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
337 changes: 337 additions & 0 deletions .vscode/eclipse-java-google-style.xml

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [



{
"type": "java",
"name": "Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Bookkeeper",
"request": "launch",
"mainClass": "org.dataone.bookkeeper.Bookkeeper",
"projectName": "bookkeeper",
"args": "server deployments/bookkeeper.yml"
}
]
}
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
FROM openjdk:8-jre
FROM eclipse-temurin:17.0.7_7-jre-jammy

LABEL org.opencontainers.image.source="https://github.com/dataoneorg/bookkeeper"
LABEL org.opencontainers.image.title="DataONE Bookkeeper"
LABEL org.opencontainers.image.version="0.5.0"
LABEL org.opencontainers.image.version="0.6.0"
LABEL org.opencontainers.image.url="https://github.com/DataONEorg/bookkeeper"
LABEL maintainer="DataONE support@dataone.org"
LABEL maintainer="DataONE <support@dataone.org>"

RUN mkdir -p /app/bookkeeper

WORKDIR /app/bookkeeper

# The bookkeeper configuration is obtained from a persistent volume mounted at /opt/local/

COPY target/bookkeeper-0.5.0.jar bookkeeper.jar
COPY target/bookkeeper-0.6.0.jar bookkeeper.jar

EXPOSE 8080 8081

Expand Down
16 changes: 16 additions & 0 deletions bookkeeper.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"folders": [
{
"path": "."
},
{
"path": "../bookkeeper-api"
}
],
"settings": {
"esbonio.sphinx.confDir": "",
"java.format.settings.url": ".vscode/eclipse-java-google-style.xml",
"java.configuration.updateBuildConfiguration": "interactive",
"java.compile.nullAnalysis.mode": "disabled"
}
}
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.9.1
version: 0.10.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.5.0"
appVersion: "0.6.0"
40 changes: 40 additions & 0 deletions helm/db/migrations/V1.14__Create_Payments_Table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--- Note that this is completed in k8s via the Dockerfile
--- or via a shell script in non-k8s development envs

CREATE TABLE IF NOT EXISTS payments (
transactionId text PRIMARY KEY,
orderId integer NOT NULL,
accountId text,
timestamp text,
count text,
hash text,
authorizationCode text,
authorizationMessage text,
requestAmount float,
transactionAmount float,
products text,
transactionApproved integer,
transactionTimestamp text,
updated timestamp with time zone,
FOREIGN KEY (orderId) REFERENCES orders (id) ON DELETE CASCADE
);

CREATE INDEX payments_order_idx ON payments USING btree(orderId);
CREATE INDEX payments_transaction_idx ON payments USING btree(transactionId);

COMMENT ON TABLE payments IS 'Payment transactions for Orders.';
COMMENT ON COLUMN payments.transactionId IS 'The unique identifier of the transaction from the payment processor.';
COMMENT ON COLUMN payments.orderId IS 'The identifier of the order to which this payment applies.';
COMMENT ON COLUMN payments.accountId IS 'The account identifier for this order.';
COMMENT ON COLUMN payments.timestamp IS 'The string timestamp when the transaction was verified, used in the hash.';
COMMENT ON COLUMN payments.count IS 'The count of transactions in a request, should be 1.';
COMMENT ON COLUMN payments.hash IS 'The verification hash from the payment processor for the transaction message.';
COMMENT ON COLUMN payments.authorizationCode IS 'The authorization code for this payment.';
COMMENT ON COLUMN payments.authorizationMessage IS 'The authorization message corresponding to the auth code.';
COMMENT ON COLUMN payments.requestAmount IS 'The requested payment amount.';
COMMENT ON COLUMN payments.transactionAmount IS 'The actual transaction amount.';
COMMENT ON COLUMN payments.products IS 'The text summary of the products in the order.';
COMMENT ON COLUMN payments.transactionApproved IS 'The flag with value 1 indicating if the transaction was approved.';
COMMENT ON COLUMN payments.transactionTimestamp IS 'The string representation of the time the transaction was requested.';
COMMENT ON COLUMN payments.updated IS 'The datetime on which this record was updated in the payments table.';

5 changes: 5 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ spec:
secretKeyRef:
name: postgres-credentials
key: password
- name: PAYMENT_API_KEY
valueFrom:
secretKeyRef:
name: payment-credentials
key: api_key
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand Down
18 changes: 10 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.dataone</groupId>
<artifactId>bookkeeper</artifactId>
<version>0.5.0</version>
<version>0.6.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dropwizard.version>2.0.0</dropwizard.version>
Expand All @@ -29,7 +29,7 @@
<!-- <docker.registry>docker.io</docker.registry> -->
<docker.repo>d1bookkeeper</docker.repo>
<docker.tag>0.3.0</docker.tag>
<bookkeeper-api.version>1.0.0</bookkeeper-api.version>
<bookkeeper-api.version>1.1.0-SNAPSHOT</bookkeeper-api.version>
</properties>
<distributionManagement>
<repository>
Expand Down Expand Up @@ -63,7 +63,7 @@
<version>${dropwizard.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-jdbi3</artifactId>
<version>${dropwizard.version}</version>
Expand Down Expand Up @@ -214,8 +214,10 @@
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.dataone.bookkeeper.Bookkeeper</mainClass>
</transformer>
</transformers>
Expand Down Expand Up @@ -254,7 +256,7 @@
</execution>
</executions>
</plugin>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven.deploy.version}</version>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/dataone/bookkeeper/Bookkeeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public void run(BookkeeperConfiguration configuration,
// Register the orders resource
environment.jersey().register(new OrdersResource(database, dataoneHelper));

// Register the payments resource
environment.jersey().register(new PaymentsResource(database, dataoneHelper));

// Register role-based authorization
environment.jersey().register(RolesAllowedDynamicFeature.class);

Expand Down
141 changes: 141 additions & 0 deletions src/main/java/org/dataone/bookkeeper/jdbi/PaymentStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* This work was created by participants in the DataONE project, and is
* jointly copyrighted by participating institutions in DataONE. For
* more information on DataONE, see our web site at http://dataone.org.
*
* Copyright 2023. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.dataone.bookkeeper.jdbi;

import java.util.List;
import org.dataone.bookkeeper.api.Payment;
import org.jdbi.v3.sqlobject.config.RegisterBeanMapper;
import org.jdbi.v3.sqlobject.customizer.Bind;
import org.jdbi.v3.sqlobject.customizer.BindBean;
import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;

@RegisterBeanMapper(Payment.class)
public interface PaymentStore {

/** The query used to find all usages */
String SELECT_CLAUSE =
"SELECT " +
"transactionId, " +
"orderId, " +
"accountId, " +
"timestamp, " +
"count, " +
"hash, " +
"authorizationCode, " +
"authorizationMessage, " +
"requestAmount, " +
"transactionAmount, " +
"products, " +
"transactionApproved, " +
"transactionTimestamp, " +
"updated " +
"FROM payments ";

/** The full query */
String SELECT_ALL = SELECT_CLAUSE;

/** Select by transaction identifier */
String SELECT_BY_TX_ID = SELECT_CLAUSE + "WHERE transactionId = :transactionId";

/**
* List all payments
* @return payments the list of payments
*/
@SqlQuery(SELECT_ALL)
List<Payment> listPayments();

/**
* Find payments by transaction identifier
* @param transactionId the transaction id
* @return payments the payments for the transactionId
*/
@SqlQuery(SELECT_BY_TX_ID)
List <Payment> findUsagesByTransactionId(@Bind("transactionId") String transactionId);

/**
* Insert a payment with a given Payment instance
* @param payment the payment to insert
*/
@SqlUpdate("INSERT INTO payments " +
"(transactionId, " +
"orderId, " +
"accountId, " +
"timestamp, " +
"count, " +
"hash, " +
"authorizationCode, " +
"authorizationMessage, " +
"requestAmount, " +
"transactionAmount, " +
"products, " +
"transactionApproved, " +
"transactionTimestamp) " +
"VALUES " +
"(:transactionId, " +
":orderId, " +
":accountId, " +
":timestamp, " +
":count, " +
":hash, " +
":authorizationCode, " +
":authorizationMessage, " +
":requestAmount, " +
":transactionAmount, " +
":products, " +
":transactionApproved, " +
":transactionTimestamp) " +
"RETURNING transactionId")
@GetGeneratedKeys
Integer insert(@BindBean Payment payment);

/**
* Update a payment for a given id
* @param payment the payment to update
*/
@SqlUpdate("UPDATE payments SET " +
"orderId = :orderId, " +
"accountId = :accountId, " +
"timestamp = :timestamp, " +
"count = :count, " +
"hash = :hash, " +
"authorizationCode = :authorizationCode, " +
"authorizationMessage = :authorizationMessage, " +
"requestAmount = :requestAmount, " +
"transactionAmount = :transactionAmount, " +
"products = :products, " +
"transactionApproved = :transactionApproved, " +
"transactionTimestamp = :transactionTimestamp) " +
"WHERE transactionId = :transactionId")
@GetGeneratedKeys
Payment update(@BindBean Payment payment);

/**
* Delete a payment
* @param transactionId the payment id to delete
* @return boolean true if the payment was deleted, otherwise false
*/
@SqlUpdate("DELETE FROM payments WHERE transactionId = :transactionId")
boolean delete(@Bind("transactionId") String transactionId);

}
Loading