-
Notifications
You must be signed in to change notification settings - Fork 5
/
redirection.go
47 lines (40 loc) · 1.48 KB
/
redirection.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
package zooz
import (
"context"
"encoding/json"
"fmt"
)
// RedirectionClient is a client for work with Redirection entity.
// https://developers.paymentsos.com/docs/api#/reference/redirections
type RedirectionClient struct {
Caller Caller
}
// Redirection is a entity model.
type Redirection struct {
ID string `json:"id"`
Created json.Number `json:"created"`
MerchantSiteURL string `json:"merchant_site_url"`
URL string `json:"url"`
}
// Get creates new Redirection entity.
func (c *RedirectionClient) Get(ctx context.Context, paymentID string, redirectionID string) (*Redirection, error) {
redirection := &Redirection{}
if err := c.Caller.Call(ctx, "GET", c.redirectionPath(paymentID, redirectionID), nil, nil, redirection); err != nil {
return nil, err
}
return redirection, nil
}
// GetList returns a list of Redirections for given payment.
func (c *RedirectionClient) GetList(ctx context.Context, paymentID string) ([]Redirection, error) {
var redirections []Redirection
if err := c.Caller.Call(ctx, "GET", c.redirectionsPath(paymentID), nil, nil, &redirections); err != nil {
return nil, err
}
return redirections, nil
}
func (c *RedirectionClient) redirectionsPath(paymentID string) string {
return fmt.Sprintf("%s/%s/redirections", paymentsPath, paymentID)
}
func (c *RedirectionClient) redirectionPath(paymentID string, redirectionID string) string {
return fmt.Sprintf("%s/%s", c.redirectionsPath(paymentID), redirectionID)
}