Skip to content

Commit

Permalink
Merge pull request #8 from muschellij2/master
Browse files Browse the repository at this point in the history
Fixed Checks
  • Loading branch information
MarkEdmondson1234 committed May 24, 2017
2 parents 32fe79a + 8ce0e16 commit 3038d3d
Show file tree
Hide file tree
Showing 44 changed files with 70 additions and 64 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Expand Up @@ -5,3 +5,4 @@ cran-comments\.md
.httr-oauth
.httr-oauth-SUSPENDED
stripeR_form.png
Readme\.md
10 changes: 6 additions & 4 deletions DESCRIPTION
Expand Up @@ -2,7 +2,7 @@ Package: stripeR
Type: Package
Title: Interface for Stripe API for R
Description: Allow users to pay in Shiny apps using Stripe payment portal.
Version: 0.0.9001
Version: 0.0.9002
Authors@R: c(person("Mark", "Edmondson",email = "r@sunholo.com",
role = c("aut", "cre")))
URL: https://github.com/MarkEdmondson1234/stripeR
Expand All @@ -11,11 +11,13 @@ Depends:
R (>= 3.2.0)
Imports:
httr (>= 1.0.0),
jsonlite (>= 0.9.16)
Suggests:
shiny (>= 0.13.0),
jsonlite (>= 0.9.16),
stats,
utils
Suggests:
knitr
License: MIT + file LICENSE
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 5.0.1
RoxygenNote: 6.0.1
23 changes: 23 additions & 0 deletions NAMESPACE
Expand Up @@ -26,3 +26,26 @@ export(stripeR_init)
export(update_charge)
export(update_customer)
export(update_subscription)
importFrom(httr,GET)
importFrom(httr,POST)
importFrom(httr,add_headers)
importFrom(httr,authenticate)
importFrom(httr,content)
importFrom(httr,modify_url)
importFrom(jsonlite,fromJSON)
importFrom(shiny,actionButton)
importFrom(shiny,br)
importFrom(shiny,column)
importFrom(shiny,fluidRow)
importFrom(shiny,h4)
importFrom(shiny,helpText)
importFrom(shiny,numericInput)
importFrom(shiny,observeEvent)
importFrom(shiny,p)
importFrom(shiny,reactiveValues)
importFrom(shiny,renderUI)
importFrom(shiny,strong)
importFrom(shiny,tagList)
importFrom(shiny,textInput)
importFrom(stats,runif)
importFrom(utils,str)
6 changes: 4 additions & 2 deletions R/charge.R
Expand Up @@ -21,10 +21,12 @@
#' a source belonging to the customer.
#'
#' If you do not pass a customer ID,
#' the source you provide must be a token from \link{create_token}
#' the source you provide must be a token from \code{\link{create_card_token}}
#'
#' @family charges
#' @export
#' @importFrom httr POST
#'
charge_card <- function(amount,
currency,
idempotency,
Expand Down Expand Up @@ -162,7 +164,7 @@ capture_charge <- function(chargeId,
#' @param ending_before A cursor used for pagination
#' @param limit between 1 and 100 objects
#' @param source A filter based on the source of the charge
#' @param starting_after A cursor used for pagination
#' @param starting_before A cursor used for pagination
#'
#'
#' @return A charge object
Expand Down
13 changes: 7 additions & 6 deletions R/customer.R
Expand Up @@ -88,12 +88,12 @@ get_customer <- function(customerId){
#' @param description Arbitary string
#' @param email customer's email address
#' @param metadata A named list
#' @param plan ID of the plan to subscribe customer to
#' @param quantity Quantity you'd like to apply to subscription. Needs plan.
#' # @param plan ID of the plan to subscribe customer to
#' # @param quantity Quantity you'd like to apply to subscription. Needs plan.
#' @param shipping Optional dictionary
#' @param source A token from \link{get_token}
#' @param tax_percent A positive decimal. Percentage added as tax.
#' @param trail_end Unix timestamp when trial period ends. Needs plan.
#' # @param tax_percent A positive decimal. Percentage added as tax.
#' # @param trail_end Unix timestamp when trial period ends. Needs plan.
#'
#' @details
#' Setting \code{account_balance} to negative means the customer will have a credit.
Expand Down Expand Up @@ -162,12 +162,13 @@ delete_customer <- function(customerId){
#' @param created filter on created
#' @param ending_before filter for pagination
#' @param limit Between 1 and 100
#' @param starting_after filter for pagination
#' @param starting_before filter for pagination
#'
#' @return List object
#'
#' @family customers
#' @export
#' @importFrom httr GET
list_customers <- function(created=NULL,
ending_before=NULL,
limit=10,
Expand All @@ -183,7 +184,7 @@ list_customers <- function(created=NULL,
url <- httr::modify_url("https://api.stripe.com/v1/customers",
query = params)

req <- do_request(url,"GET", limit=limit)
req <- do_request(url, "GET", limit=limit)

content <- req$data

Expand Down
9 changes: 7 additions & 2 deletions R/requests.R
Expand Up @@ -59,6 +59,7 @@ stripeR_init <- function(live=FALSE){
#' @return the request content or NULL
#'
#' @keywords internal
#' @importFrom httr modify_url add_headers authenticate
do_request <- function(url,
request_type,
idempotency=NULL,
Expand Down Expand Up @@ -150,9 +151,12 @@ do_request <- function(url,
#' @return content if it is there, or NULL
#'
#' @keywords internal
#' @importFrom httr content
#' @importFrom jsonlite fromJSON
checkRequest <- function(req){

content <- httr::content(req, as = "text", type = "application/json",encoding = "UTF-8")
content <- httr::content(req, as = "text", type = "application/json",
encoding = "UTF-8")

if(!is.null(content)){
content <- jsonlite::fromJSON(content, simplifyVector = FALSE, flatten = TRUE)
Expand Down Expand Up @@ -187,6 +191,7 @@ checkRequest <- function(req){
#' @param f A function of a http request
#'
#' @keywords internal
#' @importFrom stats runif
retryRequest <- function(f){
the_request <- try(f)

Expand All @@ -196,7 +201,7 @@ retryRequest <- function(f){
if(the_request[["status_code"]] %in% c(429, 500, 501, 502, 503, 504)){
for(i in 1:5){
warning("Trying again: ", i, " of 5")
Sys.sleep((2 ^ i) + runif(n = 1, min = 0, max = 1))
Sys.sleep((2 ^ i) + stats::runif(n = 1, min = 0, max = 1))
the_request <- try(f)
if(!is.error(the_request)) break
}
Expand Down
7 changes: 6 additions & 1 deletion R/shiny.R
Expand Up @@ -32,12 +32,15 @@ stripeRShinyUI <- function(id){
#' @param formText reactive - Custom text for form
#' @param bottom_left What to see in the bottom left of form
#' @param thanks What to see once the form is successfully submitted
#' @param currency The currency the amount is in
#' @param live Whether to charge against the live Stripe account.
#' @param metadata reactive - A named list of other data to send into stripeR
#'
#' @return A reactive status object
#'
#' @export
#' @importFrom shiny p fluidRow renderUI column h4 strong helpText
#' @importFrom shiny numericInput textInput br actionButton tagList observeEvent
stripeRShiny <- function(input, output, session,
amount,
plan,
Expand Down Expand Up @@ -219,6 +222,7 @@ stripeRShiny <- function(input, output, session,
#'
#' @family shiny
#' @keywords internal
#' @importFrom shiny reactiveValues
stripeShinyInit <- function(){

shiny::reactiveValues(charged=FALSE,
Expand All @@ -241,8 +245,9 @@ stripeShinyInit <- function(){
#'
#' @family shiny
#' @keywords internal
#' @importFrom utils str
updateStatus <- function(attempt, status){
str(attempt)
utils::str(attempt)
if(is.error(attempt)){
warning(error.message(attempt))
status$charge_message <- error.message(attempt)
Expand Down
2 changes: 1 addition & 1 deletion R/subscriptions.R
Expand Up @@ -166,7 +166,7 @@ cancel_subscription <- function(customerId, subscriptionId, at_period_end=FALSE)
#' @param customerId The ID of the customer
#' @param ending_before filter for pagination
#' @param limit Between 1 and 100
#' @param starting_after filter for pagination
#' @param starting_before filter for pagination
#'
#' @return List object
#'
Expand Down
2 changes: 2 additions & 0 deletions Readme.md
@@ -1,5 +1,7 @@
# stripeR

[![Travis-CI Build Status](https://travis-ci.org/MarkEdmondson1234/stripeR.svg?branch=master)](https://travis-ci.org/MarkEdmondson1234/stripeR)

An interface with the [Stripe](https://stripe.com) API for user payments.

[API docs](https://stripe.com/docs/api/curl)
Expand Down
1 change: 0 additions & 1 deletion man/balance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/balance_history.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/balance_transaction.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/cancel_subscription.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/capture_charge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/charge_card.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/checkRequest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/create_bank_token.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/create_card_token.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/create_customer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/create_subscription.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/delete_customer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/do_request.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/error.message.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/get_charge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/get_customer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/get_subscription.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/get_token.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/idempotency.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/is.error.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/list_charges.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/list_customers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/list_subscriptions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/make_meta.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/retryRequest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/stripeRShiny.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/stripeRShinyUI.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/stripeR_auth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3038d3d

Please sign in to comment.