Class: Pin::Receipt
- Inherits:
-
Base
- Object
- Base
- Pin::Receipt
- Defined in:
- lib/pin_up_receipts/receipt.rb
Overview
This class lets you generate and save receipts from a Pin::Charge.
Class Method Summary collapse
-
.root ⇒ Object
include Pin.
Instance Method Summary collapse
-
#initialize(charge, your_details, logo_path = '', payment_options = {}, template_path = 'views/receipt.html.erb', save_path = 'tmp/receipt.html') ⇒ Receipt
constructor
Create a new PinUpReceipts::Receipt instance Args: charge: Charge hash from Pin::Charge.find your_details: (Array), an Array of details you would like displayed about you or your company payment_options: (Hash), If your charge had extra components (such as late fees or discounts or taxes) pass them in here as a hash eg:.
-
#render ⇒ Object
Renders the HTML receipt but does not save it – useful for showing on screen.
-
#save ⇒ Object
Renders and saves the HTML receipt – useful for emailing receipt.
Constructor Details
#initialize(charge, your_details, logo_path = '', payment_options = {}, template_path = 'views/receipt.html.erb', save_path = 'tmp/receipt.html') ⇒ Receipt
Create a new PinUpReceipts::Receipt instance Args:
charge: Charge hash from Pin::Charge.find
your_details: (Array), an Array of details you would like displayed about you or your company
payment_options: (Hash), If your charge had extra components (such as late fees or discounts or taxes) pass them in here as a hash eg:
payment_options = {}
payment_options["fee"] = {"name" => "late fee", "amount" => "$10.00"}
payment_options["tax"] = {"name" => "GST", "amount" => "$10.00"}
payment_options["discount"] = {"name" => "Member Discount", "amount" => "$10.00"}
template_path: (String), path to your own template if you wish to design your own receipt (take a look at the included template for variable names)
save_path: (String), path that the HTML receipt will be saved
25 26 27 28 29 30 31 32 33 |
# File 'lib/pin_up_receipts/receipt.rb', line 25 def initialize(charge, your_details, logo_path='', ={}, template_path = 'views/receipt.html.erb', save_path = 'tmp/receipt.html') @charge = charge @logo = logo_path @details = your_details @payment_options = @template_path = template_path if template_path @save_path = save_path if save_path @amount = number_to_currency(@charge["amount"], @charge["currency"]) end |
Class Method Details
.root ⇒ Object
include Pin
8 9 10 |
# File 'lib/pin_up_receipts/receipt.rb', line 8 def self.root File. '../../..', __FILE__ end |
Instance Method Details
#render ⇒ Object
Renders the HTML receipt but does not save it – useful for showing on screen
37 38 39 40 |
# File 'lib/pin_up_receipts/receipt.rb', line 37 def render template = ERB.new File.new(@template_path).read, nil, "%" template.result(binding) end |
#save ⇒ Object
Renders and saves the HTML receipt – useful for emailing receipt
44 45 46 47 48 |
# File 'lib/pin_up_receipts/receipt.rb', line 44 def save receipt = File.new(@save_path, 'w') receipt.write(render) receipt.close end |