response to service

This commit is contained in:
boufni95 2024-10-03 16:56:54 +00:00
parent d2f2ac48eb
commit 1049586646
15 changed files with 354 additions and 51 deletions

View file

@ -107,6 +107,7 @@ type Client struct {
RequestNPubLinkingToken func(req RequestNPubLinkingTokenRequest) (*RequestNPubLinkingTokenResponse, error)
ResetDebit func(req DebitOperation) error
ResetNPubLinkingToken func(req RequestNPubLinkingTokenRequest) (*RequestNPubLinkingTokenResponse, error)
RespondToDebit func(req DebitResponse) error
SendAppUserToAppPayment func(req SendAppUserToAppPaymentRequest) error
SendAppUserToAppUserPayment func(req SendAppUserToAppUserPaymentRequest) error
SetMockAppBalance func(req SetMockAppBalanceRequest) error
@ -1433,6 +1434,30 @@ func NewClient(params ClientParams) *Client {
}
return &res, nil
},
RespondToDebit: func(req DebitResponse) error {
auth, err := params.RetrieveUserAuth()
if err != nil {
return err
}
finalRoute := "/api/user/debit/finish"
body, err := json.Marshal(req)
if err != nil {
return err
}
resBody, err := doPostRequest(params.BaseURL+finalRoute, body, auth)
if err != nil {
return err
}
result := ResultError{}
err = json.Unmarshal(resBody, &result)
if err != nil {
return err
}
if result.Status == "ERROR" {
return fmt.Errorf(result.Reason)
}
return nil
},
SendAppUserToAppPayment: func(req SendAppUserToAppPaymentRequest) error {
auth, err := params.RetrieveAppAuth()
if err != nil {

View file

@ -175,6 +175,7 @@ type DebitAuthorization struct {
}
type DebitAuthorizationRequest struct {
Authorize_npub string `json:"authorize_npub"`
Request_id string `json:"request_id"`
Rules []DebitRule `json:"rules"`
}
type DebitAuthorizations struct {
@ -186,6 +187,11 @@ type DebitExpirationRule struct {
type DebitOperation struct {
Npub string `json:"npub"`
}
type DebitResponse struct {
Npub string `json:"npub"`
Request_id string `json:"request_id"`
Response *DebitResponse_response `json:"response"`
}
type DebitRule struct {
Rule *DebitRule_rule `json:"rule"`
}
@ -261,8 +267,9 @@ type LinkNPubThroughTokenRequest struct {
Token string `json:"token"`
}
type LiveDebitRequest struct {
Debit *LiveDebitRequest_debit `json:"debit"`
Npub string `json:"npub"`
Debit *LiveDebitRequest_debit `json:"debit"`
Npub string `json:"npub"`
Request_id string `json:"request_id"`
}
type LiveUserOperation struct {
Operation *UserOperation `json:"operation"`
@ -497,6 +504,18 @@ type UsersInfo struct {
No_balance int64 `json:"no_balance"`
Total int64 `json:"total"`
}
type DebitResponse_response_type string
const (
DENIED DebitResponse_response_type = "denied"
INVOICE DebitResponse_response_type = "invoice"
)
type DebitResponse_response struct {
Type DebitResponse_response_type `json:"type"`
Denied *Empty `json:"denied"`
Invoice *string `json:"invoice"`
}
type DebitRule_rule_type string
const (