Documentation ¶
Index ¶
- func GetOperation(ctx context.Context) string
- func JSON[R any](ctx context.Context, c *Client, method, path string, data any) (res *R, err error)
- func JSONNop(ctx context.Context, c *Client, method, path string, data any) (err error)
- func NewJSONRequest(ctx context.Context, method, url string, data any) (res *http.Request, err error)
- func RespJSON[R any](r *http.Response) (res *R, err error)
- func WithOperation(ctx context.Context, op string) context.Context
- type Amount
- type CancelSubscriptionReq
- type CaptureOrderReq
- type Client
- func (c *Client) Auth(ctx context.Context) (res *Token, err error)
- func (c *Client) CancelSubscription(ctx context.Context, req *CancelSubscriptionReq) (err error)
- func (c *Client) CaptureOrder(ctx context.Context, req *CaptureOrderReq) (res *Order, err error)
- func (c *Client) CreateOrder(ctx context.Context, req *CreateOrderReq) (res *Order, err error)
- func (c *Client) CreateSubscription(ctx context.Context, req *CreateSubscriptionReq) (res *Subscription, err error)
- func (c *Client) GetSubscription(ctx context.Context, req *GetSubscriptionReq) (res *Subscription, err error)
- func (c *Client) VerifyWebhookSign(ctx context.Context, req *VerifyWSReq) (ok bool, err error)
- type CreateOrderReq
- type CreateSubscriptionReq
- type Error
- type ErrorDetail
- type EventType
- type GetSubscriptionReq
- type Link
- type Order
- type OrderIntent
- type OrderStatus
- type PaymentPreferences
- type PaymentSource
- type PurchaseUnit
- type Sale
- type Subscription
- type SubscriptionPlan
- type SubscriptionStatus
- type Token
- type VerifyWSReq
- type Webhook
- type WebhookVerification
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetOperation ¶
func JSON ¶
func JSON[R any](ctx context.Context, c *Client, method, path string, data any, ) (res *R, err error)
JSON performs the request with the data marshaled to JSON format, unmarshals the response body into a new R, and automatically refreshes the client's access token.
func NewJSONRequest ¶
func NewJSONRequest(ctx context.Context, method, url string, data any, ) (res *http.Request, err error)
NewJSONRequest returns a new http.Request with the given data marshaled to JSON format.
Types ¶
type Amount ¶
type Amount struct { // CurrencyCode is the three-character ISO-4217 currency code that identifies the currency. // // Required. CurrencyCode string `json:"currency_code"` // Required. Value string `json:"value"` }
Amount is the total order amount with an optional breakdown that provides details, such as the total item amount, total tax amount, shipping, handling, insurance, and discounts, if any.
See https://developer.paypal.com/docs/api/orders/v2/#orders_create!path=purchase_units/amount&t=request.
type CancelSubscriptionReq ¶
type CaptureOrderReq ¶
type CaptureOrderReq struct { ID string `json:"id"` PaymentSource *PaymentSource `json:"payment_source"` }
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Auth ¶
Auth requests a new token from PayPal server. See https://developer.paypal.com/api/rest/authentication/.
func (*Client) CancelSubscription ¶
func (c *Client) CancelSubscription(ctx context.Context, req *CancelSubscriptionReq) (err error)
CancelSubscription cancels a subscription.
See https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_cancel
func (*Client) CaptureOrder ¶
CaptureOrder captures payment for an order.
See https://developer.paypal.com/docs/api/orders/v2/#orders_capture.
func (*Client) CreateOrder ¶
CreateOrder creates an order.
See https://developer.paypal.com/docs/api/orders/v2/#orders_create.
func (*Client) CreateSubscription ¶
func (c *Client) CreateSubscription(ctx context.Context, req *CreateSubscriptionReq, ) (res *Subscription, err error)
CreateSubscription creates a subscription.
See https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create
func (*Client) GetSubscription ¶
func (c *Client) GetSubscription(ctx context.Context, req *GetSubscriptionReq, ) (res *Subscription, err error)
GetSubscription get details of a subscription.
See https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_get
func (*Client) VerifyWebhookSign ¶
VerifyWebhookSign verifies a webhook signature.
See https://developer.paypal.com/docs/api/webhooks/v1/#verify-webhook-signature_post
type CreateOrderReq ¶
type CreateOrderReq struct {
*Order
}
type CreateSubscriptionReq ¶
type CreateSubscriptionReq struct {
*Subscription
}
type Error ¶
type Error struct { StatusCode int Name string `json:"name"` Message string `json:"message"` DebugID string `json:"debug_id"` Details []*ErrorDetail `json:"details"` Links []*Link `json:"links"` // For identity errors Err string `json:"error"` ErrDesc string `json:"error_description"` }
Error is the PayPal API error response. See https://developer.paypal.com/api/rest/responses/.
type ErrorDetail ¶
type EventType ¶
type EventType string
EventType is the type of webhook.
See https://developer.paypal.com/api/rest/webhooks/event-names/
const ( PaymentSaleCompleted EventType = "PAYMENT.SALE.COMPLETED" BillingSubscriptionCreated EventType = "BILLING.SUBSCRIPTION.CREATED" BillingSubscriptionActivated EventType = "BILLING.SUBSCRIPTION.ACTIVATED" BillingSubscriptionUpdated EventType = "BILLING.SUBSCRIPTION.UPDATED" BillingSubscriptionExpired EventType = "BILLING.SUBSCRIPTION.EXPIRED" BillingSubscriptionCancelled EventType = "BILLING.SUBSCRIPTION.CANCELLED" BillingSubscriptionSuspended EventType = "BILLING.SUBSCRIPTION.SUSPENDED" BillingSubscriptionPaymentFailed EventType = "BILLING.SUBSCRIPTION.PAYMENT.FAILED" )
TODO(ion) Use code gen
type GetSubscriptionReq ¶
type GetSubscriptionReq struct {
ID string
}
type Link ¶
type Link struct { HRef string `json:"href"` Rel string `json:"rel"` Method string `json:"method"` }
Link is a HATEOAS link. See https://developer.paypal.com/api/rest/responses/#link-hateoaslinks.
type Order ¶
type Order struct { ID string `json:"id,omitempty"` Intent OrderIntent `json:"intent,omitempty"` // Required PurchaseUnits []*PurchaseUnit `json:"purchase_units,omitempty"` // Required Status OrderStatus `json:"status,omitempty"` CreateTime time.Time `json:"create_time,omitempty"` UpdateTime time.Time `json:"update_time,omitempty"` Links []*Link `json:"links,omitempty"` }
Order is the PayPal order.
See https://developer.paypal.com/docs/api/orders/v2/#definition-order.
type OrderIntent ¶
type OrderIntent string
OrderIndent is the intent to either capture payment immediately or authorize a payment for an order after order creation.
See https://developer.paypal.com/docs/api/orders/v2/#orders_create!path=intent&t=request.
const ( OICapture OrderIntent = "CAPTURE" OIAuthorize OrderIntent = "AUTHORIZE" )
type OrderStatus ¶
type OrderStatus string
const ( // OSCreated indicates the order was created with the specified context. OSCreated OrderStatus = "CREATED" // OSSaved indicates the order was saved and persisted. OSSaved OrderStatus = "SAVED" // OSApproved indicates the customer approved the payment through the PayPal wallet // or another form of guest or unbranded payment. // For example, a card, bank account, or so on. OSApproved OrderStatus = "APPROVED" // OSVoided indicates all purchase units in the order are voided. OSVoided OrderStatus = "VOIDED" // OSCompleted indicates the payment was authorized // or the authorized payment was captured for the order. OSCompleted OrderStatus = "COMPLETED" // OSPayerActionRequired indicates the order requires an action from the payer // (e.g. 3DS authentication). OSPayerActionRequired OrderStatus = "PAYER_ACTION_REQUIRED" )
type PaymentPreferences ¶
type PaymentPreferences struct {
SetupFee *Amount `json:"setup_fee,omitempty"`
}
type PaymentSource ¶
type PaymentSource struct { }
PaymentSource is the payment source.
See https://developer.paypal.com/docs/api/orders/v2/#definition-payment_source.
type PurchaseUnit ¶
type PurchaseUnit struct { Amount *Amount `json:"amount"` // Requried // Description is the purchase description. // // The maximum length of the character is dependent on the type of characters used. // The character length is specified assuming a US ASCII character. // Depending on type of character; (e.g. accented character, Japanese characters) // the number of characters that can be specified as input // might not equal the permissible max length. Description string `json:"description"` }
PurchaseUnit represents either a full or partial order that the payer intends to purchase from the payee.
See https://developer.paypal.com/docs/api/orders/v2/#orders_create!path=purchase_units&t=request.
type Sale ¶
type Sale struct { ID string `json:"id,omitempty"` BillingAgreementId string `json:"billing_agreement_id,omitempty"` // Subscription ID Amount struct { Total string `json:"total,omitempty"` Currency string `json:"currency,omitempty"` } `json:"amount,omitempty"` Links []*Link `json:"links,omitempty"` }
type Subscription ¶
type Subscription struct { ID string `json:"id,omitempty"` PlanID string `json:"plan_id,omitempty"` Quantity string `json:"quantity,omitempty"` Status SubscriptionStatus `json:"status,omitempty"` Plan *SubscriptionPlan `json:"plan,omitempty"` }
type SubscriptionPlan ¶
type SubscriptionPlan struct {
PaymentPreferences *PaymentPreferences `json:"payment_preferences,omitempty"`
}
type SubscriptionStatus ¶
type SubscriptionStatus string
const ( SSApprovalPending SubscriptionStatus = "APPROVAL_PENDING" SSApproved SubscriptionStatus = "APPROVED" SSActive SubscriptionStatus = "ACTIVE" SSSuspended SubscriptionStatus = "SUSPENDED" SSCancelled SubscriptionStatus = "CANCELLED" SSExpired SubscriptionStatus = "EXPIRED" )
type Token ¶
type VerifyWSReq ¶
type VerifyWSReq struct { AuthAlgo string `json:"auth_algo,omitempty"` CertURL string `json:"cert_url,omitempty"` TransmissionID string `json:"transmission_id,omitempty"` TransmissionTime time.Time `json:"transmission_time,omitempty"` TransmissionSig string `json:"transmission_sig,omitempty"` // WebhookID is the ID of webhook as configured in your Developer Portal account. WebhookID string `json:"webhook_id,omitempty"` WebhookEvent any `json:"webhook_event,omitempty"` }
type Webhook ¶
type Webhook struct { ID string `json:"id,omitempty"` CreateTime time.Time `json:"create_time,omitempty"` ResourceType string `json:"resource_type,omitempty"` EventType EventType `json:"event_type,omitempty"` Summary string `json:"summary,omitempty"` Resource map[string]any `json:"resource,omitempty"` Links []Link `json:"links,omitempty"` }
type WebhookVerification ¶
type WebhookVerification struct {
VerificationStatus string `json:"verification_status,omitempty"`
}