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
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
8e799256
Commit
8e799256
authored
5 years ago
by
Ramakrishnan Muthukrishnan
Browse files
Options
Downloads
Patches
Plain Diff
WIP: a "charge" endpoint that does nothing
parent
d24834d9
No related branches found
No related tags found
1 merge request
!30
Expose a browser facing API for charge
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/PaymentServer/Processors/Stripe.hs
+21
-4
21 additions, 4 deletions
src/PaymentServer/Processors/Stripe.hs
with
21 additions
and
4 deletions
src/PaymentServer/Processors/Stripe.hs
+
21
−
4
View file @
8e799256
...
...
@@ -11,14 +11,21 @@ module PaymentServer.Processors.Stripe
import
Control.Monad.IO.Class
(
liftIO
)
import
Control.Monad
(
mzero
)
import
Data.Text
(
Text
)
import
Text.Printf
(
printf
)
import
Data.Aeson
(
ToJSON
(
toJSON
)
,
FromJSON
(
parseJSON
)
,
Object
,
Value
(
Object
)
,
object
,
(
.:
)
)
import
Servant
(
Server
...
...
@@ -29,6 +36,7 @@ import Servant.API
,
JSON
,
Post
,
(
:>
)
,
(
:<|>
)(
..
)
)
import
Web.Stripe.Event
(
Event
(
Event
,
eventId
,
eventCreated
,
eventLiveMode
,
eventType
,
eventData
,
eventObject
,
eventPendingWebHooks
,
eventRequest
)
...
...
@@ -51,7 +59,10 @@ data Acknowledgement = Ok
instance
ToJSON
Acknowledgement
where
toJSON
Ok
=
object
[]
type
StripeAPI
=
"webhook"
:>
ReqBody
'
[
JSON
]
Event
:>
Post
'
[
JSON
]
Acknowledgement
type
StripeAPI
=
WebhookAPI
:<|>
ChargeAPI
type
WebhookAPI
=
"webhook"
:>
ReqBody
'
[
JSON
]
Event
:>
Post
'
[
JSON
]
Acknowledgement
-- | getVoucher finds the metadata item with the key `"Voucher"` and returns
-- the corresponding value, or Nothing.
...
...
@@ -61,7 +72,8 @@ getVoucher (MetaData (("Voucher", value):xs)) = Just value
getVoucher
(
MetaData
(
x
:
xs
))
=
getVoucher
(
MetaData
xs
)
stripeServer
::
VoucherDatabase
d
=>
d
->
Server
StripeAPI
stripeServer
=
webhook
stripeServer
d
=
(
webhook
d
)
:<|>
(
charge
d
)
-- | Process charge succeeded events
webhook
::
VoucherDatabase
d
=>
d
->
Event
->
Handler
Acknowledgement
...
...
@@ -89,7 +101,7 @@ webhook d _ =
-- | Browser facing API that takes token, voucher and a few other information
-- and calls stripe charges API. If payment succeeds, then the voucher is stored
-- in the voucher database.
type
Browser
API
=
"charge"
:>
ReqBody
'
[
JSON
]
Token
:>
Post
'
[
JSON
]
Acknowledgement
type
Charge
API
=
"charge"
:>
ReqBody
'
[
JSON
]
Token
:>
Post
'
[
JSON
]
Acknowledgement
data
Token
=
Token
{
token
::
Text
...
...
@@ -101,3 +113,8 @@ instance FromJSON Token where
v
.:
"token"
<*>
v
.:
"voucher"
parseJSON
_
=
mzero
charge
::
VoucherDatabase
d
=>
d
->
Token
->
Handler
Acknowledgement
charge
d
(
Token
token
voucher
)
=
-- call the stripe Charge API
return
Ok
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