-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
92 lines (76 loc) · 2.05 KB
/
utils.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package paygent
import (
"fmt"
"strconv"
"time"
"github.com/qor/gomerchant"
)
var PaygentServerTimeZone, _ = time.LoadLocation("Asia/Tokyo")
type paramsInterface interface {
Get(string) (interface{}, bool)
}
func get3DModeParams(params paramsInterface) (bool, *SecureCodeParams) {
if value, ok := params.Get("Paygent3DMode"); ok {
if fmt.Sprint(value) == "true" {
if value, ok := params.Get("Paygent3DParams"); ok {
if v, ok := value.(SecureCodeParams); ok {
return true, &v
}
if v, ok := value.(*SecureCodeParams); ok {
return true, v
}
}
}
}
return false, nil
}
func getPaymentID(params paramsInterface) (string, bool) {
paymentID, ok := params.Get("payment_id")
return fmt.Sprint(paymentID), ok
}
func extractTransactionFromPaygentResponse(params Response) (transaction gomerchant.Transaction) {
transaction.ID, _ = getPaymentID(params)
if v, ok := params.Get("currency_code"); ok {
transaction.Currency = fmt.Sprint(v)
} else {
transaction.Currency = "JPY"
}
if v, ok := params.Get("payment_init_date"); ok {
if t, err := time.ParseInLocation("20060102150405", fmt.Sprint(v), PaygentServerTimeZone); err == nil {
transaction.CreatedAt = &t
}
}
if v, ok := params.Get("payment_amount"); ok {
if i, err := strconv.Atoi(fmt.Sprint(v)); err == nil {
transaction.Amount = i
}
}
if v, ok := params.Get("payment_status"); ok {
transaction.Status = fmt.Sprint(v)
switch transaction.Status {
case "20", "30", "35":
transaction.Paid = true
case "40", "41":
transaction.Paid = true
transaction.Captured = true
case "32", "33", "42", "55", "60":
transaction.Cancelled = true
}
}
return
}
// Paygent Status Code meaning
// 10 Applied
// 11 Authorization failed
// 13 3D Secure suspended
// 14 3D Secure authentication
// 20 Authorization succeeded
// 30 Sales being requested
// 35 Sales requested
// 40 Cleared
// 41 Cleared (sales cancellation overdue)
// 32 Authorization cancelled
// 33 Authorization expired
// 42 Sales being cancelled
// 55 Sales cancellation requested
// 60 Sales cancelled