This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
forked from Arman92/go-tdlib
/
paymentResult.go
65 lines (56 loc) · 2.44 KB
/
paymentResult.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package tdlib
import (
"encoding/json"
"fmt"
)
// PaymentResult Contains the result of a payment request
type PaymentResult struct {
tdCommon
Success bool `json:"success"` // True, if the payment request was successful; otherwise the verification_url will be non-empty
VerificationUrl string `json:"verification_url"` // URL for additional payment credentials verification
}
// MessageType return the string telegram-type of PaymentResult
func (paymentResult *PaymentResult) MessageType() string {
return "paymentResult"
}
// NewPaymentResult creates a new PaymentResult
//
// @param success True, if the payment request was successful; otherwise the verification_url will be non-empty
// @param verificationUrl URL for additional payment credentials verification
func NewPaymentResult(success bool, verificationUrl string) *PaymentResult {
paymentResultTemp := PaymentResult{
tdCommon: tdCommon{Type: "paymentResult"},
Success: success,
VerificationUrl: verificationUrl,
}
return &paymentResultTemp
}
// SendPaymentForm Sends a filled-out payment form to the bot for final verification
// @param chatId Chat identifier of the Invoice message
// @param messageId Message identifier
// @param paymentFormId Payment form identifier returned by getPaymentForm
// @param orderInfoId Identifier returned by validateOrderInfo, or an empty string
// @param shippingOptionId Identifier of a chosen shipping option, if applicable
// @param credentials The credentials chosen by user for payment
// @param tipAmount Chosen by the user amount of tip in the smallest units of the currency
func (client *Client) SendPaymentForm(chatId int64, messageId int64, paymentFormId JSONInt64, orderInfoId string, shippingOptionId string, credentials InputCredentials, tipAmount int64) (*PaymentResult, error) {
result, err := client.SendAndCatch(UpdateData{
"@type": "sendPaymentForm",
"chat_id": chatId,
"message_id": messageId,
"payment_form_id": paymentFormId,
"order_info_id": orderInfoId,
"shipping_option_id": shippingOptionId,
"credentials": credentials,
"tip_amount": tipAmount,
})
if err != nil {
return nil, err
}
if result.Data["@type"].(string) == "error" {
return nil, fmt.Errorf("error! code: %v msg: %s", result.Data["code"], result.Data["message"])
}
var paymentResult PaymentResult
err = json.Unmarshal(result.Raw, &paymentResult)
return &paymentResult, err
}