module Platformx module StripeHelpers require "active_support/all" ######################################################## # # Start Helpers # ######################################################## def x_stripe_invoices(customer_id: "") invoices = Stripe::Invoice.all return invoices end def x_stripe_invoice(invoice: "") invoice = Stripe::Invoice.retrieve(invoice) return invoice end def x_stripe_customer(customer_id: "") customer = Stripe::Customer.retrieve(customer_id) return customer end def x_stripe_customer_card(customer_id: "", card_id: "") customer = Stripe::Customer.retrieve(customer_id) card = customer.sources.retrieve(card_id) return card end 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 ######################################################## # # Common functions for Stripe # ######################################################## 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 end