https://github.com/stevenmmortimer/squareupr
This R package connects the Square APIs from R
https://github.com/stevenmmortimer/squareupr
api api-wrapper r square squareup
Last synced: about 2 months ago
JSON representation
This R package connects the Square APIs from R
- Host: GitHub
- URL: https://github.com/stevenmmortimer/squareupr
- Owner: StevenMMortimer
- License: other
- Created: 2018-05-12T01:45:03.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2020-07-23T16:48:55.000Z (almost 5 years ago)
- Last Synced: 2025-01-29T18:22:16.477Z (4 months ago)
- Topics: api, api-wrapper, r, square, squareup
- Language: R
- Homepage: https://stevenmmortimer.github.io/squareupr/
- Size: 381 KB
- Stars: 2
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
README
---
output:
github_document:
html_preview: false
---```{r, echo = FALSE, message = FALSE}
knitr::opts_chunk$set(
fig.align = 'center',
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-")
```# squareupr
[](https://travis-ci.org/StevenMMortimer/squareupr)
[](https://ci.appveyor.com/project/StevenMMortimer/squareupr)
[](http://cran.r-project.org/package=squareupr)
[](https://codecov.io/gh/StevenMMortimer/squareupr?branch=master)**squareupr** is an R package that connects to the Square APIs (Connect v1 & v2).
* OAuth 2.0 (Single sign-on) and Personal Access Token Authentication methods (`sq_auth()`)
* v2 Locations Endpoint (`sq_list_locations()`, `sq_get_location()`)
* v2 Transactions Endpoint (`sq_list_transactions()`, `sq_get_transaction()`)
* v2 Customers Endpoint - CRUD (Create, Retrieve, Update, Delete) methods for customers with:
* `sq_list_customers()`, `sq_search_customers()`, `sq_get_customer()`, `sq_create_customer()`, `sq_update_customer()`, `sq_delete_customer()`
* v1 Payments Endpoint (`sq_list_payments()`, `sq_get_payment()`)
* v1 Items Endpoint - CRUD (Create, Retrieve, Update, Delete) methods for items with:
* `sq_list_items()`, `sq_get_item()`, `sq_create_item()`, `sq_update_item()`, `sq_delete_item()`
* List v1 records (`sq_list_fees()`, `sq_list_categories()`, `sq_list_modifiers()`,
`sq_list_discounts()`)## Table of Contents
* [Installation](#installation)
* [Usage](#usage)
* [Authenticate](#authenticate)
* [Transactions](#transactions)
* [Customers](#customers)
* [Credits](#credits)
* [More Information](#more-information)## Installation
```{r, eval = FALSE}
# This package is not yet available on CRAN so you must install from GitHub
# install.packages("devtools")
devtools::install_github("StevenMMortimer/squareupr")
```If you encounter a clear bug, please file a minimal reproducible example on
[GitHub](https://github.com/StevenMMortimer/squareupr/issues).## Usage
### Authenticate
First, load the **squareupr** package and authenticate. There are two ways to authenticate:1. Personal Access Token
2. OAuth 2.0```{r auth, include = FALSE}
library(dplyr)
library(squareupr)
settings <- readRDS(here::here("tests", "testthat", "squareupr_test_settings.rds"))
suppressMessages(sq_auth(personal_access_token = settings$personal_access_token,
verbose = FALSE))
``````{r, eval=FALSE}
library(dplyr)
library(squareupr)# Using Personal Access Token (PAT)
sq_auth(personal_access_token = "sq-Th1s1sMyPers0nalAcessT0ken")# Using OAuth 2.0 authentication
sq_auth()
```NOTE: Before using OAuth 2.0 authentication it is necessary that you set up your
own Connected App in the Square dashboard. An App ID and App Secret will be
provided, then you will be able to plug into your script like so:```{r other-params, eval=FALSE}
options(squareupr.app_id = "sq0-99-thisisatest99connected33app22id")
options(squareupr.app_secret = "sq0-Th1s1sMyAppS3cr3t")
sq_auth()
```OAuth 2.0 credentials will be cached locally in a file entitled `".httr-oauth-squareupr"`
in the current working directory so that a new token is not needed each session.### Transactions
Transactions are organized by location. With the v2 Locations endpoint you can pull
information regarding all locations first to obtain the location IDs. Then with the
`sq_list_transactions()` function you can provide the location and timeframe to search.
The function defaults to pulling transactions from the previous day using `Sys.Date() - 1`.
Once you obtain the transactions the `tenders` field lists all methods of payment
used to pay in the transaction.```{r transactions-by-location}
# list all locations
our_locations <- sq_list_locations()
our_transactions <- sq_list_transactions(location = our_locations$id[2],
begin_time = as.Date('2019-07-09'),
end_time = as.Date('2019-07-10'))
our_transactions
```### Customers
Once you pull data about transactions you can take the customer_id from the transaction
`tenders` field and match that up with customer details. In Square customers can
be placed into groups that allow for the analysis of transactions at a group-level.```{r customers}
# list customers created in the last 30 days
created_start <- format(Sys.Date() - 30, '%Y-%m-%dT00:00:00-00:00')
created_end <- format(Sys.Date(), '%Y-%m-%dT00:00:00-00:00')
our_customers <- sq_search_customers(query = list(filter=
list(created_at=
list(start_at=created_start,
end_at=created_end))))
our_customers$given_name <- "{HIDDEN}"
our_customers$family_name <- "{HIDDEN}"
our_customers %>% select(id, created_at, updated_at,
given_name, family_name, preferences, groups)# show the groups that each customer belongs to
# filter to the groups designated automatically by Square
sq_extract_cust_groups(our_customers) %>%
filter(grepl("^CQ689YH4KCJMY", groups.id))
```## Credits
This application uses other open source software components. The authentication
components are mostly verbatim copies of the routines established in the **googlesheets**
package (https://github.com/jennybc/googlesheets). We acknowledge and are grateful
to these developers for their contributions to open source.## More Information
This package makes requests best formatted to match what the APIs require as input.
This articulation is not perfect and continued progress will be made to add and improve
functionality. For details on formatting, attributes, and methods please refer to
[Square's documentation](https://docs.connect.squareup.com/api/connect/v2)
as they are explained better there.More information is also available on the `pkgdown` site at
https://StevenMMortimer.github.io/squareupr.[Top](#squareupr)
---
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md).
By participating in this project you agree to abide by its terms.