Documentation
¶
Index ¶
- Constants
- Variables
- func NewRequest(method, url string, payload interface{}) (*http.Request, error)
- type Address
- type AddressType
- type Amount
- type AuthWithAmountReq
- type Authorization
- type AuthorizationState
- type Capture
- type CaptureState
- type Client
- func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error)
- func (c *Client) CreatePayment(p Payment) (*CreatePaymentResp, error)
- func (c *Client) ExecutePayment(paymentID, payerID string, transactions []Transaction) (*ExecutePaymentResp, error)
- func (c *Client) GetAccessToken() (*TokenResp, error)
- func (c *Client) GetAuthorization(authID string) (*Authorization, error)
- func (c *Client) GetCapture(captureID string) (*Capture, error)
- func (c *Client) GetPayment(id string) (*Payment, error)
- func (c *Client) GetRefund(refundID string) (*Refund, error)
- func (c *Client) GetSale(saleID string) (*Sale, error)
- func (c *Client) ListPayments(filter map[string]string) ([]Payment, error)
- func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorization, error)
- func (c *Client) RefundCapture(captureID string, a *Amount) (*Refund, error)
- func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error)
- func (c *Client) Send(req *http.Request, v interface{}) error
- func (c *Client) SendWithAuth(req *http.Request, v interface{}) error
- func (c *Client) StoreInVault(cc VaultRequest) (*VaultResponse, error)
- func (c *Client) VoidAuthorization(authID string) (*Authorization, error)
- type CreatePaymentResp
- type CreditCard
- type CreditCardState
- type CreditCardToken
- type Details
- type ErrorDetail
- type ErrorResponse
- type ExecutePaymentResp
- type FundingInstrument
- type Item
- type ItemList
- type Links
- type ListPaymentsResp
- type Order
- type OrderState
- type Payer
- type PayerInfo
- type PayerStatus
- type Payment
- type PaymentError
- type PaymentErrorDetails
- type PaymentExecution
- type PaymentIntent
- type PaymentMethod
- type PaymentState
- type PendingReason
- type ProtectionEligibility
- type ProtectionEligibilityType
- type ReasonCode
- type RedirectURLs
- type Refund
- type RefundReq
- type RefundState
- type Resource
- type Sale
- type SalePaymentMode
- type SaleState
- type ShippingAddress
- type TaxIDType
- type TokenResp
- type Transaction
- type VaultRequest
- type VaultResponse
Constants ¶
const ( // APIBaseSandBox points to the sandbox (for testing) version of the API APIBaseSandBox = "https://api.sandbox.paypal.com/v1" // APIBaseLive points to the live version of the API APIBaseLive = "https://api.paypal.com/v1" )
Variables ¶
var ( AuthorizationStatePending AuthorizationState = "pending" AuthorizationStateAuthorized AuthorizationState = "authorized" AuthorizationStateCaptured AuthorizationState = "captured" AuthorizationStatePartiallyCaptured AuthorizationState = "partially_captured" AuthorizationStateExpired AuthorizationState = "expired" AuthorizationStateVoided AuthorizationState = "voided" CaptureStatePending CaptureState = "pending" CaptureStateCompleted CaptureState = "completed" CaptureStateRefunded CaptureState = "refunded" CaptureStatePartiallyRefunded CaptureState = "partially_refunded" CreditCardStateExpired CreditCardState = "expired" CreditCardStateOK CreditCardState = "ok" OrderStatePending OrderState = "PENDING" OrderStateCompleted OrderState = "COMPLETED" OrderStateRefunded OrderState = "REFUNDED" OrderStatePartiallyRefunded = "PARTIALLY_REFUNDED" PendingReasonPayerShippingUnconfirmed PendingReason = "PAYER-SHIPPING-UNCONFIRMED" PendingReasonMultiCurrency PendingReason = "MULTI-CURRENCY" PendingReasonRiskReview PendingReason = "RISK-REVIEW" PendingReasonRegulatoryReview PendingReason = "REGULATORY-REVIEW" PendingReasonVerificationRequired PendingReason = "VERIFICATION-REQUIRED" PendingReasonOrder PendingReason = "ORDER" PendingReasonOther PendingReason = "OTHER" ReasonCodeChargeback ReasonCode = "CHARGEBACK" ReasonCodeGuarantee ReasonCode = "GUARANTEE" ReasonCodeBuyerComplaint ReasonCode = "BUYER_COMPLAINT" ReasonCodeRefund ReasonCode = "REFUND" ReasonCodeUnconfirmedShippingAddress ReasonCode = "UNCONFIRMED_SHIPPING_ADDRESS" ReasonCodeEcheck ReasonCode = "ECHECK" ReasonCodeInternationalWithdrawal ReasonCode = "INTERNATIONAL_WITHDRAWAL" ReasonCodeReceivingPreferenceMandatesManualAction ReasonCode = "RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION" ReasonCodePaymentReview ReasonCode = "PAYMENT_REVIEW" ReasonCodeRegulatoryReview ReasonCode = "REGULATORY_REVIEW" ReasonCodeUnilateral ReasonCode = "UNILATERAL" ReasonCodeVerificationRequired ReasonCode = "VERIFICATION_REQUIRED" ProtectionEligibilityEligible ProtectionEligibility = "ELIGIBLE" ProtectionEligibilityPartiallyEligible ProtectionEligibility = "PARTIALLY_ELIGIBLE" ProtectionEligibilityIneligible ProtectionEligibility = "INELIGIBLE" ProtectionEligibilityTypeEligible ProtectionEligibilityType = "ELIGIBLE" ProtectionEligibilityTypeItemNotReceivedEligible ProtectionEligibilityType = "ITEM_NOT_RECEIVED_ELIGIBLE" ProtectionEligibilityTypeIneligible ProtectionEligibilityType = "INELIGIBLE" PaymentMethodCreditCard PaymentMethod = "credit_card" PaymentMethodPaypal PaymentMethod = "paypal" PayerStatusVerified PayerStatus = "VERIFIED" PayerStatusUnverified PayerStatus = "UNVERIFIED" PaymentStateCreated PaymentState = "created" PaymentStateApproved PaymentState = "approved" PaymentStateFailed PaymentState = "failed" PaymentStatePending PaymentState = "pending" PaymentStateCanceled PaymentState = "canceled" PaymentStateExpired PaymentState = "expired" AddressTypeResidential AddressType = "residential" AddressTypeBusiness AddressType = "business" AddressTypeMailbox AddressType = "mailbox" PaymentIntentSale PaymentIntent = "sale" PaymentIntentAuthorize PaymentIntent = "authorize" PaymentIntentOrder PaymentIntent = "order" RefundStatePending RefundState = "pending" RefundStateCompleted RefundState = "completed" RefundStateFailed RefundState = "failed" SaleStatePending SaleState = "pending" SaleStateCompleted SaleState = "completed" SaleStateRefunded SaleState = "refunded" SaleStatePartiallyRefunded SaleState = "partially_refunded" SalePaymentModeInstantTransfer SalePaymentMode = "INSTANT_TRANSFER" SalePaymentModeManualBankTransfer SalePaymentMode = "MANUAL_BANK_TRANSFER" SalePaymentModeDelayedTransfer SalePaymentMode = "DELAYED_TRANSFER" SalePaymentModeEcheck SalePaymentMode = "ECHECK" )
Functions ¶
Types ¶
type Address ¶
type Address struct {
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"`
}
Address maps to address object
type AddressType ¶
type AddressType string
type Amount ¶
type Amount struct {
Currency string `json:"currency"`
Total string `json:"total"`
Details *Details `json:"details,omitempty"`
}
Amount maps to the amount object
type AuthWithAmountReq ¶
type AuthWithAmountReq struct {
Amount *Amount `json:"amount"`
}
type Authorization ¶
type Authorization struct {
Id int64 `json:"-"`
Amount *Amount `json:"amount,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
State AuthorizationState `json:"state,omitempty"`
ParentPayment string `json:"parent_payment,omitempty"`
ID string `json:"id,omitempty"`
ValidUntil *time.Time `json:"valid_until,omitempty"`
Links []Links `json:"links,omitempty"`
ClearingTime string `json:"clearing_time,omitempty"`
ProtectionEligibility string `json:"protection_eligibility,omitempty"`
ProtectionEligibilityType string `json:"protection_eligibility_type,omitempty"`
}
Authorization maps to the authorization object
type AuthorizationState ¶
type AuthorizationState string
type Capture ¶
type Capture struct {
Id int64 `json:"-"`
Amount *Amount `json:"amount,omitempty"`
IsFinalCapture bool `json:"is_final_capture"`
CreateTime *time.Time `json:"create_time,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
State CaptureState `json:"state,omitempty"`
ParentPayment string `json:"parent_payment,omitempty"`
ID string `json:"id,omitempty"`
Links []Links `json:"links,omitempty"`
}
Capture maps to the capture object
type CaptureState ¶
type CaptureState string
type Client ¶
type Client struct {
ClientID string
Secret string
APIBase string
Token *TokenResp
// contains filtered or unexported fields
}
Client represents a Paypal REST API Client
func (*Client) CaptureAuthorization ¶
func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error)
CaptureAuthorization captures and process an existing authorization. To use this method, the original payment must have Intent set to PaymentIntentAuthorize
func (*Client) CreatePayment ¶
func (c *Client) CreatePayment(p Payment) (*CreatePaymentResp, error)
CreatePayment creates a payment in Paypal
func (*Client) ExecutePayment ¶
func (c *Client) ExecutePayment(paymentID, payerID string, transactions []Transaction) (*ExecutePaymentResp, error)
ExecutePayment completes an approved Paypal payment that has been approved by the payer
func (*Client) GetAccessToken ¶
GetAcessToken request a new access token from Paypal
func (*Client) GetAuthorization ¶
func (c *Client) GetAuthorization(authID string) (*Authorization, error)
GetAuthorization returns an authorization by ID
func (*Client) GetCapture ¶
GetCapture returns details about a captured payment
func (*Client) GetPayment ¶
GetPayment fetches a payment in Paypal
func (*Client) ListPayments ¶
ListPayments retrieve payments resources from Paypal
func (*Client) ReauthorizeAuthorization ¶
func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorization, error)
ReauthorizeAuthorization reauthorize a Paypal account payment. Paypal recommends that a payment should be reauthorized after the initial 3-day honor period to ensure that funds are still available. Only paypal account payments can be re- authorized
func (*Client) RefundCapture ¶
RefundCapture refund a captured payment. For partial refunds, a lower Amount object can be passed in.
func (*Client) RefundSale ¶
RefundSale refunds a completed payment and accepts an optional Amount struct. If Amount is provided, a partial refund is requested, or else a full refund is made instead
func (*Client) Send ¶
Send makes a request to the API, the response body will be unmarshaled into v, or if v is an io.Writer, the response will be written to it without decoding
func (*Client) SendWithAuth ¶
SendWithAuth makes a request to the API and apply OAuth2 header automatically. If the access token soon to be expired, it will try to get a new one before making the main request
func (*Client) StoreInVault ¶
func (c *Client) StoreInVault(cc VaultRequest) (*VaultResponse, error)
StoreInVault will store credit card details with PayPal.
func (*Client) VoidAuthorization ¶
func (c *Client) VoidAuthorization(authID string) (*Authorization, error)
VoidAuthorization voids a previously authorized payment. A fully captured authorization cannot be voided
type CreatePaymentResp ¶
type CreditCard ¶
type CreditCard struct {
ID string `json:"id,omitempty"`
PayerID string `json:"payer_id,omitempty"`
Number string `json:"number"`
Type string `json:"type"`
ExpireMonth string `json:"expire_month"`
ExpireYear string `json:"expire_year"`
CVV2 string `json:"cvv2,omitempty"`
FirstName string `json:"first_name,omitempty"`
LastName string `json:"last_name,omitempty"`
BillingAddress *Address `json:"billing_address,omitempty"`
State CreditCardState `json:"state,omitempty"`
ValidUntil string `json:"valid_until,omitempty"`
}
CreditCard maps to credit_card object
type CreditCardState ¶
type CreditCardState string
type CreditCardToken ¶
type CreditCardToken struct {
CreditCardID string `json:"credit_card_id"`
PayerID string `json:"payer_id,omitempty"`
Last4 string `json:"last4,omitempty"`
ExpireYear string `json:"expire_year,omitempty"`
ExpireMonth string `json:"expire_month,omitempty"`
}
CreditCardToken maps to credit_card_token object
type Details ¶
type Details struct {
Id int64 `json:"-"`
Shipping string `json:"shipping,omitempty"`
Subtotal string `json:"subtotal"`
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"`
}
Details maps to the details object
type ErrorDetail ¶
ErrorDetails map to error_details object
type ErrorResponse ¶
type ErrorResponse struct {
// HTTP response that caused this error
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 contains errors maps to error object
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type ExecutePaymentResp ¶
type ExecutePaymentResp struct {
Intent PaymentIntent `json:"intent"`
Payer *Payer `json:"payer"`
Transactions []Transaction `json:"transactions"`
Links []Links `json:"links"`
}
type FundingInstrument ¶
type FundingInstrument struct {
CreditCard *CreditCard `json:"credit_card,omitempty"`
CreditCardToken *CreditCardToken `json:"credit_card_token,omitempty"`
}
FundingInstrument maps to funding_instrument object
type Item ¶
type Item struct {
Quantity int `json:"quantity"`
Name string `json:"name"`
Price string `json:"price"`
Currency string `json:"currency"`
SKU string `json:"sku,omitempty"`
Description string `json:"description,omitempty"`
Tax string `json:"tax,omitempty"`
}
Item maps to item object
type ItemList ¶
type ItemList struct {
Items []Item `json:"items,omitempty"`
ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
}
ItemList maps to item_list object
type Links ¶
type Links struct {
Href string `json:"href"`
Rel string `json:"rel"`
// TODO: Support HyperSchema with its multiple types per field
// TargetSchema HyperSchema `json:"targetSchema"`
Method string `json:"method"`
Enctype string `json:"enctype"`
}
Links maps to links object
type ListPaymentsResp ¶
type ListPaymentsResp struct {
Payments []Payment `json:"payments"`
}
type Order ¶
type Order struct {
ID string `json:"id,omitempty"`
PurchaseUnitReferenceID string `json:"purchase_unit_reference_id,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
Amount []Amount `json:"amount,omitempty"`
State OrderState `json:"state,omitempty"`
PendingReason PendingReason `json:"pending_reason,omitempty"`
ReasonCode ReasonCode `json:"reason_code,omitempty"`
ClearingTime string `json:"clearing_time,omitempty"`
ProtectionEligibility string `json:"protection_eligibility,omitempty"`
ProtectionEligibilityType string `json:"protection_eligiblity_type,omitempty"`
}
Order maps to order object
type OrderState ¶
type OrderState string
type Payer ¶
type Payer struct {
PaymentMethod PaymentMethod `json:"payment_method"`
FundingInstruments []FundingInstrument `json:"funding_instruments,omitempty"`
PayerInfo *PayerInfo `json:"payer_info,omitempty"`
Status PayerStatus `json:"payer_status,omitempty"`
}
Payer maps to payer object
type PayerInfo ¶
type PayerInfo 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 *ShippingAddress `json:"shipping_address,omitempty"`
TaxIDType TaxIDType `json:"tax_id_type,omitempty"`
TaxID string `json:"tax_id,omitempty"`
}
PayerInfo maps to payer_info object
type PayerStatus ¶
type PayerStatus string
type Payment ¶
type Payment struct {
Intent PaymentIntent `json:"intent"`
Payer *Payer `json:"payer"`
Transactions []Transaction `json:"transactions"`
RedirectURLs *RedirectURLs `json:"redirect_urls,omitempty"`
ID string `json:"id,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
State PaymentState `json:"state,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
ExperienceProfileID string `json:"experience_profile_id,omitempty"`
}
Payment maps to payment object
type PaymentError ¶
type PaymentError struct {
Name string `json:"name,omitempty"`
DebugID string `json:"debug_id,omitempty"`
Message string `json:"message,omitempty"`
InformationLink string `json:"information_link,omitempty"`
Details *PaymentErrorDetails `json:"details,omitempty"`
}
PaymentError maps to the error object for payments
type PaymentErrorDetails ¶
type PaymentErrorDetails struct {
Field string `json:"field,omitempty"`
Issue string `json:"issue,omitempty"`
}
PaymentErrorDetails maps to the error_details object for payments
type PaymentExecution ¶
type PaymentExecution struct {
PayerID string `json:"payer_id,omitempty"`
Transactions []Transaction `json:"transactions,omitempty"`
}
PaymentExecution maps to payment_execution object
type PaymentIntent ¶
type PaymentIntent string
type PaymentMethod ¶
type PaymentMethod string
type PaymentState ¶
type PaymentState string
type PendingReason ¶
type PendingReason string
type ProtectionEligibility ¶
type ProtectionEligibility string
type ProtectionEligibilityType ¶
type ProtectionEligibilityType string
type ReasonCode ¶
type ReasonCode string
type RedirectURLs ¶
type RedirectURLs struct {
ReturnURL string `json:"return_url,omitempty"`
CancelURL string `json:"cancel_url,omitempty"`
}
RedirectURLs maps to redirect_urls object
type Refund ¶
type Refund struct {
ID string `json:"id,omitempty"`
Amount *Amount `json:"amount,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
State RefundState `json:"state,omitempty"`
CaptureID string `json:"capture_id,omitempty"`
ParentPayment string `json:"parent_payment,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
}
Refund maps to refund object
type RefundState ¶
type RefundState string
type Resource ¶
type Resource struct {
Sale *Sale `json:"sale,omitempty"`
Authorization *Authorization `json:"authorization,omitempty"`
Capture *Capture `json:"capture,omitempty"`
Refund *Refund `json:"refund,omitempty"`
}
Resource can be either sale, authorization, capture or refund object
type Sale ¶
type Sale struct {
ID string `json:"id,omitempty"`
Amount *Amount `json:"amount,omitempty"`
Description string `json:"description,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
State SaleState `json:"state,omitempty"`
ParentPayment string `json:"parent_payment,omitempty"`
UpdateTime *time.Time `json:"update_time,omitempty"`
PaymentMode SalePaymentMode `json:"payment_mode,omitempty"`
PendingReason PendingReason `json:"pending_reason,omitempty"`
ReasonCode ReasonCode `json:"reason_code,omitempty"`
ClearingTime string `json:"clearing_time,omitempty"`
ProtectionEligibility ProtectionEligibility `json:"protection_eligibility,omitempty"`
ProtectionEligibilityType ProtectionEligibilityType `json:"protection_eligibility_type,omitempty"`
Links []Links `json:"links,omitempty"`
}
Sale maps to sale object
type SalePaymentMode ¶
type SalePaymentMode string
type ShippingAddress ¶
type ShippingAddress struct {
RecipientName string `json:"recipient_name,omitempty"`
Type AddressType `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"`
}
ShippingAddress maps to shipping_address object
type TokenResp ¶
type TokenResp struct {
Scope string `json:"scope"` // "https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/vault/credit-card/.*",
Token string `json:"access_token"` // "EEwJ6tF9x5WCIZDYzyZGaz6Khbw7raYRIBV_WxVvgmsG",
Type string `json:"token_type"` // "Bearer",
AppID string `json:"app_id"` // "APP-6XR95014BA15863X",
ExpiresIn int `json:"expires_in"` // 28800
ExpiresAt time.Time `json:"expires_at"`
}
TokenResp maps to the API response for the /oauth2/token endpoint
type Transaction ¶
type Transaction struct {
Amount *Amount `json:"amount"`
Description string `json:"description,omitempty"`
ItemList *ItemList `json:"item_list,omitempty"`
RelatedResources []Resource `json:"related_resources,omitempty"`
InvoiceNumber string `json:"invoice_number,omitempty"`
Custom string `json:"custom,omitempty"`
SoftDescriptor string `json:"soft_descriptor,omitempty"`
}
Transaction maps to transaction object
type VaultRequest ¶
type VaultRequest struct {
CreditCard
MerchantID string `json:"merchant_id,omitempty"`
ExternalCardID string `json:"external_card_id,omitempty"`
}
VaultRequest maps to vault_request object
type VaultResponse ¶
type VaultResponse struct {
VaultRequest
CreateTime *time.Time `json: "create_time"`
UpdateTime *time.Time `json: "update_time"`
State string `json: "state"`
ValidUntil string `json: "valid_until"`
Links []Links `json:"links"`
}
VaultResponse maps to vault_response object