api

package
v0.0.0-...-8b0bed9 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ContextOAuth2 takes a oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

Types

type APIClient

type APIClient struct {
	CustomersApi *CustomersApiService

	OrdersApi *OrdersApiService

	PaymentsApi *PaymentsApiService

	RefundsApi *RefundsApiService

	TransactionsApi *TransactionsApiService
	// contains filtered or unexported fields
}

APIClient manages communication with the Square Connect API API v2.0 In most cases there should be only one, shared, APIClient.

func NewAPIClient

func NewAPIClient(cfg *Configuration) *APIClient

NewAPIClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) ChangeBasePath

func (c *APIClient) ChangeBasePath(path string)

Change base path to allow switching to mocks

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type Configuration

type Configuration struct {
	BasePath      string            `json:"basePath,omitempty"`
	Host          string            `json:"host,omitempty"`
	Scheme        string            `json:"scheme,omitempty"`
	DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
	UserAgent     string            `json:"userAgent,omitempty"`
	HTTPClient    *http.Client
}

func NewConfiguration

func NewConfiguration() *Configuration

func NewSandboxConfiguration

func NewSandboxConfiguration() *Configuration

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

type CustomersApiDeleteCustomerOpts

type CustomersApiDeleteCustomerOpts struct {
	Version optional.Int64
}

type CustomersApiListCustomersOpts

type CustomersApiListCustomersOpts struct {
	Cursor    optional.String
	Limit     optional.Int32
	SortField optional.String
	SortOrder optional.String
	Count     optional.Bool
}

type CustomersApiService

type CustomersApiService service

func (*CustomersApiService) AddGroupToCustomer

func (a *CustomersApiService) AddGroupToCustomer(ctx context.Context, customerId string, groupId string) (models.AddGroupToCustomerResponse, *http.Response, error)

CustomersApiService AddGroupToCustomer Adds a group membership to a customer. The customer is identified by the `customer_id` value and the customer group is identified by the `group_id` value.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param customerId The ID of the customer to add to a group.
  • @param groupId The ID of the customer group to add the customer to.

@return AddGroupToCustomerResponse

func (*CustomersApiService) CreateCustomer

CustomersApiService CreateCustomer Creates a new customer for a business. You must provide at least one of the following values in your request to this endpoint: - `given_name` - `family_name` - `company_name` - `email_address` - `phone_number`

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return CreateCustomerResponse

func (*CustomersApiService) CreateCustomerCard

CustomersApiService CreateCustomerCard Adds a card on file to an existing customer. As with charges, calls to `CreateCustomerCard` are idempotent. Multiple calls with the same card nonce return the same card record that was created with the provided nonce during the _first_ call.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param customerId The Square ID of the customer profile the card is linked to.
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return CreateCustomerCardResponse

func (*CustomersApiService) DeleteCustomer

func (a *CustomersApiService) DeleteCustomer(ctx context.Context, customerId string, localVarOptionals *CustomersApiDeleteCustomerOpts) (models.DeleteCustomerResponse, *http.Response, error)

func (*CustomersApiService) DeleteCustomerCard

func (a *CustomersApiService) DeleteCustomerCard(ctx context.Context, customerId string, cardId string) (models.DeleteCustomerCardResponse, *http.Response, error)

CustomersApiService DeleteCustomerCard Removes a card on file from a customer.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param customerId The ID of the customer that the card on file belongs to.
  • @param cardId The ID of the card on file to delete.

@return DeleteCustomerCardResponse

func (*CustomersApiService) ListCustomers

func (*CustomersApiService) RemoveGroupFromCustomer

func (a *CustomersApiService) RemoveGroupFromCustomer(ctx context.Context, customerId string, groupId string) (models.RemoveGroupFromCustomerResponse, *http.Response, error)

CustomersApiService RemoveGroupFromCustomer Removes a group membership from a customer. The customer is identified by the `customer_id` value and the customer group is identified by the `group_id` value.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param customerId The ID of the customer to remove from the group.
  • @param groupId The ID of the customer group to remove the customer from.

@return RemoveGroupFromCustomerResponse

func (*CustomersApiService) RetrieveCustomer

func (a *CustomersApiService) RetrieveCustomer(ctx context.Context, customerId string) (models.RetrieveCustomerResponse, *http.Response, error)

CustomersApiService RetrieveCustomer Returns details for a single customer.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param customerId The ID of the customer to retrieve.

@return RetrieveCustomerResponse

func (*CustomersApiService) SearchCustomers

CustomersApiService SearchCustomers Searches the customer profiles associated with a Square account using one or more supported query filters. Calling `SearchCustomers` without any explicit query filter returns all customer profiles ordered alphabetically based on `given_name` and `family_name`. Under normal operating conditions, newly created or updated customer profiles become available for the search operation in well under 30 seconds. Occasionally, propagation of the new or updated profiles can take closer to one minute or longer, especially during network incidents and outages.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return SearchCustomersResponse

func (*CustomersApiService) UpdateCustomer

CustomersApiService UpdateCustomer Updates a customer profile. This endpoint supports sparse updates, so only new or changed fields are required in the request. To add or update a field, specify the new value. To remove a field, specify `null` and include the `X-Clear-Null` header set to `true` (recommended) or specify an empty string (string fields only). As a best practice, include the `version` field in the request to enable [optimistic concurrency](https://developer.squareup.com/docs/build-basics/common-api-patterns/optimistic-concurrency) control. If included, the value must be set to the current version of the customer profile. To update a customer profile that was created by merging existing profiles, you must use the ID of the newly created profile. You cannot use this endpoint to change cards on file. To make changes, use the [Cards API](https://developer.squareup.com/reference/square_2023-12-13/cards-api) or [Gift Cards API](https://developer.squareup.com/reference/square_2023-12-13/gift-cards-api).

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param customerId The ID of the customer to update.
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return UpdateCustomerResponse

type GenericSwaggerError

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

GenericSwaggerError Provides access to the body, error and model on returned errors.

func (GenericSwaggerError) Body

func (e GenericSwaggerError) Body() []byte

Body returns the raw bytes of the response

func (GenericSwaggerError) Error

func (e GenericSwaggerError) Error() string

Error returns non-empty string if there was an error.

func (GenericSwaggerError) Model

func (e GenericSwaggerError) Model() interface{}

Model returns the unpacked model of the error

type OrdersApiService

type OrdersApiService service

func (*OrdersApiService) BatchRetrieveOrders

OrdersApiService BatchRetrieveOrders Retrieves a set of [orders](https://developer.squareup.com/reference/square_2023-12-13/objects/Order) by their IDs. If a given order ID does not exist, the ID is ignored instead of generating an error.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return BatchRetrieveOrdersResponse

func (*OrdersApiService) CalculateOrder

OrdersApiService CalculateOrder Enables applications to preview order pricing without creating an order.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return CalculateOrderResponse

func (*OrdersApiService) CloneOrder

OrdersApiService CloneOrder Creates a new order, in the `DRAFT` state, by duplicating an existing order. The newly created order has only the core fields (such as line items, taxes, and discounts) copied from the original order.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return CloneOrderResponse

func (*OrdersApiService) CreateOrder

OrdersApiService CreateOrder Creates a new [order](https://developer.squareup.com/reference/square_2023-12-13/objects/Order) that can include information about products for purchase and settings to apply to the purchase. To pay for a created order, see [Pay for Orders](https://developer.squareup.com/docs/orders-api/pay-for-orders). You can modify open orders using the [UpdateOrder](https://developer.squareup.com/reference/square_2023-12-13/orders-api/update-order) endpoint.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return CreateOrderResponse

func (*OrdersApiService) PayOrder

OrdersApiService PayOrder Pay for an [order](https://developer.squareup.com/reference/square_2023-12-13/objects/Order) using one or more approved [payments](https://developer.squareup.com/reference/square_2023-12-13/objects/Payment) or settle an order with a total of `0`. The total of the `payment_ids` listed in the request must be equal to the order total. Orders with a total amount of `0` can be marked as paid by specifying an empty array of `payment_ids` in the request. To be used with `PayOrder`, a payment must: - Reference the order by specifying the `order_id` when [creating the payment](https://developer.squareup.com/reference/square_2023-12-13/payments-api/create-payment). Any approved payments that reference the same `order_id` not specified in the `payment_ids` is canceled. - Be approved with [delayed capture](https://developer.squareup.com/docs/payments-api/take-payments/card-payments/delayed-capture). Using a delayed capture payment with `PayOrder` completes the approved payment.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param orderId The ID of the order being paid.
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return PayOrderResponse

func (*OrdersApiService) RetrieveOrder

OrdersApiService RetrieveOrder Retrieves an [Order](https://developer.squareup.com/reference/square_2023-12-13/objects/Order) by ID.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param orderId The ID of the order to retrieve.

@return RetrieveOrderResponse

func (*OrdersApiService) SearchOrders

OrdersApiService SearchOrders Search all orders for one or more locations. Orders include all sales, returns, and exchanges regardless of how or when they entered the Square ecosystem (such as Point of Sale, Invoices, and Connect APIs). `SearchOrders` requests need to specify which locations to search and define a [SearchOrdersQuery](https://developer.squareup.com/reference/square_2023-12-13/objects/SearchOrdersQuery) object that controls how to sort or filter the results. Your `SearchOrdersQuery` can: Set filter criteria. Set the sort order. Determine whether to return results as complete `Order` objects or as [OrderEntry](https://developer.squareup.com/reference/square_2023-12-13/objects/OrderEntry) objects. Note that details for orders processed with Square Point of Sale while in offline mode might not be transmitted to Square for up to 72 hours. Offline orders have a `created_at` value that reflects the time the order was created, not the time it was subsequently transmitted to Square.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return SearchOrdersResponse

func (*OrdersApiService) UpdateOrder

OrdersApiService UpdateOrder Updates an open [order](https://developer.squareup.com/reference/square_2023-12-13/objects/Order) by adding, replacing, or deleting fields. Orders with a `COMPLETED` or `CANCELED` state cannot be updated. An `UpdateOrder` request requires the following: - The `order_id` in the endpoint path, identifying the order to update. - The latest `version` of the order to update. - The [sparse order](https://developer.squareup.com/docs/orders-api/manage-orders/update-orders#sparse-order-objects) containing only the fields to update and the version to which the update is being applied. - If deleting fields, the [dot notation paths](https://developer.squareup.com/docs/orders-api/manage-orders/update-orders#identifying-fields-to-delete) identifying the fields to clear. To pay for an order, see [Pay for Orders](https://developer.squareup.com/docs/orders-api/pay-for-orders).

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param orderId The ID of the order to update.
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return UpdateOrderResponse

type PaymentsApiListPaymentsOpts

type PaymentsApiListPaymentsOpts struct {
	BeginTime  optional.String
	EndTime    optional.String
	SortOrder  optional.String
	Cursor     optional.String
	LocationId optional.String
	Total      optional.Int64
	Last4      optional.String
	CardBrand  optional.String
	Limit      optional.Int32
}

type PaymentsApiService

type PaymentsApiService service

func (*PaymentsApiService) CancelPayment

func (a *PaymentsApiService) CancelPayment(ctx context.Context, paymentId string) (models.CancelPaymentResponse, *http.Response, error)

PaymentsApiService CancelPayment Cancels (voids) a payment. You can use this endpoint to cancel a payment with the APPROVED `status`.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param paymentId The ID of the payment to cancel.

@return CancelPaymentResponse

func (*PaymentsApiService) CancelPaymentByIdempotencyKey

PaymentsApiService CancelPaymentByIdempotencyKey Cancels (voids) a payment identified by the idempotency key that is specified in the request. Use this method when the status of a `CreatePayment` request is unknown (for example, after you send a `CreatePayment` request, a network error occurs and you do not get a response). In this case, you can direct Square to cancel the payment using this endpoint. In the request, you provide the same idempotency key that you provided in your `CreatePayment` request that you want to cancel. After canceling the payment, you can submit your `CreatePayment` request again. Note that if no payment with the specified idempotency key is found, no action is taken and the endpoint returns successfully.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return CancelPaymentByIdempotencyKeyResponse

func (*PaymentsApiService) CompletePayment

PaymentsApiService CompletePayment Completes (captures) a payment. By default, payments are set to complete immediately after they are created. You can use this endpoint to complete a payment with the APPROVED `status`.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param paymentId The unique ID identifying the payment to be completed.
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return CompletePaymentResponse

func (*PaymentsApiService) CreatePayment

PaymentsApiService CreatePayment Creates a payment using the provided source. You can use this endpoint to charge a card (credit/debit card or Square gift card) or record a payment that the seller received outside of Square (cash payment from a buyer or a payment that an external entity processed on behalf of the seller). The endpoint creates a `Payment` object and returns it in the response.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return CreatePaymentResponse

func (*PaymentsApiService) GetPayment

PaymentsApiService GetPayment Retrieves details for a specific payment.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param paymentId A unique ID for the desired payment.

@return GetPaymentResponse

func (*PaymentsApiService) ListPayments

func (*PaymentsApiService) UpdatePayment

PaymentsApiService UpdatePayment Updates a payment with the APPROVED status. You can update the `amount_money` and `tip_money` using this endpoint.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param paymentId The ID of the payment to update.
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return UpdatePaymentResponse

type RefundsApiListPaymentRefundsOpts

type RefundsApiListPaymentRefundsOpts struct {
	BeginTime  optional.String
	EndTime    optional.String
	SortOrder  optional.String
	Cursor     optional.String
	LocationId optional.String
	Status     optional.String
	SourceType optional.String
	Limit      optional.Int32
}

type RefundsApiService

type RefundsApiService service

func (*RefundsApiService) GetPaymentRefund

func (a *RefundsApiService) GetPaymentRefund(ctx context.Context, refundId string) (models.GetPaymentRefundResponse, *http.Response, error)

RefundsApiService GetPaymentRefund Retrieves a specific refund using the `refund_id`.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param refundId The unique ID for the desired `PaymentRefund`.

@return GetPaymentRefundResponse

func (*RefundsApiService) ListPaymentRefunds

func (*RefundsApiService) RefundPayment

RefundsApiService RefundPayment Refunds a payment. You can refund the entire payment amount or a portion of it. You can use this endpoint to refund a card payment or record a refund of a cash or external payment. For more information, see [Refund Payment](https://developer.squareup.com/docs/payments-api/refund-payments).

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param body An object containing the fields to POST for the request. See the corresponding object definition for field details.

@return RefundPaymentResponse

type TransactionsApiListTransactionsOpts

type TransactionsApiListTransactionsOpts struct {
	BeginTime optional.String
	EndTime   optional.String
	SortOrder optional.String
	Cursor    optional.String
}

type TransactionsApiService

type TransactionsApiService service

func (*TransactionsApiService) CaptureTransaction

func (a *TransactionsApiService) CaptureTransaction(ctx context.Context, locationId string, transactionId string) (models.CaptureTransactionResponse, *http.Response, error)

TransactionsApiService CaptureTransaction Captures a transaction that was created with the [Charge](https://developer.squareup.com/reference/square_2023-12-13/transactions-api/charge) endpoint with a `delay_capture` value of `true`. See [Delayed capture transactions](https://developer.squareup.com/docs/payments/transactions/overview#delayed-capture) for more information.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param locationId
  • @param transactionId

@return CaptureTransactionResponse

func (*TransactionsApiService) ListTransactions

func (*TransactionsApiService) RetrieveTransaction

func (a *TransactionsApiService) RetrieveTransaction(ctx context.Context, locationId string, transactionId string) (models.RetrieveTransactionResponse, *http.Response, error)

TransactionsApiService RetrieveTransaction Retrieves details for a single transaction.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param locationId The ID of the transaction's associated location.
  • @param transactionId The ID of the transaction to retrieve.

@return RetrieveTransactionResponse

func (*TransactionsApiService) VoidTransaction

func (a *TransactionsApiService) VoidTransaction(ctx context.Context, locationId string, transactionId string) (models.VoidTransactionResponse, *http.Response, error)

TransactionsApiService VoidTransaction Cancels a transaction that was created with the [Charge](https://developer.squareup.com/reference/square_2023-12-13/transactions-api/charge) endpoint with a `delay_capture` value of `true`. See [Delayed capture transactions](https://developer.squareup.com/docs/payments/transactions/overview#delayed-capture) for more information.

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param locationId
  • @param transactionId

@return VoidTransactionResponse

Jump to

Keyboard shortcuts

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