Skip to content

Commit

Permalink
Payment & PaymentMethod, #15
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiancook committed Jun 18, 2023
1 parent 83d6429 commit 195cf88
Show file tree
Hide file tree
Showing 20 changed files with 277 additions and 11 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,32 @@ export interface Partner extends PartnerData {
approvedByUserId?: string;
}

export type PaymentStatus = "pending" | "processing" | "paid" | "void";

export interface PaymentData extends Record<string, unknown> {
status: PaymentStatus;
paymentMethodId: string;
reference?: string;
}

export interface Payment extends PaymentData {
paymentId: string;
createdAt: string;
updatedAt: string;
}

export type PaymentMethodStatus = "pending" | "available" | "expired" | "void";

export interface PaymentMethodData extends Record<string, unknown> {
status: PaymentMethodStatus;
}

export interface PaymentMethod extends PaymentMethodData {
paymentMethodId: string;
createdAt: string;
updatedAt: string;
}

export interface ProductData extends Record<string, unknown> {
productName: string;
// Is the product publicly visible
Expand Down Expand Up @@ -472,6 +498,7 @@ export interface ShipmentData extends Record<string, unknown> {
from?: ShipmentFrom;
// A shipment would always have a destination
to: ShipmentTo;
identifiers?: Identifier[];
}

export interface Shipment extends ShipmentData {
Expand Down
27 changes: 27 additions & 0 deletions src/client/interface.readonly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,32 @@ export interface Partner extends PartnerData {
approvedByUserId?: string;
}

export type PaymentStatus = "pending" | "processing" | "paid" | "void";

export interface PaymentData extends Record<string, unknown> {
status: PaymentStatus;
paymentMethodId: string;
reference?: string;
}

export interface Payment extends PaymentData {
paymentId: string;
createdAt: string;
updatedAt: string;
}

export type PaymentMethodStatus = "pending" | "available" | "expired" | "void";

export interface PaymentMethodData extends Record<string, unknown> {
status: PaymentMethodStatus;
}

export interface PaymentMethod extends PaymentMethodData {
paymentMethodId: string;
createdAt: string;
updatedAt: string;
}

export interface ProductData extends Record<string, unknown> {
productName: string;
// Is the product publicly visible
Expand Down Expand Up @@ -438,6 +464,7 @@ export interface ShipmentData extends Record<string, unknown> {
from?: ShipmentFrom;
// A shipment would always have a destination
to: ShipmentTo;
identifiers?: Identifier[];
}

export interface Shipment extends ShipmentData {
Expand Down
4 changes: 3 additions & 1 deletion src/data/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ export * from "./inventory";
export * from "./order";
export * from "./order-product";
export * from "./inventory-product";
export * from "./file";
export * from "./file";
export * from "./payment";
export * from "./payment-method";
11 changes: 11 additions & 0 deletions src/data/payment-method/add-payment-method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { v4 } from "uuid";
import { PaymentMethodData, PaymentMethod } from "./types";
import { setPaymentMethod } from "./set-payment-method";

export async function addPaymentMethod(data: PaymentMethodData): Promise<PaymentMethod> {
const paymentMethodId = v4();
return setPaymentMethod({
...data,
paymentMethodId,
});
}
6 changes: 6 additions & 0 deletions src/data/payment-method/get-payment-method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { getPaymentMethodStore } from "./store";

export function getPaymentMethod(id: string) {
const store = getPaymentMethodStore();
return store.get(id);
}
7 changes: 7 additions & 0 deletions src/data/payment-method/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from "./store";
export * from "./types";
export * from "./get-payment-method";
export * from "./list-payment-methods";
export * from "./add-payment-method";
export * from "./set-payment-method";
export * as paymentMethodSchema from "./schema";
11 changes: 11 additions & 0 deletions src/data/payment-method/list-payment-methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PaymentMethod } from "./types";
import { getPaymentMethodStore } from "./store";

export interface ListPaymentMethodsInput {}

export async function listPaymentMethods({}: ListPaymentMethodsInput = {}): Promise<
PaymentMethod[]
> {
const store = getPaymentMethodStore();
return store.values();
}
34 changes: 34 additions & 0 deletions src/data/payment-method/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export const paymentMethodStatus = {
type: "string",
enum: [
"pending",
"available",
"expired",
"void"
]
}

export const paymentMethodData = {
type: "object",
properties: {
status: paymentMethodStatus,
},
required: ["status"],
} as const;

export const paymentMethod = {
type: "object",
properties: {
paymentMethodId: {
type: "string",
},
createdAt: {
type: "string",
},
updatedAt: {
type: "string",
},
...paymentMethodData.properties,
},
required: ["paymentMethodId", "createdAt", "updatedAt", ...paymentMethodData.required],
} as const;
16 changes: 16 additions & 0 deletions src/data/payment-method/set-payment-method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { PaymentMethod, PaymentMethodData } from "./types";
import { getPaymentMethodStore } from "./store";

export async function setPaymentMethod(
data: PaymentMethodData & Pick<PaymentMethod, "paymentMethodId"> & Partial<PaymentMethod>
): Promise<PaymentMethod> {
const store = await getPaymentMethodStore();
const updatedAt = new Date().toISOString();
const document: PaymentMethod = {
createdAt: data.createdAt || updatedAt,
...data,
updatedAt,
};
await store.set(data.paymentMethodId, document);
return document;
}
8 changes: 8 additions & 0 deletions src/data/payment-method/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getKeyValueStore } from "../kv";
import { PaymentMethod } from "./types";

const STORE_NAME = "paymentMethod" as const;

export function getPaymentMethodStore() {
return getKeyValueStore<PaymentMethod>(STORE_NAME);
}
11 changes: 11 additions & 0 deletions src/data/payment-method/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type PaymentMethodStatus = "pending" | "available" | "expired" | "void";

export interface PaymentMethodData extends Record<string, unknown> {
status: PaymentMethodStatus;
}

export interface PaymentMethod extends PaymentMethodData {
paymentMethodId: string;
createdAt: string;
updatedAt: string;
}
11 changes: 11 additions & 0 deletions src/data/payment/add-payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { v4 } from "uuid";
import { PaymentData, Payment } from "./types";
import { setPayment } from "./set-payment";

export async function addPayment(data: PaymentData): Promise<Payment> {
const paymentId = v4();
return setPayment({
...data,
paymentId,
});
}
6 changes: 6 additions & 0 deletions src/data/payment/get-payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { getPaymentStore } from "./store";

export function getPayment(id: string) {
const store = getPaymentStore();
return store.get(id);
}
7 changes: 7 additions & 0 deletions src/data/payment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from "./store";
export * from "./types";
export * from "./get-payment";
export * from "./list-payments";
export * from "./add-payment";
export * from "./set-payment";
export * as paymentSchema from "./schema";
11 changes: 11 additions & 0 deletions src/data/payment/list-payments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Payment } from "./types";
import { getPaymentStore } from "./store";

export interface ListPaymentsInput {}

export async function listPayments({}: ListPaymentsInput = {}): Promise<
Payment[]
> {
const store = getPaymentStore();
return store.values();
}
34 changes: 34 additions & 0 deletions src/data/payment/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export const paymentStatus = {
type: "string",
enum: [
"pending",
"processing",
"paid",
"void"
]
}

export const paymentData = {
type: "object",
properties: {
status: paymentStatus,
},
required: ["status"],
} as const;

export const payment = {
type: "object",
properties: {
paymentId: {
type: "string",
},
createdAt: {
type: "string",
},
updatedAt: {
type: "string",
},
...paymentData.properties,
},
required: ["paymentId", "createdAt", "updatedAt", ...paymentData.required],
} as const;
16 changes: 16 additions & 0 deletions src/data/payment/set-payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Payment, PaymentData } from "./types";
import { getPaymentStore } from "./store";

export async function setPayment(
data: PaymentData & Pick<Payment, "paymentId"> & Partial<Payment>
): Promise<Payment> {
const store = await getPaymentStore();
const updatedAt = new Date().toISOString();
const document: Payment = {
createdAt: data.createdAt || updatedAt,
...data,
updatedAt,
};
await store.set(data.paymentId, document);
return document;
}
8 changes: 8 additions & 0 deletions src/data/payment/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getKeyValueStore } from "../kv";
import { Payment } from "./types";

const STORE_NAME = "payment" as const;

export function getPaymentStore() {
return getKeyValueStore<Payment>(STORE_NAME);
}
13 changes: 13 additions & 0 deletions src/data/payment/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type PaymentStatus = "pending" | "processing" | "paid" | "void";

export interface PaymentData extends Record<string, unknown> {
status: PaymentStatus;
paymentMethodId: string;
reference?: string;
}

export interface Payment extends PaymentData {
paymentId: string;
createdAt: string;
updatedAt: string;
}
20 changes: 10 additions & 10 deletions src/package.readonly.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// File generated by scripts/pre-build.js

export const commit = "5f4d3f32f71f701d32d53171e27ac0b12b18bdce";
export const commitShort = "5f4d3f3";
export const commit = "83d642984e47c8a70000dd4e02e625a18c9bb03f";
export const commitShort = "83d6429";
export const commitAuthor = "Fabian Cook";
export const commitEmail = "[email protected]";
export const commitMessage = "1.0.0-alpha.24";
export const commitAt = "2023-06-16T22:48:03.000Z";
export const secondsBetweenCommitAndBuild = 47576.66;
export const minutesBetweenCommitAndBuild = 792.94;
export const timeBetweenCommitAndBuild = "792 minutes and 56 seconds";
export const commitMessage = "Order, pick, pack, ship scenario";
export const commitAt = "2023-06-17T12:02:23.000Z";
export const secondsBetweenCommitAndBuild = 43435.77;
export const minutesBetweenCommitAndBuild = 723.93;
export const timeBetweenCommitAndBuild = "723 minutes and 55 seconds";
// Variables to be replaced after tests
export const secondsBetweenCommitAndTestCompletion = "47593.24";
export const minutesBetweenCommitAndTestCompletion = "793.22";
export const timeBetweenCommitAndTestCompletion = "793 minutes and 13 seconds";
export const secondsBetweenCommitAndTestCompletion = "";
export const minutesBetweenCommitAndTestCompletion = "";
export const timeBetweenCommitAndTestCompletion = "";

0 comments on commit 195cf88

Please sign in to comment.