Class: MPower::Checkout::Invoice
- Defined in:
- lib/mpower/checkout/redirect_invoice.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cancel_url ⇒ Object
Returns the value of attribute cancel_url.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#custom_data ⇒ Object
Returns the value of attribute custom_data.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#description ⇒ Object
Returns the value of attribute description.
-
#invoice_token ⇒ Object
Returns the value of attribute invoice_token.
-
#invoice_url ⇒ Object
Returns the value of attribute invoice_url.
-
#items ⇒ Object
Returns the value of attribute items.
-
#receipt_url ⇒ Object
Returns the value of attribute receipt_url.
-
#return_url ⇒ Object
Returns the value of attribute return_url.
-
#store ⇒ Object
Returns the value of attribute store.
-
#taxes ⇒ Object
Returns the value of attribute taxes.
-
#total_amount ⇒ Object
Returns the value of attribute total_amount.
Attributes inherited from Core
#response_code, #response_text, #result, #status, #token, #transaction_id
Instance Method Summary collapse
- #add_custom_data(key, value) ⇒ Object
-
#add_item(name, quantity, unit_price, total_price, description = "") ⇒ Object
Adds invoice items to the @items hash, the idea is to allow this function to be used in a loop.
-
#add_tax(name, amount) ⇒ Object
Adds invoice tax to the @taxes hash, the idea is to allow this function to be used in a loop.
- #confirm(token) ⇒ Object
- #create ⇒ Object
- #get_custom_data(key) ⇒ Object
- #get_customer_info(key) ⇒ Object
- #get_items ⇒ Object
- #get_taxes ⇒ Object
-
#initialize ⇒ Invoice
constructor
A new instance of Invoice.
Methods inherited from Core
Methods included from Utilities
#hash_to_json, #http_get_request, #http_json_request, #json_to_hash
Constructor Details
#initialize ⇒ Invoice
Returns a new instance of Invoice.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 8 def initialize @items = {} @taxes = {} @custom_data = {} @customer = {} @total_amount = 0.0 @currency = "ghs" @store = MPower::Checkout::Store @return_url = @store.return_url @cancel_url = @store.cancel_url end |
Instance Attribute Details
#cancel_url ⇒ Object
Returns the value of attribute cancel_url.
6 7 8 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 6 def cancel_url @cancel_url end |
#currency ⇒ Object
Returns the value of attribute currency.
5 6 7 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 5 def currency @currency end |
#custom_data ⇒ Object
Returns the value of attribute custom_data.
6 7 8 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 6 def custom_data @custom_data end |
#customer ⇒ Object
Returns the value of attribute customer.
6 7 8 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 6 def customer @customer end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 5 def description @description end |
#invoice_token ⇒ Object
Returns the value of attribute invoice_token.
5 6 7 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 5 def invoice_token @invoice_token end |
#invoice_url ⇒ Object
Returns the value of attribute invoice_url.
6 7 8 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 6 def invoice_url @invoice_url end |
#items ⇒ Object
Returns the value of attribute items.
5 6 7 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 5 def items @items end |
#receipt_url ⇒ Object
Returns the value of attribute receipt_url.
6 7 8 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 6 def receipt_url @receipt_url end |
#return_url ⇒ Object
Returns the value of attribute return_url.
6 7 8 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 6 def return_url @return_url end |
#store ⇒ Object
Returns the value of attribute store.
5 6 7 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 5 def store @store end |
#taxes ⇒ Object
Returns the value of attribute taxes.
5 6 7 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 5 def taxes @taxes end |
#total_amount ⇒ Object
Returns the value of attribute total_amount.
5 6 7 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 5 def total_amount @total_amount end |
Instance Method Details
#add_custom_data(key, value) ⇒ Object
43 44 45 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 43 def add_custom_data(key,value) @custom_data["#{key}"] = value end |
#add_item(name, quantity, unit_price, total_price, description = "") ⇒ Object
Adds invoice items to the @items hash, the idea is to allow this function to be used in a loop
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 21 def add_item(name,quantity,unit_price,total_price,description="") @items.merge!({ :"item_#{@items.size}" => { :name => name, :quantity => quantity, :unit_price => unit_price, :total_price => total_price, :description => description } }) end |
#add_tax(name, amount) ⇒ Object
Adds invoice tax to the @taxes hash, the idea is to allow this function to be used in a loop
34 35 36 37 38 39 40 41 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 34 def add_tax(name,amount) @taxes.merge!({ :"tax_#{@taxes.size}" => { :name => name, :amount => amount } }) end |
#confirm(token) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 63 def confirm(token) result = http_get_request("#{MPower::Setup.checkout_confirm_base_url}#{token}") unless result.size > 0 @response_text = "Invoice Not Found" @response_code = 1002 @status = MPower::FAIL return false end if result["status"] == "completed" rebuild_invoice(result) @response_text = result["response_text"] true else @status = result["status"] @items = result["invoice"]["items"] @taxes = result["invoice"]["taxes"] @description = result["invoice"]["description"] @custom_data = result["custom_data"] @total_amount = result["invoice"]["total_amount"] @response_text = "Invoice status is #{result['status'].upcase}" false end end |
#create ⇒ Object
88 89 90 91 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 88 def create result = http_json_request(MPower::Setup.checkout_base_url,build_invoice_payload) create_response(result) end |
#get_custom_data(key) ⇒ Object
59 60 61 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 59 def get_custom_data(key) @custom_data["#{key}"] end |
#get_customer_info(key) ⇒ Object
55 56 57 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 55 def get_customer_info(key) @customer["#{key}"] end |
#get_items ⇒ Object
47 48 49 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 47 def get_items @items end |
#get_taxes ⇒ Object
51 52 53 |
# File 'lib/mpower/checkout/redirect_invoice.rb', line 51 def get_taxes @taxes end |