-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
68 lines (57 loc) · 1.64 KB
/
example_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
package gobilling_test
import (
"fmt"
"time"
"github.com/bliof/gobilling"
"github.com/bliof/gobilling/gateway"
)
// Here we create a credit card object and validate it.
// Notice that when you validate the card the Brand will be
// automaticly added to the struct if it was not provided in
// advance.
func ExampleCreditCard_create() {
// The verificationValue is also known as CVV2, CVC2, or CID
creditCard := gobilling.CreditCard{
FirstName: "Rose",
LastName: "Tyler",
Number: "4242424242424242",
Month: 9,
Year: time.Now().Year() + 1,
VerificationValue: "000",
}
// When validating the credit card, the Brand will be automaticly filled
err := creditCard.Validate()
fmt.Printf("Is the card valid? %t\n", err == nil)
fmt.Printf("creditCard.Brand = %s\n", creditCard.Brand)
// Output:
// Is the card valid? true
// creditCard.Brand = visa
}
func ExampleGateway_interaction() {
gateway := gateway.PayPal{
User: "TestMerchant",
Password: "password",
Signature: "ashjdfasdkf",
Testing: true,
}
amount := 20.0
creditCard := gobilling.CreditCard{
FirstName: "Rose",
LastName: "Tyler",
Number: "4222222222222",
Month: 9,
Year: time.Now().Year() + 1,
VerificationValue: "000",
}
err := creditCard.Validate()
if err == nil {
response := gateway.Purchase(
amount,
&creditCard,
gobilling.BillingAddress{Street: "FirstStreet", City: "SanJose", State: "CA", Zip: "95131"},
)
if response.IsSuccessful() {
fmt.Printf("Charged %.2f to the credit card %s", amount, creditCard.DisplayNumber())
}
}
}