-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgogojudo_test.go
113 lines (85 loc) · 2.17 KB
/
gogojudo_test.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package gogojudo
import (
"math/rand"
"strconv"
"testing"
"time"
)
var JP *JudoPay
func TestNew(t *testing.T) {
JP = New()
if JP == New() {
t.Errorf("Created object is not alike to base struct.")
}
t.Logf("New Passed.")
}
func TestPayments(t *testing.T) {
// Using the current unit nanosecond as a rand seed since
// rand.Intn() uses the same default seed so you get duplicated
// in sequestial test runs
s1 := rand.NewSource(time.Now().UnixNano())
r1 := rand.New(s1)
var testPayment = CardPaymentModel{
CV2: "452",
CardNumber: "4976000000003436",
ConsumerReference: "0",
YourPaymentReference: strconv.Itoa(r1.Intn(10000)),
ExpiryDate: "12/20",
Amount: 1,
}
payment, err := JP.Payments(testPayment)
if err != nil {
t.Error("Payment failed, error: " + err.Error())
return
}
t.Logf("Payment Passed, Receipt ID: " + payment.ReceiptID)
// Get transaction test
t.Run("Get", func(t *testing.T) {
res, err := JP.Transaction(payment.ReceiptID)
if err != nil {
t.Errorf("Failed, error: " + err.Error())
return
}
if res.ReceiptID != "" {
t.Log("Pass, receipt ID: " + res.ReceiptID)
}
})
// Refund half the amount
t.Run("Partial Refund", func(t *testing.T) {
res, err := JP.Refund(RefundModel{
ReceiptID: payment.ReceiptID,
YourPaymentReference: strconv.Itoa(r1.Intn(10000)),
Amount: 0.50,
})
if err != nil {
t.Errorf("Failed, error: " + err.Error())
return
}
if res.ReceiptID != "" {
t.Log("Pass, receipt ID: " + res.ReceiptID)
}
})
// Refund the remaining amount for a full refund
t.Run("Finish Refund", func(t *testing.T) {
res, err := JP.Refund(RefundModel{
ReceiptID: payment.ReceiptID,
YourPaymentReference: strconv.Itoa(r1.Intn(10000)),
Amount: 0.50,
})
if err != nil {
t.Errorf("Failed, error: " + err.Error())
return
}
if res.ReceiptID != "" {
t.Log("Pass, receipt ID: " + res.ReceiptID)
}
})
}
func TestTransactions(t *testing.T) {
res, err := JP.ListTransactions(10, 0, TimeAscending)
if err != nil {
t.Error(err)
return
}
t.Logf("Pass: %v Transactions", res.ResultCount)
}