-
Notifications
You must be signed in to change notification settings - Fork 1
/
oauth_test.go
66 lines (50 loc) · 1.37 KB
/
oauth_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
package gopaypal
import (
"flag"
"testing"
)
var (
clientID string
secret string
redirectURL string
identityToken string
oauthToken string
paymentID string
payerID string
)
func init() {
// Get client ID string pointer
flag.StringVar(&clientID, "clientid", "", "PayPal REST API client id")
// Get secret key string pointer
flag.StringVar(&secret, "secret", "", "PayPal REST API secret key")
// Get redirect URL
flag.StringVar(&redirectURL, "redirect", "", "PayPal REST API redirect uri")
// Get identity token
flag.StringVar(&identityToken, "iden", "", "PayPal Identity token")
// Get OAuth token
flag.StringVar(&oauthToken, "token", "", "PayPal OAuth token")
// Get payment ID
flag.StringVar(&paymentID, "paymentid", "", "PayPal payment ID")
// Get payer ID
flag.StringVar(&payerID, "payerid", "", "PayPal payer ID")
flag.Parse()
}
func TestClient_GetAccessToken(t *testing.T) {
if oauthToken != "" {
t.SkipNow()
}
// Create gopaypal client
client := NewClient(clientID, secret, SandBoxURL)
// Try to get access token
tokenres, err := client.GetAccessToken()
if err != nil {
t.Errorf("Cannot get PayPal OAuth access token: %v", err)
t.FailNow()
}
// Check if response is valid
if tokenres.AccessToken == "" {
t.Error("Wrong access token")
t.FailNow()
}
t.Logf("Your OAuth token is %v", tokenres.AccessToken)
}