forked from vasconcelosvcd/go-cielo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsale.go
42 lines (33 loc) · 973 Bytes
/
sale.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
package cielo
import (
"errors"
"fmt"
)
//Sale returns the payment/sale authorization
//Endpoint POST /1/sales
func (c *Client) DoSale(sale *Sale) (*Sale, error) {
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.Environment.APIUrl, "/1/sales/"), sale)
salePayed := &Sale{}
if err != nil {
return salePayed, err
}
err = c.Send(req, salePayed)
return salePayed, nil
}
//UndoSale returns the payment/sale authorization
//Endpoint POST /1/sales
func (c *Client) UndoSale(sale *Sale) (*UndoSaleResponse, error) {
if sale.Payment.PaymentID ==""{
return nil,errors.New("missing PaymentId parameter")
}
if sale.Payment.Amount == 0{
return nil,errors.New("missing Amount parameter")
}
req, err := c.NewRequest("PUT", fmt.Sprintf("%s%s%s%s", c.Environment.APIUrl, "/1/sales/",sale.Payment.PaymentID,"/void"), sale)
salePayed := &UndoSaleResponse{}
if err != nil {
return salePayed, err
}
err = c.Send(req, salePayed)
return salePayed, nil
}