Class: StarRezAccount
- Includes:
- HTTParty
- Defined in:
- lib/starrez_api/star_rez_account.rb
Instance Attribute Summary collapse
-
#entry_id ⇒ Object
Returns the value of attribute entry_id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#results ⇒ Object
Returns the value of attribute results.
-
#total_amount ⇒ Object
Returns the value of attribute total_amount.
-
#total_tax_amount ⇒ Object
Returns the value of attribute total_tax_amount.
-
#total_tax_amount2 ⇒ Object
Returns the value of attribute total_tax_amount2.
Class Method Summary collapse
- .create_payment(entry, amount, conditions = {}, options = {}) ⇒ Object
- .create_transaction(entry, amount, conditions = {}, options = {}) ⇒ Object
- .get_balance(*args) ⇒ Object
Instance Attribute Details
#entry_id ⇒ Object
Returns the value of attribute entry_id.
10 11 12 |
# File 'lib/starrez_api/star_rez_account.rb', line 10 def entry_id @entry_id end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/starrez_api/star_rez_account.rb', line 10 def name @name end |
#results ⇒ Object
Returns the value of attribute results.
10 11 12 |
# File 'lib/starrez_api/star_rez_account.rb', line 10 def results @results end |
#total_amount ⇒ Object
Returns the value of attribute total_amount.
10 11 12 |
# File 'lib/starrez_api/star_rez_account.rb', line 10 def total_amount @total_amount end |
#total_tax_amount ⇒ Object
Returns the value of attribute total_tax_amount.
10 11 12 |
# File 'lib/starrez_api/star_rez_account.rb', line 10 def total_tax_amount @total_tax_amount end |
#total_tax_amount2 ⇒ Object
Returns the value of attribute total_tax_amount2.
10 11 12 |
# File 'lib/starrez_api/star_rez_account.rb', line 10 def total_tax_amount2 @total_tax_amount2 end |
Class Method Details
.create_payment(entry, amount, conditions = {}, options = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/starrez_api/star_rez_account.rb', line 79 def self.create_payment(entry,amount,conditions={},={}) conditions[:description] ||= "Deposit" url = "#{base_uri}/accounts/createpayment/#{entry}" charge_groups_string = "" if conditions[:charge_groups].any? break_up_total = conditions[:charge_groups].collect { |g| g[:amount] }.reduce(&:+) raise ArgumentError, "Payment amount and charge group breakup amounts must be equal" unless break_up_total == amount conditions[:charge_groups].each do |charge_group| if charge_group[:id].present? charge_groups_string += %(<BreakUp ChargeGroupID="#{charge_group[:id]}">) elsif charge_group[:name].present? exi charge_groups_string += %(<BreakUp ChargeGroup="#{charge_group[:name]}">) else raise ArgumentError, "Charge group ID or name must be provided" end raise ArgumentError, "Amount must be provided for payment breakup" if charge_group[:amount].blank? charge_groups_string += %(<Amount>#{charge_group[:amount]}</Amount>) if charge_group[:tag].present? charge_groups_string += %(<TransactionTag>#{charge_group[:tag]}</TransactionTag>) end charge_groups_string += %(<TransactionExternalID>#{charge_group[:external_id]}</TransactionExternalID>) if charge_group[:external_id].present? charge_groups_string += %(<TransactionTermSessionID>#{charge_group[:term_session_id]}</TransactionTermSessionID>) if charge_group[:term_session_id].present? charge_groups_string += %(</BreakUp>) end else raise ArgumentError, "At least one charge group must be provided in :charge_groups" end amount_string = %(<Amount>#{amount}</Amount>) description_string = %(<Description>#{conditions[:description]}</Description>) payment_xml = <<XML <Payment> <TransactionTypeEnum>Payment</TransactionTypeEnum> <PaymentTypeID>8</PaymentTypeID> <SecurityUserID>6</SecurityUserID> #{description_string} #{amount_string} #{charge_groups_string} </Payment> XML response = post(url, :body => payment_xml) if [:return].eql? :response return response else if response.code.eql? 409 raise ArgumentError, "Duplicate Transaction Found" elsif response.code.eql? 404 raise ArgumentError, "Invalid Entry ID" elsif response.code.eql? 403 raise SecurityError, 'Access Denied to API' elsif response.code.eql? 400 raise ArgumentError, "Bad Request" elsif response.code.eql? 200 doc = Hpricot(response.body.gsub(/utf-16/,'utf-8')) doc.search("paymentid").inner_html else return false end end end |
.create_transaction(entry, amount, conditions = {}, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/starrez_api/star_rez_account.rb', line 42 def self.create_transaction(entry,amount,conditions={},={}) url = "#{base_uri}/accounts/createtransaction/#{entry}" transaction_xml = <<XML <Transaction> <TransactionTypeEnum>Payment</TransactionTypeEnum> <Amount>#{amount}</Amount> <Description>#{conditions[:description]}</Description> <TermSessionID>#{conditions[:term_session_id]}</TermSessionID> <ExternalID>#{conditions[:external_id]}</ExternalID> <Comments>#{conditions[:comments]}</Comments> <ChargeGroupID>#{conditions[:charge_group_id]}</ChargeGroupID> <ChargeItemID>#{conditions[:charge_item_id]}</ChargeItemID> <SecurityUserID>6</SecurityUserID> </Transaction> XML response = post(url, :body => transaction_xml) if [:return].eql? :response return response else if response.code.eql? 409 raise ArgumentError, "Duplicate Transaction Found" elsif response.code.eql? 404 raise ArgumentError, "Invalid Entry ID" elsif response.code.eql? 403 raise SecurityError, 'Access Denied to API' elsif response.code.eql? 400 raise ArgumentError, "Bad Request" elsif response.code.eql? 200 doc = Hpricot(response.body.gsub(/utf-16/,'utf-8')) doc.search("transactionid").inner_html else return false end end end |
.get_balance(*args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/starrez_api/star_rez_account.rb', line 12 def self.get_balance(*args) = args. entry = args[0] || @entry_id charge_group = args[1] || [:charge_group] if entry.blank? raise IOError, "Must include an Entry ID to search" end url = "#{base_uri}/accounts/getbalance/#{entry}/#{charge_group}" response = get(url) if [:return].eql? :response return response else if response.code.eql? 404 raise ArgumentError, "Invalid Entry ID" elsif response.code.eql? 403 raise SecurityError, 'Access Denied to API' elsif response.code.eql? 200 doc = Hpricot(response.body.gsub(/utf-16/,'utf-8')) account = StarRezAccount.new account.name = doc.at("Entry").at("title").inner_html account.total_amount = "%.2f" % doc.at("totalamount").inner_html account.total_tax_amount = "%.2f" % doc.at("totaltaxamount").inner_html account.total_tax_amount2 = "%.2f" % doc.at("totaltaxamount2").inner_html account else return false end end end |