module Platformx::StripeHelpers

Stripe helpers module @author Tim Mushen

Public Instance Methods

x_stripe_customer(customer_id: "") click to toggle source

Get stripe customer @param customer_id [String] stripe customer id @return [Stripe::Customer] stripe customer identified by id

# 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: "") click to toggle source

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

# 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: "") click to toggle source

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

# 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: "") click to toggle source

Get specific stripe invoice @param invoice [String] stripe invoice id @return [Stripe::Invoice] the stripe invoice identified by id

# 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: "") click to toggle source

Provide all stripe invoices @param customer_id [String] stripe customer id @return [Array<Stripe::Invoice>] collection of stripe invoices

# 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: "") click to toggle source

Stripe total including tax @param amount [Numeric] amount @param tax_percentage [Numeric] tax percentage @return [String] stripe total including tax if included

# 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