Class: PayTrace::Transaction
- Inherits:
-
Object
- Object
- PayTrace::Transaction
- Extended by:
- TransactionOperations
- Defined in:
- lib/paytrace/transaction.rb
Constant Summary collapse
- TRANSACTION_METHOD =
"PROCESSTRANX"- EXPORT_TRANSACTIONS_METHOD =
"ExportTranx"- EXPORT_TRANSACTIONS_RESPONSE =
"TRANSACTIONRECORD"- ATTACH_SIGNATURE_METHOD =
"AttachSignature"- CALCULATE_SHIPPING_COST =
"CalculateShipping"- CALCULATE_SHIPPING_COST_RESPONSE =
"SHIPPINGRECORD"- LEVEL_3_VISA_METHOD =
"Level3Visa"- LEVEL_3_MC_METHOD =
"Level3MCRD"
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#billing_address ⇒ Object
readonly
Returns the value of attribute billing_address.
-
#credit_card ⇒ Object
readonly
Returns the value of attribute credit_card.
-
#customer ⇒ Object
readonly
Returns the value of attribute customer.
-
#discretionary_data ⇒ Object
Returns the value of attribute discretionary_data.
-
#optional_fields ⇒ Object
readonly
Returns the value of attribute optional_fields.
-
#response ⇒ Object
Returns the value of attribute response.
-
#shipping_address ⇒ Object
readonly
Returns the value of attribute shipping_address.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .add_level_three_mc(params = {}) ⇒ Object
- .add_level_three_visa(params = {}) ⇒ Object
- .attach_signature(params = {}) ⇒ Object
- .calculate_shipping(params = {}) ⇒ Object
- .export(params = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Transaction
constructor
A new instance of Transaction.
- #set_request(request) ⇒ Object
- #set_shipping_same_as_billing ⇒ Object
Methods included from TransactionOperations
authorization, capture, cash_advance, forced_sale, refund, sale, store_forward, void
Constructor Details
#initialize(params = {}) ⇒ Transaction
Returns a new instance of Transaction.
100 101 102 103 104 105 106 107 |
# File 'lib/paytrace/transaction.rb', line 100 def initialize(params = {}) @amount = params[:amount] @credit_card = params[:credit_card] @type = params[:type] @customer = params[:customer] @discretionary_data = params[:discretionary_data] || {} include_optional(params[:optional]) if params[:optional] end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
84 85 86 |
# File 'lib/paytrace/transaction.rb', line 84 def amount @amount end |
#billing_address ⇒ Object (readonly)
Returns the value of attribute billing_address.
84 85 86 |
# File 'lib/paytrace/transaction.rb', line 84 def billing_address @billing_address end |
#credit_card ⇒ Object (readonly)
Returns the value of attribute credit_card.
84 85 86 |
# File 'lib/paytrace/transaction.rb', line 84 def credit_card @credit_card end |
#customer ⇒ Object (readonly)
Returns the value of attribute customer.
84 85 86 |
# File 'lib/paytrace/transaction.rb', line 84 def customer @customer end |
#discretionary_data ⇒ Object
Returns the value of attribute discretionary_data.
85 86 87 |
# File 'lib/paytrace/transaction.rb', line 85 def discretionary_data @discretionary_data end |
#optional_fields ⇒ Object (readonly)
Returns the value of attribute optional_fields.
84 85 86 |
# File 'lib/paytrace/transaction.rb', line 84 def optional_fields @optional_fields end |
#response ⇒ Object
Returns the value of attribute response.
85 86 87 |
# File 'lib/paytrace/transaction.rb', line 85 def response @response end |
#shipping_address ⇒ Object (readonly)
Returns the value of attribute shipping_address.
84 85 86 |
# File 'lib/paytrace/transaction.rb', line 84 def shipping_address @shipping_address end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
84 85 86 |
# File 'lib/paytrace/transaction.rb', line 84 def type @type end |
Class Method Details
.add_level_three_mc(params = {}) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/paytrace/transaction.rb', line 205 def self.add_level_three_mc(params = {}) line_items = params.delete(:line_items) || [] request = PayTrace::API::Request.new request.set_param(:method, LEVEL_3_MC_METHOD) request.set_params([ :transaction_id, :invoice, :customer_reference_id, :tax_amount, :national_tax, :freight, :duty, :source_zip, :shipping_postal_code, :shipping_country, :add_tax, :additional_tax_included ], params) line_items.each do |li| request.set_multivalue(:line_item, li) end gateway = PayTrace::API::Gateway.new response = gateway.send_request(request) unless response.has_errors? response.values end end |
.add_level_three_visa(params = {}) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/paytrace/transaction.rb', line 172 def self.add_level_three_visa(params = {}) line_items = params.delete(:line_items) || [] request = PayTrace::API::Request.new request.set_param(:method, LEVEL_3_VISA_METHOD) request.set_params([ :transaction_id, :invoice, :customer_reference_id, :tax_amount, :national_tax, :merchant_tax_id, :customer_tax_id, :ccode, :discount, :freight, :duty, :source_zip, :shipping_postal_code, :shipping_country, :add_tax, :add_tax_rate ], params) line_items.each do |li| request.set_multivalue(:line_item, li) end gateway = PayTrace::API::Gateway.new response = gateway.send_request(request) unless response.has_errors? response.values end end |
.attach_signature(params = {}) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/paytrace/transaction.rb', line 144 def self.attach_signature(params = {}) request = PayTrace::API::Request.new request.set_param(:method, ATTACH_SIGNATURE_METHOD) request.set_param(:transaction_id, params[:transaction_id]) request.set_param(:image_data, params[:image_data]) request.set_param(:image_type, params[:image_type]) if params.has_key?(:image_file) File.open(params[:image_file], 'rb') do |file| request.set_param(:image_data, Base64.encode64(file.read)) end end gateway = PayTrace::API::Gateway.new gateway.send_request(request) end |
.calculate_shipping(params = {}) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/paytrace/transaction.rb', line 160 def self.calculate_shipping(params = {}) request = PayTrace::API::Request.new request.set_param(:method, CALCULATE_SHIPPING_COST) request.set_params(params.keys, params) gateway = PayTrace::API::Gateway.new response = gateway.send_request(request, [CALCULATE_SHIPPING_COST_RESPONSE]) unless response.has_errors? response.values[CALCULATE_SHIPPING_COST_RESPONSE] end end |
.export(params = {}) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/paytrace/transaction.rb', line 124 def self.export(params = {}) request = PayTrace::API::Request.new request.set_param(:method, EXPORT_TRANSACTIONS_METHOD) request.set_param(:transaction_id, params[:transaction_id]) request.set_param(:start_date, params[:start_date]) request.set_param(:end_date, params[:end_date]) request.set_param(:transaction_type, params[:transaction_type]) request.set_param(:customer_id, params[:customer_id]) request.set_param(:transaction_user, params[:transaction_user]) request.set_param(:return_bin, params[:return_bin]) request.set_param(:search_text, params[:search_test]) gateway = PayTrace::API::Gateway.new response = gateway.send_request(request, [EXPORT_TRANSACTIONS_RESPONSE]) unless response.has_errors? response.values[EXPORT_TRANSACTIONS_RESPONSE] end end |
Instance Method Details
#set_request(request) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/paytrace/transaction.rb', line 109 def set_request(request) add_credit_card(request, credit_card) if credit_card if customer.is_a?(PayTrace::Customer) request.set_param(:customer_id, customer.id) elsif customer.is_a?(Fixnum) request.set_param(:customer_id, customer) end add_transaction_info(request) add_addresses(request) add_optional_fields(request) if optional_fields if @discretionary_data.any? request.set_discretionary(@discretionary_data) end end |
#set_shipping_same_as_billing ⇒ Object
96 97 98 |
# File 'lib/paytrace/transaction.rb', line 96 def set_shipping_same_as_billing() @shipping_address = @billing_address end |