-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Declarative SuccessfulPayment handler #84
Comments
You can add this extension yourself, it's not there by default since successful payments come attached to a message and not in an Update which is the common pattern for these extension methods. package com.bot4s.telegram.api.declarative
import cats.instances.list._
import cats.syntax.flatMap._
import cats.syntax.functor._
import cats.syntax.traverse._
import com.bot4s.telegram.api.BotBase
import com.bot4s.telegram.models.{Message, SuccessfulPayment}
import scala.collection.mutable
/**
* Extension for processing (successful) payments.
* See [[https://core.telegram.org/bots/payments]].
*/
trait MyPayments[F[_]] extends BotBase[F] {
private val successfulPaymentActions = mutable.ArrayBuffer[Action[F, SuccessfulPayment]]()
/**
* Executes 'action' for every successful payment.
*/
def onSuccessfulPayment(action: Action[F, SuccessfulPayment]): Unit = {
successfulPaymentActions += action
}
override def receiveMessage(message: Message): F[Unit] =
for {
_ <- successfulPaymentActions.toList.traverse(action => message.successfulPayment.map(action).getOrElse(unit))
_ <- super.receiveMessage(message)
} yield ()
} If you have any issues with payments, bugs or even feature requests (e.g. in the usability department) please file an issue; I'm glad to help. |
@mukel Thanks a lot. I have already done that. I filed this issue to pick up it later. If we have |
Docs: https://core.telegram.org/bots/api#successfulpayment
Add declarative handler for successful payments to
com.bot4s.telegram.api.declarative.Payments
like it is done forcom.bot4s.telegram.api.declarative.Payments#onPreCheckoutQuery
.The text was updated successfully, but these errors were encountered: