Documentation
¶
Index ¶
- Constants
- type AccessToken
- type Address
- type Amount
- type AmountItem
- type Breakdown
- type CapturedOrder
- type CapturedOrderPayment
- type CapturedOrderPayments
- type CapturedOrderPurchaseUnit
- type Client
- func (c *Client) CaptureOrder(ctx context.Context, orderID string) (*CapturedOrder, error)
- func (c *Client) CreateOrder(ctx context.Context, unit PurchaseUnit, options ...CreateOrderOption) (*CreatedOrder, error)
- func (c *Client) GetAccessToken(ctx context.Context) *AccessToken
- func (c *Client) SwitchToLive()
- type CreateOrderOption
- type CreateOrderRequest
- type CreatedOrder
- type Credentials
- type Link
- type Name
- type OrderIntent
- type Payee
- type Payer
- type Payment
- type PaymentSource
- type PaypalDetail
- type PaypalError
- type PaypalPaymentSource
- type PurchaseUnit
- type PurchaseUnitDetails
- type PurchaseUnitOption
- type SellerProtection
- type SellerReceivableBreakdown
- type Shipping
- type Status
Constants ¶
const ( SandboxHost = "https://api-m.sandbox.paypal.com" Host = "https://api-m.paypal.com" )
const ( // OrderIntentCapture The merchant intends to capture payment immediately after the customer makes a payment. OrderIntentCapture = OrderIntent("CAPTURE") // OrderIntentAuthorize The merchant intends to authorize a payment and place funds on hold after the customer makes a payment. // Authorized payments are best captured within three days of authorization but are available to capture for up to 29 days. // After the three-day honor period, the original authorized payment expires and you must re-authorize the payment. // You must make a separate request to capture payments on demand. // This intent is not supported when you have more than one purchase_unit within your order. OrderIntentAuthorize = OrderIntent("AUTHORIZE") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessToken ¶
type AccessToken struct {
Scope string `json:"scope"`
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
AppID string `json:"app_id"`
ExpiresIn int `json:"expires_in"`
Nonce string `json:"nonce"`
ExpiresAt time.Time `json:"-"`
}
AccessToken represents the access token response from PayPal
{
"scope": "https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/disputes/read-buyer https://uri.paypal.com/services/payments/realtimepayment https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/payments/payment/authcapture openid https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/payments/refund https://api-m.paypal.com/v1/vault/credit-card https://api-m.paypal.com/v1/payments/.* https://uri.paypal.com/payments/payouts https://api-m.paypal.com/v1/vault/credit-card/.* https://uri.paypal.com/services/subscriptions https://uri.paypal.com/services/applications/webhooks",
"access_token": "A21AAFEpH4PsADK7qSS7pSRsgzfENtu-Q1ysgEDVDESseMHBYXVJYE8ovjj68elIDy8nF26AwPhfXTIeWAZHSLIsQkSYz9ifg",
"token_type": "Bearer",
"app_id": "APP-80W284485P519543T",
"expires_in": 31668,
"nonce": "2020-04-03T15:35:36ZaYZlGvEkV4yVSz8g6bAKFoGSEzuy3CQcz3ljhibkOHg"
}
func (*AccessToken) WillExpires ¶
func (t *AccessToken) WillExpires() bool
WillExpires token will be expired in 30 seconds
type Address ¶
type Address struct {
AddressLine1 string `json:"address_line_1,omitzero"`
AddressLine2 string `json:"address_line_2,omitzero"`
AdminArea2 string `json:"admin_area_2,omitzero"`
AdminArea1 string `json:"admin_area_1,omitzero"`
PostalCode string `json:"postal_code,omitzero"`
CountryCode string `json:"country_code,omitzero"`
}
type Amount ¶
type Amount struct {
AmountItem
Breakdown Breakdown `json:"breakdown,omitzero"`
}
Amount is the total amount of a purchase unit
type AmountItem ¶
type AmountItem struct {
CurrencyCode string `json:"currency_code"`
Value string `json:"value"`
Amount float64 `json:"-"`
}
AmountItem is the amount of a purchase unit
type Breakdown ¶
type Breakdown struct {
ItemAmount AmountItem `json:"item_amount"`
Shipping AmountItem `json:"shipping_amount"`
}
Breakdown is the breakdown of the amount
type CapturedOrder ¶
type CapturedOrder struct {
ID string `json:"id"`
Status Status `json:"status"`
Links []Link `json:"links"`
PaymentSource PaymentSource `json:"payment_source,omitzero"`
PurchaseUnits []CapturedOrderPurchaseUnit `json:"purchase_units,omitzero"`
Payer Payer `json:"payer,omitzero"`
}
type CapturedOrderPayment ¶
type CapturedOrderPayment struct {
ID string `json:"id"`
Status Status `json:"status"`
Amount AmountItem `json:"amount"`
InvoiceID string `json:"invoice_id,omitzero"`
FinalCapture bool `json:"final_capture,omitzero"`
SellerProtection SellerProtection `json:"seller_protection,omitzero"`
SellerReceivableBreakdown SellerReceivableBreakdown `json:"seller_receivable_breakdown,omitzero"`
Links []Link `json:"links,omitzero"`
CreateTime string `json:"create_time,omitzero"`
UpdateTime string `json:"update_time,omitzero"`
}
type CapturedOrderPayments ¶
type CapturedOrderPayments struct {
Captures []CapturedOrderPayment `json:"captures"`
}
type CapturedOrderPurchaseUnit ¶
type CapturedOrderPurchaseUnit struct {
ReferenceID string `json:"reference_id,omitzero"`
Shipping Shipping `json:"shipping,omitzero"`
Payments CapturedOrderPayments `json:"payments,omitzero"`
}
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) CaptureOrder ¶
CaptureOrder captures a previously created order by its ID. It sends a request to the PayPal API to capture the order and returns the captured order details or an error.
func (*Client) CreateOrder ¶
func (c *Client) CreateOrder(ctx context.Context, unit PurchaseUnit, options ...CreateOrderOption) (*CreatedOrder, error)
CreateOrder creates a new order with the given purchase unit and options. It sends a request to the PayPal API to create the order and returns the created order details or an error.
func (*Client) GetAccessToken ¶
func (c *Client) GetAccessToken(ctx context.Context) *AccessToken
func (*Client) SwitchToLive ¶
func (c *Client) SwitchToLive()
type CreateOrderOption ¶
type CreateOrderOption func(*CreateOrderRequest)
CreateOrderOption is a function that take a pointer to a CreateOrderRequest and modify it. They are used to configure a CreateOrderRequest when calling the CreateOrder function.
func WithOrderIntent ¶
func WithOrderIntent(intent OrderIntent) CreateOrderOption
WithOrderIntent sets the intent of the order to the given intent.
It is a required field, and it can be either "CAPTURE" or "AUTHORIZE".
func WithPaypalPaymentSources ¶
func WithPaypalPaymentSources(s PaypalPaymentSource) CreateOrderOption
WithPaypalPaymentSources sets the payment source of the CreateOrderRequest to the given PayPalPaymentSource.
It takes a PaypalPaymentSource as an argument, and sets the PaymentSource field in the request to it.
func WithPurchaseUnit ¶
func WithPurchaseUnit(units ...PurchaseUnit) CreateOrderOption
WithPurchaseUnits sets the purchase units for the CreateOrderRequest.
It takes a variadic argument of PurchaseUnit, and appends them to the PurchaseUnits field in the request.
type CreateOrderRequest ¶
type CreateOrderRequest struct {
Intent OrderIntent `json:"intent"`
PurchaseUnits []PurchaseUnit `json:"purchase_units"`
PaymentSource PaymentSource `json:"payment_source,omitzero"`
}
CreateOrderRequest represents the request body of the Create Order API. It contains the intent of the order, the purchase units, and the payment source.
func NewCreateOrderRequest ¶
func NewCreateOrderRequest(unit PurchaseUnit, options ...CreateOrderOption) *CreateOrderRequest
NewCreateOrderRequest create a new CreateOrderRequest with default values
type CreatedOrder ¶
type CreatedOrder struct {
ID string `json:"id"` // The unique identifier for the order.
Status Status `json:"status"` // The current status of the order.
Links []Link `json:"links"` // Related links for the order actions.
}
CreatedOrder represents a PayPal order that has been created. It contains the ID, status, and links related to the order.
type Credentials ¶
type OrderIntent ¶
type OrderIntent string
OrderIntent represents the intent of the order. It can be either "CAPTURE" or "AUTHORIZE". If it is "CAPTURE", the order is automatically captured and the payment is taken. If it is "AUTHORIZE", the order is only authorized and the payment is not taken until the order is captured.
type Payment ¶
type Payment struct {
ID string `json:"id"`
Status string `json:"status"`
Amount AmountItem `json:"amount"`
InvoiceID string `json:"invoice_id"`
Payee Payee `json:"payee"`
SellerProtection SellerProtection `json:"seller_protection"`
ExpirationTime string `json:"expiration_time"` // "expiration_time": "2017-10-10T23:23:45Z",
CreateTime string `json:"create_time"` // "create_time": "2017-09-11T23:23:45Z",
UpdateTime string `json:"update_time"` // "update_time": "2017-09-11T23:23:45Z",
Links []Link `json:"links"`
}
{
"id": "0VF52814937998046",
"status": "CREATED",
"amount": {
"value": "10.99",
"currency_code": "USD"
},
"invoice_id": "INVOICE-123",
"seller_protection": {
"status": "ELIGIBLE",
"dispute_categories": [
"ITEM_NOT_RECEIVED",
"UNAUTHORIZED_TRANSACTION"
]
},
"payee": {
"email_address": "merchant@example.com",
"merchant_id": "7KNGBPH2U58GQ"
},
"expiration_time": "2017-10-10T23:23:45Z",
"create_time": "2017-09-11T23:23:45Z",
"update_time": "2017-09-11T23:23:45Z",
"links": [
{
"rel": "self",
"method": "GET",
"href": "https://api-m.paypal.com/v2/payments/authorizations/0VF52814937998046"
},
{
"rel": "capture",
"method": "POST",
"href": "https://api-m.paypal.com/v2/payments/authorizations/0VF52814937998046/capture"
},
{
"rel": "void",
"method": "POST",
"href": "https://api-m.paypal.com/v2/payments/authorizations/0VF52814937998046/void"
},
{
"rel": "reauthorize",
"method": "POST",
"href": "https://api-m.paypal.com/v2/payments/authorizations/0VF52814937998046/reauthorize"
}
]
}
type PaymentSource ¶
type PaymentSource struct {
Paypal PaypalPaymentSource `json:"paypal,omitzero"`
}
type PaypalDetail ¶
type PaypalError ¶
type PaypalError struct {
Name string `json:"name"`
Message string `json:"message"`
StatusCode int `json:"-"`
DebugID string `json:"debug_id"`
Details []PaypalDetail `json:"details"`
Links []Link `json:"links"`
}
func (*PaypalError) Error ¶
func (e *PaypalError) Error() string
type PaypalPaymentSource ¶
type PaypalPaymentSource struct {
EmailAddress string `json:"email_address,omitzero"`
AccountID string `json:"account_id,omitzero"`
AccountStatus string `json:"account_status,omitzero"`
Name Name `json:"name,omitzero"`
Address Address `json:"address,omitzero"`
AppSwitchEligibility bool `json:"app_switch_eligibility,omitzero"`
}
type PurchaseUnit ¶
type PurchaseUnit struct {
//description The purchase description.
Description string `json:"description,omitzero"`
// CustomerID The API caller-provided external ID. Used to reconcile client transactions with PayPal transactions.
// Appears in transaction and settlement reports but is not visible to the payer.
CustomerID string `json:"customer_id,omitzero"`
// InvoiceID The API caller-provided external invoice number for this order.
// Appears in both the payer's transaction history and the emails that the payer receives.
InvoiceID string `json:"invoice_id,omitzero"`
Amount Amount `json:"amount"`
PurchaseUnitDetails
}
PurchaseUnit is a purchase unit https://developer.paypal.com/docs/api/orders/v2/#orders_create!ct=application/json&path=purchase_units&t=request
func CreatePurchaseUnit ¶
func CreatePurchaseUnit(desc string, currencyCode string, amount float64, options ...PurchaseUnitOption) PurchaseUnit
type PurchaseUnitDetails ¶
type PurchaseUnitDetails struct {
// ReferenceID The API caller-provided external ID for the purchase unit.
// Required for multiple purchase units when you must update the order through PATCH. If you omit
// this value and the order contains only one purchase unit, PayPal sets this value to `default`.
ReferenceID string `json:"reference_id,omitzero"`
// SoftDescriptor The soft descriptor is the dynamic text used to construct the statement descriptor
// that appears on a payer's card statement.
SoftDescriptor string `json:"soft_descriptor,omitzero"`
}
type PurchaseUnitOption ¶
type PurchaseUnitOption func(*PurchaseUnit)
func WithPurchaseUnitCustomerID ¶
func WithPurchaseUnitCustomerID(customerID string) PurchaseUnitOption
func WithPurchaseUnitInvoiceID ¶
func WithPurchaseUnitInvoiceID(invoiceID string) PurchaseUnitOption
func WithPurchaseUnitShippingFee ¶
func WithPurchaseUnitShippingFee(fee float64) PurchaseUnitOption
type SellerProtection ¶
type SellerReceivableBreakdown ¶
type SellerReceivableBreakdown struct {
GrossAmount AmountItem `json:"gross_amount,omitzero"`
NetAmount AmountItem `json:"net_amount,omitzero"`
PaypalFee AmountItem `json:"paypal_fee,omitzero"`
}