Skip to content
Snippets Groups Projects
Commit 0c141d02 authored by Ramakrishnan Muthukrishnan's avatar Ramakrishnan Muthukrishnan
Browse files

handle cases where voucher code is missing/mismatched from response

parent e2ba9ef9
No related branches found
No related tags found
1 merge request!30Expose a browser facing API for charge
......@@ -152,7 +152,16 @@ charge d key (Charges token voucher amount currency) = do
-&- tokenId
-&- MetaData [("Voucher", voucher)]
case result of
Right (Charge {}) -> do
liftIO $ payForVoucher d voucher
return Ok
Left (StripeError {}) -> throwError err400 { errBody = "Stripe charge didn't succeed" }
Right Charge { chargeMetaData = metadata } ->
-- verify that we are getting the same metadata that we sent.
case metadata of
MetaData [("Voucher", v)] ->
if v == voucher
then
do
liftIO $ payForVoucher d voucher
return Ok
else
throwError err400 { errBody = "Voucher code mismatch" }
_ -> throwError err400 { errBody = "Voucher code not found" }
Left StripeError {} -> throwError err400 { errBody = "Stripe charge didn't succeed" }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment