From f40bb4abf66a858e3581cc3e716eebf23e0c322d Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@leastauthority.com>
Date: Fri, 18 Oct 2019 13:31:54 +0530
Subject: [PATCH] persistence: paying for a voucher inserts it into the
 vouchers table

---
 src/PaymentServer/Persistence.hs | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/PaymentServer/Persistence.hs b/src/PaymentServer/Persistence.hs
index f332786..814a4ff 100644
--- a/src/PaymentServer/Persistence.hs
+++ b/src/PaymentServer/Persistence.hs
@@ -113,8 +113,7 @@ memory = do
 
 instance VoucherDatabase Sqlite.Connection where
   -- payForVoucher :: Sqlite.Connection -> Voucher -> IO ()
-  payForVoucher dbConn voucher = do
-    undefined
+  payForVoucher = insertVoucher
   -- redeemVoucher :: Sqlite.Connection -> Voucher -> Fingerprint -> IO (Either RedeemError ())
   redeemVoucher dbConn voucher fingerprint = do
     unpaid <- isVoucherUnpaid dbConn voucher
@@ -145,6 +144,10 @@ getVoucherFingerprint :: Sqlite.Connection -> Voucher -> IO [Fingerprint]
 getVoucherFingerprint dbConn voucher = do
   Sqlite.query dbConn "SELECT redeemed.fingerprint FROM vouchers INNER JOIN redeemed ON vouchers.id = redeemed.voucher_id AND vouchers.name = ?" (Sqlite.Only voucher)
 
+insertVoucher :: Sqlite.Connection -> Voucher -> IO ()
+insertVoucher dbConn voucher =
+  Sqlite.execute dbConn "INSERT INTO vouchers (name) VALUES (?)" (Sqlite.Only voucher)
+
 getDBConnection :: Text -> IO ()
 getDBConnection name = do
   dbConn <- Sqlite.open (unpack name)
-- 
GitLab