feat(payment): implement coffee tip plans and update payment flow
This commit is contained in:
@@ -12,18 +12,30 @@ import {
|
||||
import { getPaymentRepository } from "@/data/repositories/payment_repository";
|
||||
import { Result } from "@/utils";
|
||||
|
||||
import type { PaymentPlanCatalog } from "./payment-state";
|
||||
|
||||
export const loadCachedPaymentPlansActor =
|
||||
fromPromise<PaymentPlansResponse | null>(async () => {
|
||||
fromPromise<
|
||||
PaymentPlansResponse | null,
|
||||
{ catalog: PaymentPlanCatalog }
|
||||
>(async ({ input }) => {
|
||||
if (input.catalog === "tip") return null;
|
||||
const paymentRepo = getPaymentRepository();
|
||||
const result = await paymentRepo.getCachedPlans();
|
||||
if (Result.isErr(result)) throw result.error;
|
||||
return result.data;
|
||||
});
|
||||
|
||||
export const refreshPaymentPlansActor = fromPromise<PaymentPlansResponse>(
|
||||
async () => {
|
||||
export const refreshPaymentPlansActor = fromPromise<
|
||||
PaymentPlansResponse,
|
||||
{ catalog: PaymentPlanCatalog }
|
||||
>(
|
||||
async ({ input }) => {
|
||||
const paymentRepo = getPaymentRepository();
|
||||
const result = await paymentRepo.getPlans();
|
||||
const result =
|
||||
input.catalog === "tip"
|
||||
? await paymentRepo.getTipPlans()
|
||||
: await paymentRepo.getPlans();
|
||||
if (Result.isErr(result)) throw result.error;
|
||||
return result.data;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user