From 71e0a81e6448b0886745cfd91c4dab4c839f7f4b Mon Sep 17 00:00:00 2001 From: Aliaksandr Pliutau Date: Fri, 23 Oct 2015 09:29:36 +0700 Subject: [PATCH] new types --- payment.go | 8 ++++ types.go | 105 ++++++++++++++++++++++++++++++----------------------- 2 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 payment.go diff --git a/payment.go b/payment.go new file mode 100644 index 0000000..0625261 --- /dev/null +++ b/payment.go @@ -0,0 +1,8 @@ +package paypalsdk + +import () + +// CreateDirectCreditCardPatment sends request with payment +func CreateDirectCreditCardPatment(cc CreditCrad, amount Amount) error { + return nil +} diff --git a/types.go b/types.go index 8307d76..d7d5f00 100644 --- a/types.go +++ b/types.go @@ -1,64 +1,79 @@ package paypalsdk import ( - "net/http" - "fmt" + "fmt" + "net/http" ) - const ( - // APIBaseSandBox points to the sandbox (for testing) version of the API - APIBaseSandBox = "https://api.sandbox.paypal.com" + // APIBaseSandBox points to the sandbox (for testing) version of the API + APIBaseSandBox = "https://api.sandbox.paypal.com" - // APIBaseLive points to the live version of the API - APIBaseLive = "https://api.paypal.com" + // APIBaseLive points to the live version of the API + APIBaseLive = "https://api.paypal.com" ) type ( - // Client represents a Paypal REST API Client - Client struct { - client *http.Client - ClientID string - Secret string - APIBase string - Token *TokenResponse - } + // 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"` - Token string `json:"access_token"` - Type string `json:"token_type"` - AppID string `json:"app_id"` - ExpiresIn int `json:"expires_in"` - } + // TokenResponse maps to the API response for the /oauth2/token endpoint + TokenResponse struct { + Scope string `json:"scope"` + Token string `json:"access_token"` + Type string `json:"token_type"` + AppID string `json:"app_id"` + ExpiresIn int `json:"expires_in"` + } - // RefreshTokenResponse maps to the API response for the /v1/identity/openidconnect/tokenservice - RefreshTokenResponse struct { - Type string `json:"token_type"` - RefreshToken string `json:"refresh_token"` - AccessToken string `json:"access_token"` - ExpiresIn int `json:"expires_in"` - } + // RefreshTokenResponse maps to the API response for the /v1/identity/openidconnect/tokenservice + RefreshTokenResponse struct { + Type string `json:"token_type"` + RefreshToken string `json:"refresh_token"` + AccessToken string `json:"access_token"` + ExpiresIn int `json:"expires_in"` + } - // 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"` - } + // 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"` + } - // ErrorDetails map to error_details object - ErrorDetail struct { - Field string `json:"field"` - Issue string `json:"issue"` - } + // ErrorDetail map to error_details object + ErrorDetail struct { + Field string `json:"field"` + 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 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) }