Skip to content

Commit

Permalink
Merge pull request #95 from klappvisor/payments
Browse files Browse the repository at this point in the history
Payments
  • Loading branch information
klappvisor authored May 21, 2017
2 parents cda2e28 + 569ab8d commit b9b7ca0
Show file tree
Hide file tree
Showing 11 changed files with 615 additions and 276 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Contributions are welcome!
6. PROFIT

Bear in mind that the CI build won't run integration test suite against your pull request since the necessary environment
variables (`$BOT_TOKEN`, `$CHAT_ID` and `$BOT_NAME`) aren't exported when a fork
variables (`$BOT_TOKEN`, `$STRIPE_TOKEN`, `$CHAT_ID` and `$BOT_NAME`) aren't exported when a fork
starts the build (for security reasons). If you do want to run them before creating RP, you can setup integration of your fork
with CircleCI.

Expand All @@ -139,12 +139,13 @@ stack build
To run test you have to create your own bot. Go to [BotFather](https://telegram.me/botfather) and create the bot. As the result you will have private bot's access token. Keep it safe!

```
stack test --test-arguments "--integration -t BOT_TOKEN -c CHAT_ID -b BOT_NAME -- HSPEC_ARGS"
stack test --test-arguments "--integration -c CHAT_ID -b BOT_NAME -- HSPEC_ARGS"
```

where

* `BOT_TOKEN` is the token obtained from BotFather
* `BOT_TOKEN` is the token obtained from BotFather and must be defined as environment variable
* `PAYMENT_TOKEN` is the token obtained from BotFather and must be defined as environment variable
* `CHAT_ID` can be id of your chat with your bot. Send some messages to this chat in Telegram and do `curl "https://api.telegram.org/bot<replace_with_token>/getUpdates"`, you'll have to parse some JSON with your brain ;-) or any other suitable tool and you will find chat id there.
* `BOT_NAME` is the name of your bot
* `HSPEC_ARGS` are the normal `hspec` arguments you can find [here][hspec-args]
Expand All @@ -153,7 +154,7 @@ The help option is available for the tests and for hspec:

```
stack test --test-arguments "-h"
stack test --test-arguments "--integration -t BOT_TOKEN -c CHAT_ID -b BOT_NAME -- -h"
stack test --test-arguments "--integration -c CHAT_ID -b BOT_NAME -- -h"
```

Note: Inline Spec is disabled for now...
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:

test:
override:
- echo $CI_PULL_REQUEST ; if [[ ! -z $CI_PULL_REQUEST ]] ; then stack test; else stack test --test-arguments "--integration --token $BOT_TOKEN --chatid $CHAT_ID --botname $BOT_NAME"; fi
- echo $CI_PULL_REQUEST ; if [[ ! -z $CI_PULL_REQUEST ]] ; then stack test; else stack test --test-arguments "--integration --chatid $CHAT_ID --botname $BOT_NAME"; fi

deployment:
master:
Expand Down
2 changes: 2 additions & 0 deletions src/Web/Telegram/API/Bot/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Web.Telegram.API.Bot.API.Get as API
import Web.Telegram.API.Bot.API.Messages as API
import Web.Telegram.API.Bot.API.Queries as API
import Web.Telegram.API.Bot.API.Updates as API
import Web.Telegram.API.Bot.API.Payments as API

type TelegramBotAPI =
TelegramBotMessagesAPI
Expand All @@ -32,6 +33,7 @@ type TelegramBotAPI =
:<|> TelegramBotEditAPI
:<|> TelegramBotQueriesAPI
:<|> TelegramBotGetAPI
:<|> TelegramBotPaymentsAPI

-- | Proxy for Thelegram Bot API
api :: Proxy TelegramBotAPI
Expand Down
52 changes: 52 additions & 0 deletions src/Web/Telegram/API/Bot/API/Payments.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}

module Web.Telegram.API.Bot.API.Payments
( -- * Functions
sendInvoiceM
, answerShippingQueryM
, answerPreCheckoutQueryM
-- * API
, TelegramBotPaymentsAPI
, paymentsApi
-- * Types
) where

import Data.Proxy
import Servant.API
import Servant.Client
import Web.Telegram.API.Bot.API.Core
import Web.Telegram.API.Bot.Requests
import Web.Telegram.API.Bot.Responses

type TelegramBotPaymentsAPI =
TelegramToken :> "sendInvoice"
:> ReqBody '[JSON] SendInvoiceRequest
:> Post '[JSON] MessageResponse
:<|> TelegramToken :> "answerShippingQuery"
:> ReqBody '[JSON] AnswerShippingQueryRequest
:> Post '[JSON] AnswerShippingQueryResponse
:<|> TelegramToken :> "answerPreCheckoutQuery"
:> ReqBody '[JSON] AnswerPreCheckoutQueryRequest
:> Post '[JSON] AnswerPreCheckoutQueryResponse

paymentsApi :: Proxy TelegramBotPaymentsAPI
paymentsApi = Proxy

sendInvoice_ :: Token -> SendInvoiceRequest -> ClientM MessageResponse
answerShippingQuery_ :: Token -> AnswerShippingQueryRequest -> ClientM AnswerShippingQueryResponse
answerPreCheckoutQuery_ :: Token -> AnswerPreCheckoutQueryRequest -> ClientM AnswerPreCheckoutQueryResponse
sendInvoice_
:<|> answerShippingQuery_
:<|> answerPreCheckoutQuery_
= client paymentsApi

sendInvoiceM :: SendInvoiceRequest -> TelegramClient MessageResponse
sendInvoiceM = run_ sendInvoice_

answerShippingQueryM :: AnswerShippingQueryRequest -> TelegramClient AnswerShippingQueryResponse
answerShippingQueryM = run_ answerShippingQuery_

answerPreCheckoutQueryM :: AnswerPreCheckoutQueryRequest -> TelegramClient AnswerPreCheckoutQueryResponse
answerPreCheckoutQueryM = run_ answerPreCheckoutQuery_
Loading

0 comments on commit b9b7ca0

Please sign in to comment.