Documentation ¶
Overview ¶
Package paypal_rest provides the PayPal REST-API provider driver
Paypal data types
Index ¶
- Constants
- Variables
- func InsertAuthorizationTx(db *sql.Tx, auth *Authorization) error
- func InsertTransactionDB(db *sql.DB, t *Transaction) error
- func InsertTransactionTx(db *sql.Tx, t *Transaction) error
- type Authorization
- type Config
- type Driver
- func (d *Driver) ApprovalHandler(tx *Transaction, p *payment.Payment) http.Handler
- func (d *Driver) Attach(ctx *service.Context, mux *mux.Router) error
- func (d *Driver) BadRequestHandler() http.Handler
- func (d *Driver) CancelHandler() http.Handler
- func (d *Driver) CancelPageHandler(p *payment.Payment) http.Handler
- func (d *Driver) InitPageHandler(p *payment.Payment) http.Handler
- func (d *Driver) InitPayment(p *payment.Payment, method *payment_method.Method) (http.Handler, error)
- func (d *Driver) InternalErrorHandler(p *payment.Payment) http.Handler
- func (d *Driver) NotFoundHandler(p *payment.Payment) http.Handler
- func (d *Driver) PaymentErrorHandler(p *payment.Payment) http.Handler
- func (d *Driver) PaymentStatusHandler(p *payment.Payment) http.Handler
- func (d *Driver) ReturnHandler() http.Handler
- func (d *Driver) ReturnPageHandler(p *payment.Payment) http.Handler
- func (d *Driver) SuccessHandler(p *payment.Payment) http.Handler
- type OAuthTransportStore
- type PayPalAmount
- type PayPalDetails
- type PayPalError
- type PayPalLink
- type PayPalPayerInfo
- type PayPalPaymentExecution
- type PayPalPaymentMethod
- type PayPalPaymentRequest
- type PayPalRedirectURLs
- type PayPalResource
- type PayPalResources
- type PayPalShippingAddress
- type PayPalTransaction
- type PaypalPayer
- type PaypalPayment
- type TokenCache
- type Transaction
- func NewPayPalPaymentTransaction(paypalP *PaypalPayment) (*Transaction, error)
- func TransactionByPaymentIDAndNonceDB(db *sql.DB, paymentID payment.PaymentID, nonce string) (*Transaction, error)
- func TransactionByPaymentIDAndNonceTx(db *sql.Tx, paymentID payment.PaymentID, nonce string) (*Transaction, error)
- func TransactionByPaymentIDAndTypeDB(db *sql.DB, paymentID payment.PaymentID, t string) (*Transaction, error)
- func TransactionByPaymentIDAndTypeTx(db *sql.Tx, paymentID payment.PaymentID, t string) (*Transaction, error)
- func TransactionCurrentByPaymentIDDB(db *sql.DB, paymentID payment.PaymentID) (*Transaction, error)
- func TransactionCurrentByPaymentIDTx(db *sql.Tx, paymentID payment.PaymentID) (*Transaction, error)
Constants ¶
const ( IntentSale = "sale" IntentAuth = "authorize" )
const ( TransactionTypeCreatePayment = "createPayment" TransactionTypeCreatePaymentResponse = "createPaymentResponse" TransactionTypeError = "error" TransactionTypeExecutePayment = "executePayment" TransactionTypeExecutePaymentResponse = "executePaymentResponse" TransactionTypeGetPayment = "getPayment" TransactionTypeGetPaymentResponse = "getPaymentResponse" )
PayPal transaction types
const Debug = false
Debug flag whether debugging is turned on
const ( // PaypalDriverPath is the (sub-)path under which PayPal driver endpoints // will be attached PaypalDriverPath = "/paypal" )
Variables ¶
var ( ErrNoToken = errors.New("no token") ErrNoTransport = errors.New("no transport") )
var ( ErrDatabase = errors.New("database error") ErrInternal = errors.New("paypal driver internal error") ErrHTTP = errors.New("HTTP error") ErrProvider = errors.New("provider error") )
var ( ErrNoLinks = errors.New("no links") ErrPayPalPaymentNoID = errors.New("paypal payment withoud ID") )
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 ConfigByPaymentMethodTx ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is the PayPal provider driver
func (*Driver) ApprovalHandler ¶
func (*Driver) BadRequestHandler ¶
func (*Driver) CancelHandler ¶
func (*Driver) CancelPageHandler ¶
func (*Driver) InitPageHandler ¶
InitPageHandler serves the init page (loading screen)
func (*Driver) InitPayment ¶
func (*Driver) InternalErrorHandler ¶
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) PaymentErrorHandler ¶
func (*Driver) PaymentStatusHandler ¶
func (*Driver) ReturnHandler ¶
func (*Driver) ReturnPageHandler ¶
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)
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
type PayPalError ¶
type PayPalLink ¶
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 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
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
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 (*Transaction) PayPalLinks ¶
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)