Class: PayTrace::Customer
- Inherits:
-
Object
- Object
- PayTrace::Customer
- Defined in:
- lib/paytrace/customer.rb
Constant Summary collapse
- CREATE_CUSTOMER =
"CreateCustomer"- UPDATE_CUSTOMER =
"UpdateCustomer"- DELETE_CUSTOMER =
"DeleteCustomer"- EXPORT_CUSTOMERS =
"ExportCustomers"- EXPORT_INACTIVE_CUSTOMERS =
"ExportInactiveCustomers"- EXPORT_CUSTOMERS_RESPONSE =
"CUSTOMERRECORD"
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
- .delete(customer_id) ⇒ Object
- .export(params = {}) ⇒ Object
- .export_inactive(params = {}) ⇒ Object
- .from_cc_info(params = {}) ⇒ Object
- .from_transaction_id(params = {}) ⇒ Object
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(customer_id = nil) ⇒ Customer
constructor
A new instance of Customer.
- #set_request_data(method, params) ⇒ Object
- #update(params = {}) ⇒ Object
Constructor Details
#initialize(customer_id = nil) ⇒ Customer
Returns a new instance of Customer.
12 13 14 |
# File 'lib/paytrace/customer.rb', line 12 def initialize(customer_id = nil) @customer_id = customer_id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/paytrace/customer.rb', line 3 def id @id end |
Class Method Details
.delete(customer_id) ⇒ Object
56 57 58 |
# File 'lib/paytrace/customer.rb', line 56 def self.delete(customer_id) Customer.new(customer_id).delete end |
.export(params = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/paytrace/customer.rb', line 28 def self.export(params = {}) # CUSTID, EMAIL, USER, RETURNBIN request = PayTrace::API::Request.new request.set_param(:method, EXPORT_CUSTOMERS) request.set_param(:customer_id, params[:customer_id]) request.set_param(:email, params[:email]) request.set_param(:transaction_user, params[:transaction_user]) request.set_param(:return_bin, params[:return_bin]) gateway = PayTrace::API::Gateway.new response = gateway.send_request(request, [EXPORT_CUSTOMERS_RESPONSE]) unless response.has_errors? response.values[EXPORT_CUSTOMERS_RESPONSE] end end |
.export_inactive(params = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/paytrace/customer.rb', line 44 def self.export_inactive(params = {}) request = PayTrace::API::Request.new request.set_param(:method, EXPORT_INACTIVE_CUSTOMERS) request.set_param(:days_inactive, params[:days_inactive]) gateway = PayTrace::API::Gateway.new response = gateway.send_request(request, [EXPORT_CUSTOMERS_RESPONSE]) unless response.has_errors? response.values[EXPORT_CUSTOMERS_RESPONSE] end end |
.from_cc_info(params = {}) ⇒ Object
60 61 62 63 |
# File 'lib/paytrace/customer.rb', line 60 def self.from_cc_info(params = {}) customer = Customer.new(params[:customer_id]) customer.set_request_data(CREATE_CUSTOMER, params) end |
.from_transaction_id(params = {}) ⇒ Object
65 66 67 68 |
# File 'lib/paytrace/customer.rb', line 65 def self.from_transaction_id(params = {}) customer = Customer.new(params[:customer_id]) customer.set_request_data(CREATE_CUSTOMER, params) end |
Instance Method Details
#delete ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/paytrace/customer.rb', line 20 def delete request = PayTrace::API::Request.new request.set_param(:method, DELETE_CUSTOMER) request.set_param(:customer_id, @customer_id) gateway = PayTrace::API::Gateway.new gateway.send_request(request) end |
#set_request_data(method, params) ⇒ Object
70 71 72 73 74 75 76 77 78 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 |
# File 'lib/paytrace/customer.rb', line 70 def set_request_data(method, params) request = PayTrace::API::Request.new request.set_param(:method, method) request.set_param(:customer_id, params[:customer_id]) request.set_param(:new_customer_id, params[:new_customer_id]) request.set_param(:transaction_id, params[:transaction_id]) if params[:billing_address] params[:billing_address].name = nil if (method == CREATE_CUSTOMER && params[:transaction_id]) params[:billing_address].set_request(request) end params[:shipping_address].set_request(request) if params[:shipping_address] if params[:credit_card] request.set_param(:card_number, params[:credit_card].card_number) request.set_param(:expiration_month, params[:credit_card].expiration_month) request.set_param(:expiration_year, params[:credit_card].expiration_year) end request.set_param(:email, params[:email]) request.set_param(:customer_phone, params[:phone]) request.set_param(:customer_fax, params[:fax]) request.set_param(:customer_password, params[:customer_password]) request.set_param(:account_number, params[:account_number]) request.set_param(:routing_number, params[:routing_number]) if params[:discretionary_data] params[:discretionary_data].keys.each do |k| request.set_discretionary(k, params[:discretionary_data][k]) end end gateway = PayTrace::API::Gateway.new response = gateway.send_request(request) unless response.has_errors? values = response.values @id = values["CUSTID"] @customer_id = values["CUSTOMERID"] self else nil end end |
#update(params = {}) ⇒ Object
16 17 18 |
# File 'lib/paytrace/customer.rb', line 16 def update(params = {}) set_request_data(UPDATE_CUSTOMER, params) end |