/
client.go
46 lines (38 loc) · 1.08 KB
/
client.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
package cardlesscredit
import (
"context"
"fmt"
"net/http"
"github.com/xendit/xendit-go"
"github.com/xendit/xendit-go/utils/validator"
)
// Client is the client used to invoke invoice API.
type Client struct {
Opt *xendit.Option
APIRequester xendit.APIRequester
}
// CreatePayment creates new cardless credit payment
func (c *Client) CreatePayment(data *CreatePaymentParams) (*xendit.CardlessCredit, *xendit.Error) {
return c.CreatePaymentWithContext(context.Background(), data)
}
// CreatePaymentWithContext creates new cardless credit payment with context
func (c *Client) CreatePaymentWithContext(ctx context.Context, data *CreatePaymentParams) (*xendit.CardlessCredit, *xendit.Error) {
if err := validator.ValidateRequired(ctx, data); err != nil {
return nil, validator.APIValidatorErr(err)
}
response := &xendit.CardlessCredit{}
header := http.Header{}
err := c.APIRequester.Call(
ctx,
"POST",
fmt.Sprintf("%s/cardless-credit", c.Opt.XenditURL),
c.Opt.SecretKey,
header,
data,
response,
)
if err != nil {
return nil, err
}
return response, nil
}