Class: PayTrace::RecurringTransaction
- Inherits:
-
Object
- Object
- PayTrace::RecurringTransaction
- Defined in:
- lib/paytrace/recurring_transaction.rb
Overview
Manages recurring transactions
Constant Summary collapse
- CREATE_METHOD =
"CreateRecur"
- DELETE_METHOD =
"DeleteRecur"
- UPDATE_METHOD =
"UpdateRecur"
- EXPORT_APPROVED_METHOD =
"ExportCustomerRecur"
- EXPORT_SCHEDULED_METHOD =
"ExportRecur"
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
:nodoc:.
-
#current_count ⇒ Object
readonly
:nodoc:.
-
#customer_id ⇒ Object
readonly
:nodoc:.
-
#description ⇒ Object
readonly
:nodoc:.
-
#id ⇒ Object
readonly
:nodoc:.
-
#next ⇒ Object
readonly
:nodoc:.
-
#repeat ⇒ Object
readonly
:nodoc:.
-
#total_count ⇒ Object
readonly
:nodoc:.
Class Method Summary collapse
-
.create(params = {}) ⇒ Object
See help.paytrace.com/api-create-recurring-transaction Creates a recurring transaction.
-
.delete(params = {}) ⇒ Object
See help.paytrace.com/api-deleting-a-recurring-transaction Deletes recurring transactions by recurrence ID or customer ID.
-
.export_approved(params = {}) ⇒ Object
See help.paytrace.com/api-exporting-a-recurring-transaction Exports the single most recent recurring transaction for a given customer ID, Params: * :customer_id – the customer ID to be exported for.
-
.export_scheduled(params = {}) ⇒ Object
See help.paytrace.com/api-exporting-recurring-transactions Exports recurring transactions by recurrence ID or customer ID.
-
.parse_response(response) ⇒ Object
:nodoc:.
- .set_request_data(method, params) ⇒ Object
-
.update(params = {}) ⇒ Object
See help.paytrace.com/api-update-recurring-transaction Updates parameters of an existing recurrence.
Instance Method Summary collapse
-
#initialize(raw_response) ⇒ RecurringTransaction
constructor
A new instance of RecurringTransaction.
- #inspect ⇒ Object
Constructor Details
#initialize(raw_response) ⇒ RecurringTransaction
Returns a new instance of RecurringTransaction.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/paytrace/recurring_transaction.rb', line 15 def initialize(raw_response) response_map = Hash[raw_response.split('+').map {|pair| pair.split('=')}] @id = response_map["RECURID"].to_i @amount = response_map["AMOUNT"].to_f @customer_id = response_map["CUSTID"] @next = response_map["NEXT"] @total_count = response_map["TOTALCOUNT"].to_i @current_count = response_map["CURRENTCOUNT"].to_i @repeat = response_map["REPEAT"].to_i @description = response_map["DESCRIPTION"] end |
Instance Attribute Details
#amount ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/paytrace/recurring_transaction.rb', line 7 def amount @amount end |
#current_count ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/paytrace/recurring_transaction.rb', line 7 def current_count @current_count end |
#customer_id ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/paytrace/recurring_transaction.rb', line 7 def customer_id @customer_id end |
#description ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/paytrace/recurring_transaction.rb', line 7 def description @description end |
#id ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/paytrace/recurring_transaction.rb', line 7 def id @id end |
#next ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/paytrace/recurring_transaction.rb', line 7 def next @next end |
#repeat ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/paytrace/recurring_transaction.rb', line 7 def repeat @repeat end |
#total_count ⇒ Object (readonly)
:nodoc:
7 8 9 |
# File 'lib/paytrace/recurring_transaction.rb', line 7 def total_count @total_count end |
Class Method Details
.create(params = {}) ⇒ Object
See help.paytrace.com/api-create-recurring-transaction Creates a recurring transaction. Params:
-
:customer_id – the customer ID for which the recurrence should be created
-
:recur_frequency – the frequency of the recurrence; this must be 1 for annually, 8 for semi-annually, A for trimesterly, 2 for quarterly, 9 for bi-monthly, , 3 for monthly, 4 for bi-weekly, 7 for 1st and 15th, 5 for weekly, or 6 for daily
-
:recur_start – date of the first recurrence
-
:recur_count – the total number of times the recurring transaction should be processed. Use 999 if the recurring transaction should be processed indefinitely
-
:amount – the amount of the recurrence
-
:transaction_type – the transaction type of the recurrence; typically “Sale”
-
:description – an optional description of the recurrence
-
:recur_receipt – “Y” to send a receipt to the customer at each recurrence; default is “N”
-
:recur_type – default value is “C” which represents credit card number. Alternative is “A” which represents an ACH/check transaction
60 61 62 |
# File 'lib/paytrace/recurring_transaction.rb', line 60 def self.create(params = {}) parse_response(set_request_data(CREATE_METHOD, params)) end |
.delete(params = {}) ⇒ Object
See help.paytrace.com/api-deleting-a-recurring-transaction Deletes recurring transactions by recurrence ID or customer ID. Params:
-
:recur_id – a recurrence ID to export
-
:customer_id – a customer ID to export
Note: only supply a recurrence ID or a customer ID, not both.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/paytrace/recurring_transaction.rb', line 69 def self.delete(params = {}) request = PayTrace::API::Request.new request.set_param(:method, DELETE_METHOD) if params[:recur_id] request.set_param(:recur_id, params[:recur_id]) else request.set_param(:customer_id, params[:customer_id]) end gateway = PayTrace::API::Gateway.new parse_response(gateway.send_request(request)) end |
.export_approved(params = {}) ⇒ Object
See help.paytrace.com/api-exporting-a-recurring-transaction Exports the single most recent recurring transaction for a given customer ID, Params:
-
:customer_id – the customer ID to be exported for
45 46 47 |
# File 'lib/paytrace/recurring_transaction.rb', line 45 def self.export_approved(params = {}) set_request_data(EXPORT_APPROVED_METHOD, params) end |
.export_scheduled(params = {}) ⇒ Object
See help.paytrace.com/api-exporting-recurring-transactions Exports recurring transactions by recurrence ID or customer ID. Params:
-
:recur_id – a recurrence ID to export
-
:customer_id – a customer ID to export
Note: only supply a recurrence ID or a customer ID, not both.
38 39 40 |
# File 'lib/paytrace/recurring_transaction.rb', line 38 def self.export_scheduled(params = {}) parse_response(set_request_data(EXPORT_SCHEDULED_METHOD, params)) end |
.parse_response(response) ⇒ Object
:nodoc:
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/paytrace/recurring_transaction.rb', line 99 def self.parse_response(response) unless response.has_errors? values = response.values if values.has_key?("RECURRINGPAYMENT") new(values["RECURRINGPAYMENT"]) else values["RECURID"] end end end |
.set_request_data(method, params) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/paytrace/recurring_transaction.rb', line 111 def self.set_request_data(method, params) request = PayTrace::API::Request.new request.set_param(:method, method) request.set_param(:recur_id, params[:recur_id]) request.set_param(:customer_id, params[:customer_id]) request.set_param(:recur_frequency, params[:recur_frequency]) request.set_param(:recur_start, params[:recur_start]) request.set_param(:recur_next, params[:recur_next]) request.set_param(:recur_count, params[:recur_count]) request.set_param(:amount, params[:amount]) request.set_param(:transaction_type, params[:transaction_type]) request.set_param(:description, params[:description]) request.set_param(:recur_receipt, params[:recur_receipt]) request.set_param(:recur_type, params[:recur_type]) gateway = PayTrace::API::Gateway.new gateway.send_request(request) end |
.update(params = {}) ⇒ Object
See help.paytrace.com/api-update-recurring-transaction Updates parameters of an existing recurrence. Params:
-
:recur_id – a recurrence ID to update
-
:customer_id – the customer ID for which the recurrence should be created
-
:recur_frequency – the frequency of the recurrence; this must be 1 for annually, 8 for semi-annually, A for trimesterly, 2 for quarterly, 9 for bi-monthly, 3 for monthly, 4 for bi-weekly, 7 for 1st and 15th, 5 for weekly, or 6 for daily
-
:recur_next – the date of the next recurrence
-
:recur_count – the total number of times the recurring transaction should be processed. Use 999 if the recurring transaction should be processed indefinitely
-
:amount – the amount of the recurrence
-
:transaction_type – the transaction type of the recurrence; typically “Sale”
-
:description – an optional description of the recurrence
-
:recur_receipt – “Y” to send a receipt to the customer at each recurrence; default is “N”
-
:recur_type – default value is “C” which represents credit card number. Alternative is “A” which represents an ACH/check transaction; note: only use for check/ACH recurrences
94 95 96 |
# File 'lib/paytrace/recurring_transaction.rb', line 94 def self.update(params = {}) parse_response(set_request_data(UPDATE_METHOD, params)) end |
Instance Method Details
#inspect ⇒ Object
27 28 29 |
# File 'lib/paytrace/recurring_transaction.rb', line 27 def inspect "<RecurringTransaction:#{@id},customer id:#{@customer_id},amount: #{@amount},next: #{@next}>" end |