mirror of
https://github.com/plutov/paypal.git
synced 2025-02-02 15:10:36 +01:00
Initial types
This commit is contained in:
parent
c518ade777
commit
a4a6af6695
18
examples/main.go
Normal file
18
examples/main.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"paypalsdk"
|
||||||
|
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
client, err := paypalsdk.NewClient("123", "123", paypalsdk.APIBaseSandBox)
|
||||||
|
if err == nil {
|
||||||
|
fmt.Println("DEBUG: ClientID=" + client.ClientID + " APIBase=" + client.APIBase)
|
||||||
|
} else {
|
||||||
|
fmt.Println("ERROR: " + err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
16
paypal.go
Normal file
16
paypal.go
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package paypalsdk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewClient returns new Client struct
|
||||||
|
func NewClient(clientID string, secret string, APIBase string) (*Client, error) {
|
||||||
|
return &Client{
|
||||||
|
&http.Client{},
|
||||||
|
clientID,
|
||||||
|
secret,
|
||||||
|
APIBase,
|
||||||
|
nil,
|
||||||
|
}, nil
|
||||||
|
}
|
35
types.go
Normal file
35
types.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package paypalsdk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// APIBaseSandBox points to the sandbox (for testing) version of the API
|
||||||
|
APIBaseSandBox = "https://api.sandbox.paypal.com/v1"
|
||||||
|
|
||||||
|
// APIBaseLive points to the live version of the API
|
||||||
|
APIBaseLive = "https://api.paypal.com/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Client represents a Paypal REST API Client
|
||||||
|
Client struct {
|
||||||
|
client *http.Client
|
||||||
|
ClientID string
|
||||||
|
Secret string
|
||||||
|
APIBase string
|
||||||
|
Token *TokenResponse
|
||||||
|
}
|
||||||
|
|
||||||
|
// TokenResponse maps to the API response for the /oauth2/token endpoint
|
||||||
|
TokenResponse struct {
|
||||||
|
Scope string `json:"scope"` // "https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/vault/credit-card/.*",
|
||||||
|
Token string `json:"access_token"` // "EEwJ6tF9x5WCIZDYzyZGaz6Khbw7raYRIBV_WxVvgmsG",
|
||||||
|
Type string `json:"token_type"` // "Bearer",
|
||||||
|
AppID string `json:"app_id"` // "APP-6XR95014BA15863X",
|
||||||
|
ExpiresIn int `json:"expires_in"` // 28800
|
||||||
|
ExpiresAt time.Time `json:"expires_at"`
|
||||||
|
}
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user