-
Notifications
You must be signed in to change notification settings - Fork 0
/
redirect_payment.go
59 lines (47 loc) · 1.17 KB
/
redirect_payment.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
package ipaymu
import (
"bytes"
"encoding/json"
"log"
)
// create redirect payment
func (p *Payment) RedirectPayment(rr *RedirectRequest) (Response, error) {
req := make(map[string]interface{})
req, _ = structToMap(rr)
// set buyer info
req["buyerName"] = p.Customer.Name
req["buyerEmail"] = p.Customer.Email
req["buyerPhone"] = p.Customer.Phone
// set notifyUrl
if p.Config.NotifyUrl != "" {
req["notifyUrl"] = p.Config.NotifyUrl
}
// set cancelUrl
if p.Config.CancelUrl != "" {
req["cancelUrl"] = p.Config.CancelUrl
}
// set returnUrl
if p.Config.ReturnUrl != "" {
req["returnUrl"] = p.Config.ReturnUrl
}
// set product list
var products = []string{}
var qtys = []uint32{}
var prices = []uint32{}
for _, prod := range p.Products {
products = append(products, prod.Name)
qtys = append(qtys, prod.Qty)
prices = append(prices, prod.Price)
}
req["product"] = products
req["qty"] = qtys
req["price"] = prices
var jsonBody []byte
jsonBody, err := json.Marshal(req)
if err != nil {
log.Println(err)
}
// log.Println("Request Body : " + req)
result, err := Call("POST", "/api/v2/payment", bytes.NewBuffer(jsonBody), p.Config)
return result, err
}