paypal_rest

package
v0.0.0-...-b3f3fbb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2015 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Overview

Package paypal_rest provides the PayPal REST-API provider driver

Paypal data types

Index

Constants

View Source
const (
	IntentSale = "sale"
	IntentAuth = "authorize"
)
View Source
const (
	TransactionTypeCreatePayment          = "createPayment"
	TransactionTypeCreatePaymentResponse  = "createPaymentResponse"
	TransactionTypeError                  = "error"
	TransactionTypeExecutePayment         = "executePayment"
	TransactionTypeExecutePaymentResponse = "executePaymentResponse"
	TransactionTypeGetPayment             = "getPayment"
	TransactionTypeGetPaymentResponse     = "getPaymentResponse"
)

PayPal transaction types

View Source
const Debug = false

Debug flag whether debugging is turned on

View Source
const (
	// PaypalDriverPath is the (sub-)path under which PayPal driver endpoints
	// will be attached
	PaypalDriverPath = "/paypal"
)

Variables

View Source
var (
	ErrNoToken     = errors.New("no token")
	ErrNoTransport = errors.New("no transport")
)
View Source
var (
	ErrDatabase = errors.New("database error")
	ErrInternal = errors.New("paypal driver internal error")
	ErrHTTP     = errors.New("HTTP error")
	ErrProvider = errors.New("provider error")
)
View Source
var (
	ErrNoLinks           = errors.New("no links")
	ErrPayPalPaymentNoID = errors.New("paypal payment withoud ID")
)
View Source
var (
	ErrConfigNotFound      = errors.New("config not found")
	ErrTransactionNotFound = errors.New("transaction not found")
)

Functions

func InsertAuthorizationTx

func InsertAuthorizationTx(db *sql.Tx, auth *Authorization) error

func InsertTransactionDB

func InsertTransactionDB(db *sql.DB, t *Transaction) error

func InsertTransactionTx

func InsertTransactionTx(db *sql.Tx, t *Transaction) error

Types

type Authorization

type Authorization struct {
	ProjectID       int64
	PaymentID       int64
	Timestamp       time.Time
	ValidUntil      time.Time
	State           string
	AuthorizationID string
	PaypalID        string
	Amount          string
	Currency        string
	Links           []byte
	Data            []byte
}

func NewPayPalPaymentAuthorization

func NewPayPalPaymentAuthorization(p *payment.Payment, paypalP *PaypalPayment) (*Authorization, error)

NewPayPalPaymentAuthorization creates an authorization entry for the given payment and PayPal payment type

The PayPal documentation is lacking information about how multiple transactions are handled. We will try a somewhat naïve approach here.

type Config

type Config struct {
	ProjectID int64
	MethodKey string
	Created   time.Time
	CreatedBy string

	Endpoint string
	ClientID string
	Secret   string
	Type     string
}

func ConfigByPaymentMethodDB

func ConfigByPaymentMethodDB(db *sql.DB, method *payment_method.Method) (*Config, error)

func ConfigByPaymentMethodTx

func ConfigByPaymentMethodTx(db *sql.Tx, method *payment_method.Method) (*Config, error)

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver is the PayPal provider driver

func (*Driver) ApprovalHandler

func (d *Driver) ApprovalHandler(tx *Transaction, p *payment.Payment) http.Handler

func (*Driver) Attach

func (d *Driver) Attach(ctx *service.Context, mux *mux.Router) error

func (*Driver) BadRequestHandler

func (d *Driver) BadRequestHandler() http.Handler

func (*Driver) CancelHandler

func (d *Driver) CancelHandler() http.Handler

func (*Driver) CancelPageHandler

func (d *Driver) CancelPageHandler(p *payment.Payment) http.Handler

func (*Driver) InitPageHandler

func (d *Driver) InitPageHandler(p *payment.Payment) http.Handler

InitPageHandler serves the init page (loading screen)

func (*Driver) InitPayment

func (d *Driver) InitPayment(p *payment.Payment, method *payment_method.Method) (http.Handler, error)

func (*Driver) InternalErrorHandler

func (d *Driver) InternalErrorHandler(p *payment.Payment) http.Handler

InternalErrorHandler serves the page notifying the user about a (critical) internal error. The payment can not continue.

It can handle a nil payment parameter.

func (*Driver) NotFoundHandler

func (d *Driver) NotFoundHandler(p *payment.Payment) http.Handler

func (*Driver) PaymentErrorHandler

func (d *Driver) PaymentErrorHandler(p *payment.Payment) http.Handler

func (*Driver) PaymentStatusHandler

func (d *Driver) PaymentStatusHandler(p *payment.Payment) http.Handler

func (*Driver) ReturnHandler

func (d *Driver) ReturnHandler() http.Handler

func (*Driver) ReturnPageHandler

func (d *Driver) ReturnPageHandler(p *payment.Payment) http.Handler

func (*Driver) SuccessHandler

func (d *Driver) SuccessHandler(p *payment.Payment) http.Handler

type OAuthTransportStore

type OAuthTransportStore struct {
	// contains filtered or unexported fields
}

func NewOAuthTransportStore

func NewOAuthTransportStore() *OAuthTransportStore

func (*OAuthTransportStore) PutTransport

func (c *OAuthTransportStore) PutTransport(projectID int64, methodKey string, tr *oauth.Transport)

func (*OAuthTransportStore) Transport

func (c *OAuthTransportStore) Transport(projectID int64, methodKey string) (*oauth.Transport, error)

type PayPalAmount

type PayPalAmount struct {
	Currency string         `json:"currency"`
	Total    string         `json:"total"`
	Details  *PayPalDetails `json:"details,omitempty"`
}

type PayPalDetails

type PayPalDetails struct {
	Shipping         string `json:"shipping,omitempty"`
	Subtotal         string `json:"subtotal,omitempty"`
	Tax              string `json:"tax,omitempty"`
	Fee              string `json:"fee,omitempty"`
	HandlingFee      string `json:"handling_fee,omitempty"`
	Insurance        string `json:"insurance,omitempty"`
	ShippingDiscount string `json:"shipping_discount,omitempty"`
}

PayPalDetails represents the PayPal "amount" details type

See https://developer.paypal.com/docs/api/#details-object

type PayPalError

type PayPalError struct {
	Name            string `json:"name"`
	Message         string `json:"message"`
	InformationLink string `json:"information_link"`
	Details         string `json:"details"`
}
type PayPalLink struct {
	HRef   string `json:"href"`
	Rel    string `json:"rel"`
	Method string `json:"method"`
}

type PayPalPayerInfo

type PayPalPayerInfo struct {
	Email           string                `json:"email,omitempty"`
	FirstName       string                `json:"first_name,omitempty"`
	LastName        string                `json:"last_name,omitempty"`
	PayerID         string                `json:"payer_id,omitempty"`
	Phone           string                `json:"phone,omitempty"`
	ShippingAddress PayPalShippingAddress `json:"shipping_address,omitempty"`
	TaxIDType       string                `json:"tax_id_type,omitempty"`
	TaxID           string                `json:"tax_id,omitempty"`
}

type PayPalPaymentExecution

type PayPalPaymentExecution struct {
	PayerID      string              `json:"payer_id"`
	Transactions []PayPalTransaction `json:"transactions,omitempty"`
}

type PayPalPaymentMethod

type PayPalPaymentMethod string
const (
	PayPalPaymentMethodPayPal PayPalPaymentMethod = "paypal"
	PayPalPaymentMethodCC                         = "credit_card"
)

type PayPalPaymentRequest

type PayPalPaymentRequest struct {
	Intent       string              `json:"intent"`
	Payer        PaypalPayer         `json:"payer"`
	Transactions []PayPalTransaction `json:"transactions"`
	RedirectURLs PayPalRedirectURLs  `json:"redirect_urls,omitempty"`
}

type PayPalRedirectURLs

type PayPalRedirectURLs struct {
	ReturnURL string `json:"return_url"`
	CancelURL string `json:"cancel_url"`
}

type PayPalResource

type PayPalResource struct {
	ID                        string       `json:"id"`
	Amount                    PayPalAmount `json:"amount"`
	IsFinalCapture            bool         `json:"is_final_capture"`
	Description               string       `json:"string,omitempty"`
	CreateTime                string       `json:"create_time"`
	State                     string       `json:"state"`
	CaptureID                 string       `json:"capture_id,omitempty"`
	ParentPayment             string       `json:"parent_payment"`
	ValidUntil                string       `json:"valid_until,omitempty"`
	UpdateTime                string       `json:"update_time"`
	PaymentMode               string       `json:"payment_mode,omitempty"`
	PendingReason             string       `json:"pending_reason,omitempty"`
	ReasonCode                string       `json:"reason_code,omitempty"`
	ClearingTime              string       `json:"clearing_time,omitempty"`
	ProtectionEligibility     string       `json:"protection_eligibility,omitempty"`
	ProtectionEligibilityType string       `json:"protection_eligibility_type,omitempty"`
	Links                     []PayPalLink `json:"links,omitempty"`
}

PayPalResource represents one of sale, authorization, capture or refund object

type PayPalResources

type PayPalResources []map[string]PayPalResource

func (PayPalResources) Resources

func (p PayPalResources) Resources(t string) []PayPalResource

type PayPalShippingAddress

type PayPalShippingAddress struct {
	RecipientName string `json:"recipient_name,omitempty"`
	Type          string `json:"type,omitempty"`
	Line1         string `json:"line1"`
	Line2         string `json:"line2,omitempty"`
	City          string `json:"city"`
	CountryCode   string `json:"country_code"`
	PostalCode    string `json:"postal_code,omitempty"`
	State         string `json:"state,omitempty"`
	Phone         string `json:"phone,omitempty"`
}

type PayPalTransaction

type PayPalTransaction struct {
	Amount           PayPalAmount    `json:"amount"`
	Description      string          `json:"description,omitempty"`
	RelatedResources PayPalResources `json:"related_resources,omitempty"`
	InvoiceNumber    string          `json:"invoice_number,omitempty"`
	Custom           string          `json:"custom,omitempty"`
	SoftDescriptor   string          `json:"soft_descriptor,omitempty"`
}

type PaypalPayer

type PaypalPayer struct {
	PaymentMethod PayPalPaymentMethod `json:"payment_method"`
	Status        string              `json:"status,omitempty"`
}

PaypalPayer represents the "payer" object as defined by the PayPal REST-API

See https://developer.paypal.com/docs/api/#payer-object

type PaypalPayment

type PaypalPayment struct {
	PayPalPaymentRequest

	ID         string       `json:"id"`
	CreateTime string       `json:"create_time"`
	State      string       `json:"state"`
	UpdateTime string       `json:"update_time"`
	Links      []PayPalLink `json:"links"`
}

type TokenCache

type TokenCache struct {
	// contains filtered or unexported fields
}

func NewTokenCache

func NewTokenCache() *TokenCache

func (*TokenCache) PutToken

func (t *TokenCache) PutToken(token *oauth.Token) error

func (*TokenCache) Token

func (t *TokenCache) Token() (*oauth.Token, error)

type Transaction

type Transaction struct {
	ProjectID        int64
	PaymentID        int64
	Timestamp        time.Time
	Type             string
	Nonce            sql.NullString
	Intent           sql.NullString
	PaypalID         sql.NullString
	PayerID          sql.NullString
	PaypalCreateTime *time.Time
	PaypalState      sql.NullString
	PaypalUpdateTime *time.Time
	Links            []byte
	Data             []byte
}

Transaction represents a transaction on a paypal payment

It can be one of the following:

  • A representation of a request.
  • A representation of a response.
  • A representation of a local change to a transaction.

It also keeps the state of the paypal payment, i.e. the most recent transaction will denote what the state of the payment is.

func NewPayPalPaymentTransaction

func NewPayPalPaymentTransaction(paypalP *PaypalPayment) (*Transaction, error)

func TransactionByPaymentIDAndNonceDB

func TransactionByPaymentIDAndNonceDB(db *sql.DB, paymentID payment.PaymentID, nonce string) (*Transaction, error)

func TransactionByPaymentIDAndNonceTx

func TransactionByPaymentIDAndNonceTx(db *sql.Tx, paymentID payment.PaymentID, nonce string) (*Transaction, error)

func TransactionByPaymentIDAndTypeDB

func TransactionByPaymentIDAndTypeDB(db *sql.DB, paymentID payment.PaymentID, t string) (*Transaction, error)

func TransactionByPaymentIDAndTypeTx

func TransactionByPaymentIDAndTypeTx(db *sql.Tx, paymentID payment.PaymentID, t string) (*Transaction, error)

func TransactionCurrentByPaymentIDDB

func TransactionCurrentByPaymentIDDB(db *sql.DB, paymentID payment.PaymentID) (*Transaction, error)

func TransactionCurrentByPaymentIDTx

func TransactionCurrentByPaymentIDTx(db *sql.Tx, paymentID payment.PaymentID) (*Transaction, error)
func (t *Transaction) PayPalLinks() (map[string]*PayPalLink, error)

func (*Transaction) SetIntent

func (t *Transaction) SetIntent(intent string)

func (*Transaction) SetNonce

func (t *Transaction) SetNonce(nonce string)

func (*Transaction) SetPayerID

func (t *Transaction) SetPayerID(id string)

func (*Transaction) SetPaypalID

func (t *Transaction) SetPaypalID(id string)

func (*Transaction) SetState

func (t *Transaction) SetState(state string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL