paypale/types.go

75 lines
1.8 KiB
Go
Raw Normal View History

2015-10-14 07:30:28 +02:00
package paypalsdk
import (
2015-10-23 04:29:36 +02:00
"fmt"
"net/http"
2015-10-14 07:30:28 +02:00
)
const (
2015-10-23 04:29:36 +02:00
// APIBaseSandBox points to the sandbox (for testing) version of the API
APIBaseSandBox = "https://api.sandbox.paypal.com"
2015-10-14 07:30:28 +02:00
2015-10-23 04:29:36 +02:00
// APIBaseLive points to the live version of the API
APIBaseLive = "https://api.paypal.com"
2015-10-14 07:30:28 +02:00
)
type (
2015-10-23 04:29:36 +02:00
// 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 {
RefreshToken string `json:"refresh_token"`
2015-10-30 08:02:32 +01:00
Token string `json:"access_token"`
Type string `json:"token_type"`
2015-10-23 04:29:36 +02:00
ExpiresIn int `json:"expires_in"`
}
2015-10-14 07:30:28 +02:00
2015-10-23 04:29:36 +02:00
// ErrorResponse is used when a response has errors
ErrorResponse struct {
Response *http.Response `json:"-"`
Name string `json:"name"`
DebugID string `json:"debug_id"`
Message string `json:"message"`
InformationLink string `json:"information_link"`
Details []ErrorDetail `json:"details"`
}
2015-10-16 12:00:57 +02:00
2015-10-23 04:29:36 +02:00
// ErrorDetail map to error_details object
ErrorDetail struct {
Field string `json:"field"`
Issue string `json:"issue"`
}
2015-10-15 07:43:50 +02:00
2015-11-02 04:34:16 +01:00
// PaypalPaymentRequest - All info about paypal type payment
PaypalPaymentRequest struct {
Transactions []Transaction
}
// PaymentResponse structure
PaymentResponse struct {
}
// Transaction element
Transaction struct {
Amount Amount
2015-10-23 04:29:36 +02:00
}
2015-10-15 07:43:50 +02:00
2015-10-23 04:29:36 +02:00
// Amount to pay
Amount struct {
Currency string
2015-11-02 04:34:16 +01:00
Total float32
2015-10-23 04:29:36 +02:00
}
2015-10-14 07:30:28 +02:00
)
2015-10-15 07:43:50 +02:00
// Error method implementation for ErrorResponse struct
func (r *ErrorResponse) Error() string {
2015-10-23 04:29:36 +02:00
return fmt.Sprintf("%v %v: %d %v\nDetails: %v", r.Response.Request.Method, r.Response.Request.URL, r.Response.StatusCode, r.Message, r.Details)
2015-10-15 07:43:50 +02:00
}