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"
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
- .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
98 99 100 101 102 103 104 105 |
# File 'lib/paytrace/transaction.rb', line 98 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
.attach_signature(params = {}) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/paytrace/transaction.rb', line 142 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
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/paytrace/transaction.rb', line 158 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
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/paytrace/transaction.rb', line 122 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
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/paytrace/transaction.rb', line 107 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
94 95 96 |
# File 'lib/paytrace/transaction.rb', line 94 def set_shipping_same_as_billing() @shipping_address = @billing_address end |