Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PaymentServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
PaymentServer
Commits
708a0ae7
Unverified
Commit
708a0ae7
authored
Jun 1, 2021
by
Jean-Paul Calderone
Committed by
GitHub
Jun 1, 2021
Browse files
Options
Downloads
Plain Diff
Merge pull request #83 from PrivateStorageio/82.currency-parsing
Pull the Currency parsing into the JSON parser
parents
190b2538
2c3b1deb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/PaymentServer/Processors/Stripe.hs
+5
-13
5 additions, 13 deletions
src/PaymentServer/Processors/Stripe.hs
with
5 additions
and
13 deletions
src/PaymentServer/Processors/Stripe.hs
+
5
−
13
View file @
708a0ae7
...
...
@@ -105,7 +105,7 @@ data Charges = Charges
,
amount
::
Int
-- ^ The amount of the charge in the minimum
-- currency unit of the target currency (eg for
-- USD, cents).
,
currency
::
Text
-- ^ The currency in which the charge will be made.
,
currency
::
Currency
-- ^ The currency in which the charge will be made.
}
deriving
(
Show
,
Eq
)
instance
FromJSON
Charges
where
...
...
@@ -113,7 +113,7 @@ instance FromJSON Charges where
v
.:
"token"
<*>
v
.:
"voucher"
<*>
(
read
<$>
v
.:
"amount"
)
<*>
v
.:
"currency"
(
read
<$>
v
.:
"currency"
)
parseJSON
_
=
mzero
...
...
@@ -150,8 +150,7 @@ withSuccessFailureMetrics attemptCount successCount op = do
-- and if the Charge is okay, then set the voucher as "paid" in the database.
charge
::
VoucherDatabase
d
=>
StripeConfig
->
d
->
Charges
->
Handler
Acknowledgement
charge
stripeConfig
d
(
Charges
token
voucher
amount
currency
)
=
do
currency'
<-
getCurrency
currency
result
<-
liftIO
((
payForVoucher
d
voucher
(
completeStripeCharge
currency'
))
::
IO
ProcessorResult
)
result
<-
liftIO
((
payForVoucher
d
voucher
(
completeStripeCharge
currency
))
::
IO
ProcessorResult
)
case
result
of
Left
AlreadyPaid
->
throwError
voucherAlreadyPaid
...
...
@@ -161,15 +160,9 @@ charge stripeConfig d (Charges token voucher amount currency) = do
throwError
.
errorForStripeType
$
errorType
Right
chargeId
->
return
Ok
where
getCurrency
::
Text
->
Handler
Currency
getCurrency
maybeCurrency
=
case
readMaybe
(
unpack
currency
)
of
Just
currency'
->
return
currency'
Nothing
->
throwError
unsupportedCurrency
tokenId
=
TokenId
token
completeStripeCharge
::
Currency
->
IO
ProcessorResult
completeStripeCharge
currency
'
=
do
completeStripeCharge
currency
=
do
result
<-
stripe
stripeConfig
charge
case
result
of
Left
any
->
...
...
@@ -178,7 +171,7 @@ charge stripeConfig d (Charges token voucher amount currency) = do
return
.
Right
$
chargeId
where
charge
=
createCharge
(
Amount
amount
)
currency
'
createCharge
(
Amount
amount
)
currency
-&-
tokenId
-&-
MetaData
[(
"Voucher"
,
voucher
)]
...
...
@@ -202,7 +195,6 @@ charge stripeConfig d (Charges token voucher amount currency) = do
serviceUnavailable
=
jsonErr
503
"Service temporarily unavailable"
internalServerError
=
jsonErr
500
"Internal server error"
unsupportedCurrency
=
jsonErr
400
"Invalid currency specified"
voucherCodeNotFound
=
jsonErr
400
"Voucher code not found"
stripeChargeFailed
=
jsonErr
400
"Stripe charge didn't succeed"
voucherAlreadyPaid
=
jsonErr
400
"Payment for voucher already supplied"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment