2018-07-08 01:41:21 +02:00
package org.telegram.telegrambots.meta.api.methods ;
2017-03-27 00:49:08 +02:00
import com.fasterxml.jackson.annotation.JsonProperty ;
2020-11-01 23:46:36 +01:00
import lombok.AllArgsConstructor ;
import lombok.Builder ;
import lombok.EqualsAndHashCode ;
import lombok.Getter ;
import lombok.NoArgsConstructor ;
import lombok.NonNull ;
import lombok.RequiredArgsConstructor ;
import lombok.Setter ;
import lombok.ToString ;
2022-06-16 19:57:41 +02:00
import org.telegram.telegrambots.meta.api.methods.botapimethods.BotApiMethodBoolean ;
2018-07-08 01:41:21 +02:00
import org.telegram.telegrambots.meta.exceptions.TelegramApiValidationException ;
2017-03-27 00:49:08 +02:00
/ * *
* @author Ruben Bermudez
* @version 1 . 0
*
* Once the user has confirmed their payment and shipping details , the Bot API sends the final confirmation
* in the form of an Update with the field pre_checkout_query . Use this method to respond to such pre - checkout queries .
*
* On success , True is returned
*
* @apiNote The Bot API must receive an answer within 10 seconds after the pre - checkout query was sent .
* /
2020-11-01 23:46:36 +01:00
@EqualsAndHashCode ( callSuper = false )
@Getter
@Setter
@ToString
@NoArgsConstructor
@RequiredArgsConstructor
@AllArgsConstructor
@Builder
2022-06-16 19:57:41 +02:00
public class AnswerPreCheckoutQuery extends BotApiMethodBoolean {
2017-03-27 00:49:08 +02:00
public static final String PATH = " answerPreCheckoutQuery " ;
private static final String PRE_CHECKOUT_QUERY_ID_FIELD = " pre_checkout_query_id " ;
private static final String OK_FIELD = " ok " ;
private static final String ERROR_MESSAGE_FIELD = " error_message " ;
@JsonProperty ( PRE_CHECKOUT_QUERY_ID_FIELD )
2020-11-01 23:46:36 +01:00
@NonNull
2017-03-27 00:49:08 +02:00
private String preCheckoutQueryId ; ///< Unique identifier for the query to be answered
@JsonProperty ( OK_FIELD )
2020-11-01 23:46:36 +01:00
@NonNull
2017-03-27 00:49:08 +02:00
private Boolean ok ; ///< Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
@JsonProperty ( ERROR_MESSAGE_FIELD )
private String errorMessage ; ///< Optional. Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout
@Override
public void validate ( ) throws TelegramApiValidationException {
2022-06-16 19:36:20 +02:00
if ( preCheckoutQueryId . isEmpty ( ) ) {
2017-03-27 00:49:08 +02:00
throw new TelegramApiValidationException ( " PreCheckoutQueryId can't be empty " , this ) ;
}
if ( ! ok ) {
if ( errorMessage = = null | | errorMessage . isEmpty ( ) ) {
throw new TelegramApiValidationException ( " ErrorMessage can't be empty if not ok " , this ) ;
}
}
}
@Override
public String getMethod ( ) {
return PATH ;
}
}