Module: Platformx::StripeHelpers

Defined in:
lib/platformx/stripe.rb

Overview

Stripe helpers module

Author:

  • Tim Mushen

Instance Method Summary collapse

Instance Method Details

#x_stripe_customer(customer_id: "") ⇒ Stripe::Customer

Get stripe customer

Parameters:

  • customer_id (String) (defaults to: "")

    stripe customer id

Returns:

  • (Stripe::Customer)

    stripe customer identified by id



26
27
28
29
# File 'lib/platformx/stripe.rb', line 26

def x_stripe_customer(customer_id: "")
	customer = Stripe::Customer.retrieve(customer_id)
	return customer
end

#x_stripe_customer_card(customer_id: "", card_id: "") ⇒ Stripe::Card

Retrieve stripe card for a customer

Parameters:

  • customer_id (String) (defaults to: "")

    stripe customer id

  • card_id (String) (defaults to: "")

    stripe card id

Returns:

  • (Stripe::Card)

    stripe card



35
36
37
38
39
# File 'lib/platformx/stripe.rb', line 35

def x_stripe_customer_card(customer_id: "", card_id: "")
	customer = Stripe::Customer.retrieve(customer_id)
	card = customer.sources.retrieve(card_id)
	return card
end

#x_stripe_customer_card_delete(customer_id: "", card_id: "") ⇒ Stripe::Card

Delete a stripe card for a customer

Parameters:

  • customer_id (String) (defaults to: "")

    stripe customer id

  • card_id (String) (defaults to: "")

    stripe card id

Returns:

  • (Stripe::Card)

    stripe card which was deleted



45
46
47
48
49
# File 'lib/platformx/stripe.rb', line 45

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

#x_stripe_invoice(invoice: "") ⇒ Stripe::Invoice

Get specific stripe invoice

Parameters:

  • invoice (String) (defaults to: "")

    stripe invoice id

Returns:

  • (Stripe::Invoice)

    the stripe invoice identified by id



18
19
20
21
# File 'lib/platformx/stripe.rb', line 18

def x_stripe_invoice(invoice: "")
	invoice = Stripe::Invoice.retrieve(invoice)
	return invoice
end

#x_stripe_invoices(customer_id: "") ⇒ Array<Stripe::Invoice>

Provide all stripe invoices

Parameters:

  • customer_id (String) (defaults to: "")

    stripe customer id

Returns:

  • (Array<Stripe::Invoice>)

    collection of stripe invoices



10
11
12
13
# File 'lib/platformx/stripe.rb', line 10

def x_stripe_invoices(customer_id: "")
	invoices = Stripe::Invoice.all
	return invoices
end

#x_stripe_total(amount: "", tax_percentage: "") ⇒ String

Stripe total including tax

Parameters:

  • amount (Numeric) (defaults to: "")

    amount

  • tax_percentage (Numeric) (defaults to: "")

    tax percentage

Returns:

  • (String)

    stripe total including tax if included



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/platformx/stripe.rb', line 55

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