mirror of
https://github.com/plutov/paypal.git
synced 2025-02-02 15:10:36 +01:00
new types
This commit is contained in:
parent
0277b266bf
commit
71e0a81e64
8
payment.go
Normal file
8
payment.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package paypalsdk
|
||||||
|
|
||||||
|
import ()
|
||||||
|
|
||||||
|
// CreateDirectCreditCardPatment sends request with payment
|
||||||
|
func CreateDirectCreditCardPatment(cc CreditCrad, amount Amount) error {
|
||||||
|
return nil
|
||||||
|
}
|
105
types.go
105
types.go
|
@ -1,64 +1,79 @@
|
||||||
package paypalsdk
|
package paypalsdk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"fmt"
|
||||||
"fmt"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// APIBaseSandBox points to the sandbox (for testing) version of the API
|
// APIBaseSandBox points to the sandbox (for testing) version of the API
|
||||||
APIBaseSandBox = "https://api.sandbox.paypal.com"
|
APIBaseSandBox = "https://api.sandbox.paypal.com"
|
||||||
|
|
||||||
// APIBaseLive points to the live version of the API
|
// APIBaseLive points to the live version of the API
|
||||||
APIBaseLive = "https://api.paypal.com"
|
APIBaseLive = "https://api.paypal.com"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Client represents a Paypal REST API Client
|
// Client represents a Paypal REST API Client
|
||||||
Client struct {
|
Client struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
ClientID string
|
ClientID string
|
||||||
Secret string
|
Secret string
|
||||||
APIBase string
|
APIBase string
|
||||||
Token *TokenResponse
|
Token *TokenResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
// TokenResponse maps to the API response for the /oauth2/token endpoint
|
// TokenResponse maps to the API response for the /oauth2/token endpoint
|
||||||
TokenResponse struct {
|
TokenResponse struct {
|
||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
Token string `json:"access_token"`
|
Token string `json:"access_token"`
|
||||||
Type string `json:"token_type"`
|
Type string `json:"token_type"`
|
||||||
AppID string `json:"app_id"`
|
AppID string `json:"app_id"`
|
||||||
ExpiresIn int `json:"expires_in"`
|
ExpiresIn int `json:"expires_in"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RefreshTokenResponse maps to the API response for the /v1/identity/openidconnect/tokenservice
|
// RefreshTokenResponse maps to the API response for the /v1/identity/openidconnect/tokenservice
|
||||||
RefreshTokenResponse struct {
|
RefreshTokenResponse struct {
|
||||||
Type string `json:"token_type"`
|
Type string `json:"token_type"`
|
||||||
RefreshToken string `json:"refresh_token"`
|
RefreshToken string `json:"refresh_token"`
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
ExpiresIn int `json:"expires_in"`
|
ExpiresIn int `json:"expires_in"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrorResponse is used when a response has errors
|
// ErrorResponse is used when a response has errors
|
||||||
ErrorResponse struct {
|
ErrorResponse struct {
|
||||||
Response *http.Response `json:"-"`
|
Response *http.Response `json:"-"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
DebugID string `json:"debug_id"`
|
DebugID string `json:"debug_id"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
InformationLink string `json:"information_link"`
|
InformationLink string `json:"information_link"`
|
||||||
Details []ErrorDetail `json:"details"`
|
Details []ErrorDetail `json:"details"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrorDetails map to error_details object
|
// ErrorDetail map to error_details object
|
||||||
ErrorDetail struct {
|
ErrorDetail struct {
|
||||||
Field string `json:"field"`
|
Field string `json:"field"`
|
||||||
Issue string `json:"issue"`
|
Issue string `json:"issue"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreditCrad - All info about customer's CC
|
||||||
|
CreditCrad struct {
|
||||||
|
Type string
|
||||||
|
Number string
|
||||||
|
ExpireYear int
|
||||||
|
ExpireMonth int
|
||||||
|
FirstName string
|
||||||
|
LastName string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Amount to pay
|
||||||
|
Amount struct {
|
||||||
|
Currency string
|
||||||
|
Amount float32
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error method implementation for ErrorResponse struct
|
// Error method implementation for ErrorResponse struct
|
||||||
func (r *ErrorResponse) Error() string {
|
func (r *ErrorResponse) Error() string {
|
||||||
return fmt.Sprintf("%v %v: %d %v\nDetails: %v", r.Response.Request.Method, r.Response.Request.URL, r.Response.StatusCode, r.Message, r.Details)
|
return fmt.Sprintf("%v %v: %d %v\nDetails: %v", r.Response.Request.Method, r.Response.Request.URL, r.Response.StatusCode, r.Message, r.Details)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user