Sha256: 0d496d30456f8cf09702a433e94b2a88abe4d99c4ce11968d6233636fd069e50

Contents?: true

Size: 1.97 KB

Versions: 41

Compression:

Stored size: 1.97 KB

Contents

module Platformx
  # Stripe helpers module
  # @author Tim Mushen
	module StripeHelpers
	require "active_support/all"

# Provide all stripe invoices
# @param customer_id [String] stripe customer id
# @return [Array<Stripe::Invoice>] collection of stripe invoices
def x_stripe_invoices(customer_id: "")
	invoices = Stripe::Invoice.all
	return invoices
end

# Get specific stripe invoice
# @param invoice [String] stripe invoice id
# @return [Stripe::Invoice] the stripe invoice identified by id
def x_stripe_invoice(invoice: "")
	invoice = Stripe::Invoice.retrieve(invoice)
	return invoice
end

# Get stripe customer
# @param customer_id [String] stripe customer id
# @return [Stripe::Customer] stripe customer identified by id
def x_stripe_customer(customer_id: "")
	customer = Stripe::Customer.retrieve(customer_id)
	return customer
end

# Retrieve stripe card for a customer
# @param customer_id [String] stripe customer id
# @param card_id [String] stripe card id
# @return [Stripe::Card] stripe card
def x_stripe_customer_card(customer_id: "", card_id: "")
	customer = Stripe::Customer.retrieve(customer_id)
	card = customer.sources.retrieve(card_id)
	return card
end

# Delete a stripe card for a customer
# @param customer_id [String] stripe customer id
# @param card_id [String] stripe card id
# @return [Stripe::Card] stripe card which was deleted
def x_stripe_customer_card_delete(customer_id: "", card_id: "")
	customer = Stripe::Customer.retrieve(customer_id)
	card = customer.sources.retrieve(card_id).delete()
	return card
end

# Stripe total including tax
# @param amount [Numeric] amount
# @param tax_percentage [Numeric] tax percentage
# @return [String] stripe total including tax if included
def x_stripe_total(amount: "", tax_percentage: "")
		num = 0

		if amount.is_a?(Numeric)
			num = (amount.to_f/100) 
		end

		if tax_percentage != "" && tax_percentage.is_a?(Numeric)
		 num = num * (1+(tax_percentage.to_f/100))
		end
		
		#num = '%.02f' % num

		return  num.to_s(:currency)

end

  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
platformx-0.0.9.7.2 lib/platformx/stripe.rb
platformx-0.0.9.7.1 lib/platformx/stripe.rb
platformx-0.0.9.6.6.7 lib/platformx/stripe.rb
platformx-0.0.9.6.6.6 lib/platformx/stripe.rb
platformx-0.0.9.6.6.5 lib/platformx/stripe.rb
platformx-0.0.9.6.6.4 lib/platformx/stripe.rb
platformx-0.0.9.6.6.3 lib/platformx/stripe.rb
platformx-0.0.9.6.6.2 lib/platformx/stripe.rb
platformx-0.0.9.6.6.1 lib/platformx/stripe.rb
platformx-0.0.9.6.4 lib/platformx/stripe.rb
platformx-0.0.9.6.3 lib/platformx/stripe.rb
platformx-0.0.9.6.2 lib/platformx/stripe.rb
platformx-0.0.9.6.1 lib/platformx/stripe.rb
platformx-0.0.9.6 lib/platformx/stripe.rb
platformx-0.0.9.5 lib/platformx/stripe.rb
platformx-0.0.9.4 lib/platformx/stripe.rb
platformx-0.0.9.3 lib/platformx/stripe.rb
platformx-0.0.9.2 lib/platformx/stripe.rb
platformx-0.0.9 lib/platformx/stripe.rb
platformx-0.0.8.9.9.9 lib/platformx/stripe.rb