def cancel_payment(self, payment_id): """Does a POST request to /v2/payments/{payment_id}/cancel. Cancels (voids) a payment. If you set `autocomplete` to false when creating a payment, you can cancel the payment using this endpoint. For more information, see [Delayed Payments](https://developer.squareup.com/docs/payments-api/take-payment s#delayed-payments). Args: payment_id (string): `payment_id` identifying the payment to be canceled. Returns: CancelPaymentResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/payments/{payment_id}/cancel' _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 'payment_id': payment_id }) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json' } # Prepare and execute request _request = self.config.http_client.post(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def list_merchants(self, cursor=None): """Does a GET request to /v2/merchants. Returns `Merchant` information for a given access token. If you don't know a `Merchant` ID, you can use this endpoint to retrieve the merchant ID for an access token. You can specify your personal access token to get your own merchant information or specify an OAuth token to get the information for the merchant that granted you access. If you know the merchant ID, you can also use the [RetrieveMerchant](#endpoint-merchants-retrievemerchant) endpoint to get the merchant information. Args: cursor (int, optional): The cursor generated by the previous response. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/merchants' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = {'cursor': cursor} _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.get(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def batch_retrieve_orders(self, location_id, body): """Does a POST request to /v2/locations/{location_id}/orders/batch-retrieve. Retrieves a set of [Order](#type-order)s by their IDs. If a given Order ID does not exist, the ID is ignored instead of generating an error. Args: location_id (string): The ID of the orders' associated location. body (BatchRetrieveOrdersRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: BatchRetrieveOrdersResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/locations/{location_id}/orders/batch-retrieve' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'location_id': location_id}) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def update_timecard(self, timecard_id, body): """Does a PUT request to /v1/me/timecards/{timecard_id}. Modifies the details of a timecard with an `API_EDIT` event for the timecard. Updating an active timecard with a `clockout_time` clocks the employee out. Args: timecard_id (string): TThe ID of the timecard to modify. body (V1Timecard): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: V1Timecard: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v1/me/timecards/{timecard_id}' _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 'timecard_id': timecard_id }) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def list_employee_wages(self, employee_id=None, limit=None, cursor=None): """Does a GET request to /v2/labor/employee-wages. Returns a paginated list of `EmployeeWage` instances for a business. Args: employee_id (string, optional): Filter wages returned to only those that are associated with the specified employee. limit (int, optional): Maximum number of Employee Wages to return per page. Can range between 1 and 200. The default is the maximum at 200. cursor (string, optional): Pointer to the next page of Employee Wage results to fetch. Returns: ListEmployeeWagesResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/labor/employee-wages' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = { 'employee_id': employee_id, 'limit': limit, 'cursor': cursor } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.get(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def retrieve_cash_drawer_shift(self, location_id, shift_id): """Does a GET request to /v2/cash-drawers/shifts/{shift_id}. Provides the summary details for a single cash drawer shift. See [ListCashDrawerShiftEvents](#endpoint-CashDrawers-ListCashDrawerShiftEv ents) for a list of cash drawer shift events. Args: location_id (string): The ID of the location to retrieve cash drawer shifts from. shift_id (string): The shift ID. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/cash-drawers/shifts/{shift_id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'shift_id': { 'value': shift_id, 'encode': True }}) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = {'location_id': location_id} _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.get(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def create_invoice(self, body): """Does a POST request to /v2/invoices. Creates a draft [invoice]($m/Invoice) for an order created using the Orders API. A draft invoice remains in your account and no action is taken. You must publish the invoice before Square can process it (send it to the customer's email address or charge the customer’s card on file). Args: body (CreateInvoiceRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/invoices' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def batch_retrieve_inventory_changes(self, body): """Does a POST request to /v2/inventory/batch-retrieve-changes. Returns historical physical counts and adjustments based on the provided filter criteria. Results are paginated and sorted in ascending order according their `occurred_at` timestamp (oldest first). BatchRetrieveInventoryChanges is a catch-all query endpoint for queries that cannot be handled by other, simpler endpoints. Args: body (BatchRetrieveInventoryChangesRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/inventory/batch-retrieve-changes' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def search_loyalty_accounts(self, body): """Does a POST request to /v2/loyalty/accounts/search. Searches for loyalty accounts in a loyalty program. You can search for a loyalty account using the phone number or customer ID associated with the account. To return all loyalty accounts, specify an empty `query` object or omit it entirely. Search results are sorted by `created_at` in ascending order. Args: body (SearchLoyaltyAccountsRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/loyalty/accounts/search' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def update_subscription(self, subscription_id, body): """Does a PUT request to /v2/subscriptions/{subscription_id}. Updates a subscription. You can set, modify, and clear the `subscription` field values. Args: subscription_id (string): The ID for the subscription to update. body (UpdateSubscriptionRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: UpdateSubscriptionResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/subscriptions/{subscription_id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'subscription_id': subscription_id}) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.put( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def create_dispute_evidence_text(self, dispute_id, body): """Does a POST request to /v2/disputes/{dispute_id}/evidence_text. Uploads text to use as evidence for a dispute challenge. Args: dispute_id (string): The ID of the dispute you want to upload evidence for. body (CreateDisputeEvidenceTextRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: CreateDisputeEvidenceTextResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/disputes/{dispute_id}/evidence_text' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'dispute_id': dispute_id}) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def remove_dispute_evidence(self, dispute_id, evidence_id): """Does a DELETE request to /v2/disputes/{dispute_id}/evidence/{evidence_id}. Removes specified evidence from a dispute. Square does not send the bank any evidence that is removed. Also, you cannot remove evidence after submitting it to the bank using [SubmitEvidence](https://developer.squareup.com/docs/reference/square/d isputes-api/submit-evidence). Args: dispute_id (string): The ID of the dispute you want to remove evidence from. evidence_id (string): The ID of the evidence you want to remove. Returns: RemoveDisputeEvidenceResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/disputes/{dispute_id}/evidence/{evidence_id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, { 'dispute_id': dispute_id, 'evidence_id': evidence_id }) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.delete(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def complete_payment(self, payment_id): """Does a POST request to /v2/payments/{payment_id}/complete. Completes (captures) a payment. By default, payments are set to complete immediately after they are created. If you set `autocomplete` to `false` when creating a payment, you can complete (capture) the payment using this endpoint. Args: payment_id (string): The unique ID identifying the payment to be completed. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/payments/{payment_id}/complete' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'payment_id': { 'value': payment_id, 'encode': True }}) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.post(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def update_item_taxes(self, body): """Does a POST request to /v2/catalog/update-item-taxes. Updates the [CatalogTax](#type-catalogtax) objects that apply to the targeted [CatalogItem](#type-catalogitem) without having to perform an upsert on the entire item. Args: body (UpdateItemTaxesRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/catalog/update-item-taxes' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def search_customers(self, body): """Does a POST request to /v2/customers/search. Searches the customer profiles associated with a Square account. Calling SearchCustomers without an explicit query parameter returns all customer profiles ordered alphabetically based on `given_name` and `family_name`. Args: body (SearchCustomersRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: SearchCustomersResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/customers/search' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def search_team_members(self, body): """Does a POST request to /v2/team-members/search. Returns a paginated list of `TeamMember` objects for a business. The list to be returned can be filtered by: - location IDs **and** - `status` Args: body (SearchTeamMembersRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/team-members/search' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def retrieve_wage_setting(self, team_member_id): """Does a GET request to /v2/team-members/{team_member_id}/wage-setting. Retrieve a `WageSetting` object for a team member specified by `TeamMember.id`. Learn about [Troubleshooting the Teams API](https://developer.squareup.com/docs/team/troubleshooting#retrievew agesetting). Args: team_member_id (string): The ID of the team member to retrieve wage setting for Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/team-members/{team_member_id}/wage-setting' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'team_member_id': { 'value': team_member_id, 'encode': True }}) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.get(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def get_bank_account_by_v1_id(self, v1_bank_account_id): """Does a GET request to /v2/bank-accounts/by-v1-id/{v1_bank_account_id}. Returns details of a [BankAccount](#type-bankaccount) identified by V1 bank account ID. For more information, see [Retrieve a bank account by using an ID issued by V1 Bank Accounts API](https://developer.squareup.com/docs/docs/bank-accounts-api#retriev e-a-bank-account-by-using-an-id-issued-by-the-v1-bank-accounts-api). Args: v1_bank_account_id (string): Connect V1 ID of the desired `BankAccount`. For more information, see [Retrieve a bank account by using an ID issued by V1 Bank Accounts API](https://developer.squareup.com/docs/docs/bank-accounts-api #retrieve-a-bank-account-by-using-an-id-issued-by-v1-bank-accou nts-api). Returns: GetBankAccountByV1IdResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/bank-accounts/by-v1-id/{v1_bank_account_id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'v1_bank_account_id': v1_bank_account_id}) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.get(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def accept_dispute(self, dispute_id): """Does a POST request to /v2/disputes/{dispute_id}/accept. Accepts the loss on a dispute. Square returns the disputed amount to the cardholder and updates the dispute state to ACCEPTED. Square debits the disputed amount from the seller’s Square account. If the Square account does not have sufficient funds, Square debits the associated bank account. Args: dispute_id (string): The ID of the dispute you want to accept. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/disputes/{dispute_id}/accept' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'dispute_id': { 'value': dispute_id, 'encode': True }}) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.post(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def void_transaction(self, location_id, transaction_id): """Does a POST request to /v2/locations/{location_id}/transactions/{transaction_id}/void. Cancels a transaction that was created with the [Charge](#endpoint-transactions-charge) endpoint with a `delay_capture` value of `true`. See the [Delay Capture of Funds](https://developer.squareup.com/docs/transactions-api/cookbook/de lay-capture) recipe for more information. Args: location_id (string): TODO: type description here. transaction_id (string): TODO: type description here. Returns: VoidTransactionResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/locations/{location_id}/transactions/{transaction_id}/void' _url_path = APIHelper.append_url_with_template_parameters( _url_path, { 'location_id': location_id, 'transaction_id': transaction_id }) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.post(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def update_customer_group(self, group_id, body): """Does a PUT request to /v2/customers/groups/{group_id}. Updates a customer group as identified by the `group_id` value. Args: group_id (string): The ID of the customer group to update. body (UpdateCustomerGroupRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/customers/groups/{group_id}' _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 'group_id': {'value': group_id, 'encode': True} }) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def batch_change_inventory(self, body): """Does a POST request to /v2/inventory/batch-change. Applies adjustments and counts to the provided item quantities. On success: returns the current calculated counts for all objects referenced in the request. On failure: returns a list of related errors. Args: body (BatchChangeInventoryRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/inventory/batch-change' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def submit_evidence(self, dispute_id): """Does a POST request to /v2/disputes/{dispute_id}/submit-evidence. Submits evidence to the cardholder's bank. Before submitting evidence, Square compiles all available evidence. This includes evidence uploaded using the [CreateDisputeEvidenceFile](https://developer.squareup.com/docs/referen ce/square/disputes-api/create-dispute-evidence-file) and [CreateDisputeEvidenceText](https://developer.squareup.com/docs/referen ce/square/disputes-api/create-dispute-evidence-text) endpoints, and evidence automatically provided by Square, when available. Args: dispute_id (string): The ID of the dispute you want to submit evidence for. Returns: SubmitEvidenceResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/disputes/{dispute_id}/submit-evidence' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'dispute_id': dispute_id}) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.post(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def list_timecard_events(self, timecard_id): """Does a GET request to /v1/me/timecards/{timecard_id}/events. Provides summary information for all events associated with a particular timecard. <aside> Only approved accounts can manage their employees with Square. Unapproved accounts cannot use employee management features with the API. </aside> Args: timecard_id (string): The ID of the timecard to list events for. Returns: list of V1TimecardEvent: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v1/me/timecards/{timecard_id}/events' _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 'timecard_id': timecard_id }) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json' } # Prepare and execute request _request = self.config.http_client.get(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def search_loyalty_rewards(self, body): """Does a POST request to /v2/loyalty/rewards/search. Searches for loyalty rewards in a loyalty account. In the current implementation, the endpoint supports search by the reward `status`. If you know a reward ID, use the [RetrieveLoyaltyReward](#endpoint-Loyalty-RetrieveLoyaltyReward) endpoint. Args: body (SearchLoyaltyRewardsRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/loyalty/rewards/search' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def retrieve_inventory_physical_count(self, physical_count_id): """Does a GET request to /v2/inventory/physical-count/{physical_count_id}. Returns the [InventoryPhysicalCount](#type-inventoryphysicalcount) object with the provided `physical_count_id`. Args: physical_count_id (string): ID of the [InventoryPhysicalCount](#type-inventoryphysicalcount) to retrieve. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/inventory/physical-count/{physical_count_id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, { 'physical_count_id': { 'value': physical_count_id, 'encode': True } }) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = {'accept': 'application/json'} # Prepare and execute request _request = self.config.http_client.get(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def search_loyalty_accounts(self, body): """Does a POST request to /v2/loyalty/accounts/search. Searches for loyalty accounts. In the current implementation, you can search for a loyalty account using the phone number associated with the account. If no phone number is provided, all loyalty accounts are returned. Args: body (SearchLoyaltyAccountsRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: SearchLoyaltyAccountsResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/loyalty/accounts/search' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def create_loyalty_account(self, body): """Does a POST request to /v2/loyalty/accounts. Creates a loyalty account. For more information, see [Create a loyalty account](https://developer.squareup.com/docs/docs/loyalty-api/overview/ #loyalty-overview-create-account). Args: body (CreateLoyaltyAccountRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: CreateLoyaltyAccountResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/loyalty/accounts' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def retrieve_cash_drawer_shift(self, location_id, shift_id): """Does a GET request to /v1/{location_id}/cash-drawer-shifts/{shift_id}. Provides the details for a single cash drawer shift, including all events that occurred during the shift. Args: location_id (string): The ID of the location to list cash drawer shifts for. shift_id (string): The shift's ID. Returns: V1CashDrawerShift: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v1/{location_id}/cash-drawer-shifts/{shift_id}' _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 'location_id': location_id, 'shift_id': shift_id }) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json' } # Prepare and execute request _request = self.config.http_client.get(_query_url, headers=_headers) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result
def create_terminal_checkout(self, body): """Does a POST request to /v2/terminals/checkouts. Creates a Terminal checkout request and sends it to the specified device to take a payment for the requested amount. Args: body (CreateTerminalCheckoutRequest): An object containing the fields to POST for the request. See the corresponding object definition for field details. Returns: ApiResponse: An object with the response value as well as other useful information such as status codes and headers. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ # Prepare query URL _url_path = '/v2/terminals/checkouts' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request _request = self.config.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) OAuth2.apply(self.config, _request) _response = self.execute_request(_request) decoded = APIHelper.json_deserialize(_response.text) if type(decoded) is dict: _errors = decoded.get('errors') else: _errors = None _result = ApiResponse(_response, body=decoded, errors=_errors) return _result