pboling-remit 0.0.2.4 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. data/LICENSE +20 -0
  2. data/README.markdown +91 -0
  3. data/lib/remit/common.rb +110 -0
  4. data/lib/remit/data_types.rb +170 -0
  5. data/lib/remit/error_codes.rb +118 -0
  6. data/lib/remit/get_pipeline.rb +212 -0
  7. data/lib/remit/ipn_request.rb +46 -0
  8. data/lib/remit/operations/cancel_token.rb +18 -0
  9. data/lib/remit/operations/discard_results.rb +18 -0
  10. data/lib/remit/operations/fund_prepaid.rb +31 -0
  11. data/lib/remit/operations/get_account_activity.rb +60 -0
  12. data/lib/remit/operations/get_account_balance.rb +29 -0
  13. data/lib/remit/operations/get_all_credit_instruments.rb +18 -0
  14. data/lib/remit/operations/get_all_prepaid_instruments.rb +18 -0
  15. data/lib/remit/operations/get_debt_balance.rb +23 -0
  16. data/lib/remit/operations/get_outstanding_debt_balance.rb +22 -0
  17. data/lib/remit/operations/get_payment_instruction.rb +21 -0
  18. data/lib/remit/operations/get_prepaid_balance.rb +23 -0
  19. data/lib/remit/operations/get_results.rb +27 -0
  20. data/lib/remit/operations/get_token_by_caller.rb +19 -0
  21. data/lib/remit/operations/get_token_usage.rb +18 -0
  22. data/lib/remit/operations/get_tokens.rb +20 -0
  23. data/lib/remit/operations/get_total_prepaid_liability.rb +22 -0
  24. data/lib/remit/operations/get_transaction.rb +54 -0
  25. data/lib/remit/operations/install_payment_instruction.rb +22 -0
  26. data/lib/remit/operations/pay.rb +30 -0
  27. data/lib/remit/operations/refund.rb +44 -0
  28. data/lib/remit/operations/reserve.rb +30 -0
  29. data/lib/remit/operations/retry_transaction.rb +18 -0
  30. data/lib/remit/operations/settle.rb +20 -0
  31. data/lib/remit/operations/settle_debt.rb +30 -0
  32. data/lib/remit/operations/subscribe_for_caller_notification.rb +18 -0
  33. data/lib/remit/operations/unsubscribe_for_caller_notification.rb +17 -0
  34. data/lib/remit/operations/write_off_debt.rb +28 -0
  35. data/lib/remit/pipeline_response.rb +64 -0
  36. data/lib/remit.rb +127 -0
  37. data/spec/integrations/get_account_activity_spec.rb +36 -0
  38. data/spec/integrations/get_tokens_spec.rb +38 -0
  39. data/spec/integrations/integrations_helper.rb +8 -0
  40. data/spec/spec_helper.rb +36 -0
  41. data/spec/units/get_pipeline_spec.rb +165 -0
  42. data/spec/units/get_results_spec.rb +49 -0
  43. data/spec/units/ipn_request_spec.rb +32 -0
  44. data/spec/units/pay_spec.rb +133 -0
  45. data/spec/units/units_helper.rb +4 -0
  46. metadata +64 -19
@@ -0,0 +1,212 @@
1
+ require 'erb'
2
+
3
+ require 'remit/common'
4
+
5
+ module Remit
6
+ module GetPipeline
7
+ class Pipeline
8
+ @parameters = []
9
+ attr_reader :parameters
10
+
11
+ class << self
12
+ # Create the parameters hash for the subclass.
13
+ def inherited(subclass) #:nodoc:
14
+ subclass.instance_variable_set('@parameters', [])
15
+ end
16
+
17
+ def parameter(name)
18
+ attr_accessor name
19
+ @parameters << name
20
+ end
21
+
22
+ def convert_key(key)
23
+ key.to_s.gsub(/_(.)/) { $1.upcase }.to_sym
24
+ end
25
+
26
+ # Returns a hash of all of the parameters for this request, including
27
+ # those that are inherited.
28
+ def parameters #:nodoc:
29
+ (superclass.respond_to?(:parameters) ? superclass.parameters : []) + @parameters
30
+ end
31
+ end
32
+
33
+ attr_reader :api
34
+
35
+ parameter :pipeline_name
36
+ parameter :return_url
37
+ parameter :caller_key
38
+ parameter :version
39
+ parameter :address_name
40
+ parameter :address_line_1
41
+ parameter :address_line_2
42
+ parameter :city
43
+ parameter :state
44
+ parameter :zip
45
+ parameter :country
46
+ parameter :phone_number
47
+
48
+ def initialize(api, options)
49
+ @api = api
50
+
51
+ options.each do |k,v|
52
+ self.send("#{k}=", v)
53
+ end
54
+ end
55
+
56
+ def url
57
+ uri = URI.parse(@api.pipeline_url)
58
+
59
+ query = {}
60
+ self.class.parameters.each do |p|
61
+ val = self.send(p)
62
+
63
+ # Convert Time values to seconds from Epoch
64
+ val = val.to_i if val.is_a?(Time)
65
+
66
+ query[self.class.convert_key(p.to_s)] = val
67
+ end
68
+
69
+ # Remove any unused optional parameters
70
+ query.reject! { |key, value| value.nil? || (value.is_a?(String) && value.empty?) }
71
+
72
+ uri.query = SignedQuery.new(@api.pipeline_url, @api.secret_key, query).to_s
73
+ uri.to_s
74
+ end
75
+
76
+ def method_missing(method, *args)
77
+ if self.class.parameters.include?(method.to_sym)
78
+ self.send(method.to_sym)
79
+ else
80
+ super
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ class SingleUsePipeline < Pipeline
87
+ parameter :caller_reference
88
+ parameter :payment_reason
89
+ parameter :payment_method
90
+ parameter :transaction_amount
91
+ parameter :recipient_token
92
+
93
+ def pipeline_name
94
+ Remit::PipelineName::SINGLE_USE
95
+ end
96
+ end
97
+
98
+ class MultiUsePipeline < Pipeline
99
+ parameter :caller_reference
100
+ parameter :payment_reason
101
+ parameter :recipient_token_list
102
+ parameter :amount_type
103
+ parameter :transaction_amount
104
+ parameter :validity_start
105
+ parameter :validity_expiry
106
+ parameter :payment_method
107
+ parameter :global_amount_limit
108
+ parameter :usage_limit_type_1
109
+ parameter :usage_limit_period_1
110
+ parameter :usage_limit_value_1
111
+ parameter :usage_limit_type_2
112
+ parameter :usage_limit_period_2
113
+ parameter :usage_limit_value_2
114
+ parameter :is_recipient_cobranding
115
+
116
+ def pipeline_name
117
+ Remit::PipelineName::MULTI_USE
118
+ end
119
+ end
120
+
121
+ class RecipientPipeline < Pipeline
122
+ parameter :caller_reference
123
+ parameter :validity_start # Time or seconds from Epoch
124
+ parameter :validity_expiry # Time or seconds from Epoch
125
+ parameter :payment_method
126
+ parameter :recipient_pays_fee
127
+ parameter :caller_reference_refund
128
+ parameter :max_variable_fee
129
+ parameter :max_fixed_fee
130
+
131
+ def pipeline_name
132
+ Remit::PipelineName::RECIPIENT
133
+ end
134
+ end
135
+
136
+ class RecurringUsePipeline < Pipeline
137
+ parameter :caller_reference
138
+ parameter :payment_reason
139
+ parameter :recipient_token
140
+ parameter :transaction_amount
141
+ parameter :validity_start # Time or seconds from Epoch
142
+ parameter :validity_expiry # Time or seconds from Epoch
143
+ parameter :payment_method
144
+ parameter :recurring_period
145
+
146
+ def pipeline_name
147
+ Remit::PipelineName::RECURRING
148
+ end
149
+ end
150
+
151
+ class PostpaidPipeline < Pipeline
152
+ parameter :caller_reference_sender
153
+ parameter :caller_reference_settlement
154
+ parameter :payment_reason
155
+ parameter :payment_method
156
+ parameter :validity_start # Time or seconds from Epoch
157
+ parameter :validity_expiry # Time or seconds from Epoch
158
+ parameter :credit_limit
159
+ parameter :global_amount_limit
160
+ parameter :usage_limit_type1
161
+ parameter :usage_limit_period1
162
+ parameter :usage_limit_value1
163
+ parameter :usage_limit_type2
164
+ parameter :usage_limit_period2
165
+ parameter :usage_limit_value2
166
+
167
+ def pipeline_name
168
+ Remit::PipelineName::SETUP_POSTPAID
169
+ end
170
+ end
171
+
172
+ class EditTokenPipeline < Pipeline
173
+ parameter :caller_reference
174
+ parameter :payment_method
175
+ parameter :token_id
176
+
177
+ def pipeline_name
178
+ Remit::PipelineName::EDIT_TOKEN
179
+ end
180
+ end
181
+
182
+ def get_single_use_pipeline(options)
183
+ self.get_pipeline(SingleUsePipeline, options)
184
+ end
185
+
186
+ def get_multi_use_pipeline(options)
187
+ self.get_pipeline(MultiUsePipeline, {:version => Date.new(2009, 1, 9).to_s}.merge(options))
188
+ end
189
+
190
+ def get_recipient_pipeline(options)
191
+ self.get_pipeline(RecipientPipeline, {:version => Date.new(2009, 1, 9).to_s}.merge(options))
192
+ end
193
+
194
+ def get_recurring_use_pipeline(options)
195
+ self.get_pipeline(RecurringUsePipeline, options)
196
+ end
197
+
198
+ def get_postpaid_pipeline(options)
199
+ self.get_pipeline(PostpaidPipeline, options)
200
+ end
201
+
202
+ def get_edit_token_pipeline(options)
203
+ self.get_pipeline(EditTokenPipeline, options)
204
+ end
205
+
206
+ def get_pipeline(pipeline_subclass, options)
207
+ pipeline = pipeline_subclass.new(self, {
208
+ :caller_key => @access_key
209
+ }.merge(options))
210
+ end
211
+ end
212
+ end
@@ -0,0 +1,46 @@
1
+ require 'base64'
2
+ require 'openssl/digest'
3
+
4
+ module Remit
5
+ # Encapsulates the logic for IPN request validation and attribute retrieval.
6
+ #
7
+ # Note: if your responses from Amazon are not validating, please pass the
8
+ # :version parameter to your original CBUI request.
9
+ class IpnRequest
10
+ # Signature key name used by AmazonFPS IPNs
11
+ SIGNATURE_KEY = 'signature'
12
+
13
+ # +params+ should be your controllers request parameters.
14
+ def initialize(params, secret_key)
15
+ raise ArgumentError, "Expected the request params hash, received: #{params.inspect}" unless params.kind_of?(Hash)
16
+ @params = strip_keys_from(params, 'action', 'controller')
17
+ @supplied_signature = @params.delete(SIGNATURE_KEY)
18
+ @secret_key = secret_key
19
+ end
20
+
21
+ def valid?
22
+ return false unless @supplied_signature
23
+ generate_signature_for(@params) == @supplied_signature
24
+ end
25
+
26
+ def method_missing(method, *args) #:nodoc:
27
+ if @params.has_key?(method.to_s)
28
+ @params[method.to_s]
29
+ else
30
+ super(method, *args)
31
+ end
32
+ end
33
+
34
+ def generate_signature_for(params)
35
+ SignedQuery.signature(@secret_key,params)
36
+ end
37
+ private :generate_signature_for
38
+
39
+ def strip_keys_from(params, *ignore_keys)
40
+ parsed = params.dup
41
+ ignore_keys.each { |key| parsed.delete(key) }
42
+ parsed
43
+ end
44
+ private :strip_keys_from
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module CancelToken
5
+ class Request < Remit::Request
6
+ action :CancelToken
7
+ parameter :token_id, :required => true
8
+ parameter :reason_text
9
+ end
10
+
11
+ class Response < Remit::Response
12
+ end
13
+
14
+ def cancel_token(request = Request.new)
15
+ call(request, Response)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module DiscardResults
5
+ class Request < Remit::Request
6
+ action :DiscardResults
7
+ parameter :transaction_ids, :required => true
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ parameter :discard_errors
12
+ end
13
+
14
+ def discard_results(request = Request.new)
15
+ call(request, Response)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module FundPrepaid
5
+ class Request < Remit::Request
6
+ action :FundPrepaid
7
+ parameter :transaction_ids
8
+ parameter :caller_description
9
+ parameter :caller_reference, :required => true
10
+ parameter :caller_token_id, :required => true
11
+ parameter :charge_fee_to, :required => true
12
+ parameter :funding_amount, :type => Remit::RequestTypes::Amount, :required => true
13
+ parameter :meta_data
14
+ parameter :prepaid_instrument_id, :required => true
15
+ parameter :recipient_description
16
+ parameter :recipient_reference
17
+ parameter :sender_description
18
+ parameter :sender_reference
19
+ parameter :sender_token_id, :required => true
20
+ parameter :transaction_date
21
+ end
22
+
23
+ class Response < Remit::Response
24
+ parameter :transaction_response, :type => TransactionResponse
25
+ end
26
+
27
+ def fund_prepaid(request = Request.new)
28
+ call(request, Response)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,60 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetAccountActivity
5
+ class Request < Remit::Request
6
+ action :GetAccountActivity
7
+ parameter :start_date, :required => true
8
+ parameter :end_date
9
+ parameter :max_batch_size
10
+ parameter :sort_order_by_date
11
+ parameter :response_group
12
+ parameter :operation
13
+ parameter :payment_method
14
+ parameter :role
15
+ parameter :status
16
+ end
17
+
18
+ class Response < Remit::Response
19
+ class Transaction < Remit::BaseResponse
20
+ class TransactionPart < Remit::BaseResponse
21
+ parameter :account_id
22
+ parameter :role
23
+ parameter :name
24
+ parameter :reference
25
+ parameter :description
26
+ parameter :fee_paid, :type => Amount
27
+ end
28
+
29
+ parameter :caller_name
30
+ parameter :caller_token_id
31
+ parameter :caller_transaction_date, :type => :time
32
+ parameter :date_completed, :type => :time
33
+ parameter :date_received, :type => :time
34
+ parameter :error_code
35
+ parameter :error_detail
36
+ parameter :error_message
37
+ parameter :fees, :type => Amount
38
+ parameter :meta_data
39
+ parameter :operation
40
+ parameter :original_transaction_id
41
+ parameter :payment_method
42
+ parameter :recipient_name
43
+ parameter :sender_name
44
+ parameter :sender_token_id
45
+ parameter :status
46
+ parameter :transaction_amount, :type => Amount
47
+ parameter :transaction_id
48
+ parameter :transaction_parts, :collection => TransactionPart
49
+ end
50
+
51
+ parameter :response_batch_size
52
+ parameter :transactions, :collection => Transaction
53
+ parameter :start_time_for_next_transaction, :type => :time
54
+ end
55
+
56
+ def get_account_activity(request = Request.new)
57
+ call(request, Response)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetAccountBalance
5
+ class Request < Remit::Request
6
+ action :GetAccountBalance
7
+ end
8
+
9
+ class Response < Remit::Response
10
+ class AccountBalance < Remit::BaseResponse
11
+ class AvailableBalances < Remit::BaseResponse
12
+ parameter :disburse_balance, :type => Amount
13
+ parameter :refund_balance, :type => Amount
14
+ end
15
+
16
+ parameter :total_balance, :type => Amount
17
+ parameter :pending_in_balance, :type => Amount
18
+ parameter :pending_out_balance, :type => Amount
19
+ parameter :available_balances, :type => AvailableBalances
20
+ end
21
+
22
+ parameter :account_balance, :type => AccountBalance
23
+ end
24
+
25
+ def get_account_balance(request = Request.new)
26
+ call(request, Response)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetAllCreditInstruments
5
+ class Request < Remit::Request
6
+ action :GetAllCreditInstruments
7
+ parameter :instrument_status
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ parameter :credit_instrument_ids
12
+ end
13
+
14
+ def get_all_credit_instruments(request = Request.new)
15
+ call(request, Response)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetAllPrepaidInstruments
5
+ class Request < Remit::Request
6
+ action :GetAllPrepaidInstruments
7
+ parameter :instrument_status
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ parameter :prepaid_instrument_ids
12
+ end
13
+
14
+ def get_all_prepaid_instruments(request = Request.new)
15
+ call(request, Response)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetDebtBalance
5
+ class Request < Remit::Request
6
+ action :GetDebtBalance
7
+ parameter :credit_instrument_id, :required => true
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ class DebtBalance < Remit::BaseResponse
12
+ parameter :available_balance, :type => Amount
13
+ parameter :pending_out_balance, :type => Amount
14
+ end
15
+
16
+ parameter :debt_balance, :type => DebtBalance
17
+ end
18
+
19
+ def get_debt_balance(request = Request.new)
20
+ call(request, Response)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetOutstandingDebtBalance
5
+ class Request < Remit::Request
6
+ action :GetOutStandingDebtBalance
7
+ end
8
+
9
+ class Response < Remit::Response
10
+ class OutstandingDebtBalance < Remit::BaseResponse
11
+ parameter :outstanding_balance, :type => Amount
12
+ parameter :pending_out_balance, :type => Amount
13
+ end
14
+
15
+ parameter :outstanding_debt, :type => OutstandingDebtBalance
16
+ end
17
+
18
+ def get_outstanding_debt_balance(request = Request.new)
19
+ call(request, Response)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetPaymentInstruction
5
+ class Request < Remit::Request
6
+ action :GetPaymentInstruction
7
+ parameter :token_id, :required => true
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ parameter :token, :type => Token
12
+ parameter :payment_instruction
13
+ parameter :account_id
14
+ parameter :token_friendly_name
15
+ end
16
+
17
+ def get_payment_instruction(request = Request.new)
18
+ call(request, Response)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetPrepaidBalance
5
+ class Request < Remit::Request
6
+ action :GetPrepaidBalance
7
+ parameter :prepaid_instrument_id, :required => true
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ class PrepaidBalance < Remit::BaseResponse
12
+ parameter :available_balance, :type => Amount
13
+ parameter :pending_in_balance, :type => Amount
14
+ end
15
+
16
+ parameter :prepaid_balance, :type => PrepaidBalance
17
+ end
18
+
19
+ def get_prepaid_balance(request = Request.new)
20
+ call(request, Response)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetResults
5
+ class Request < Remit::Request
6
+ action :GetResults
7
+ parameter :operation
8
+ parameter :max_results_count
9
+ end
10
+
11
+ class Response < Remit::Response
12
+ class TransactionResults < Remit::BaseResponse
13
+ parameter :transaction_id
14
+ parameter :operation_type, :element => :operation
15
+ parameter :caller_reference
16
+ parameter :transaction_status, :element => :status
17
+ end
18
+
19
+ parameter :transaction_results, :collection => TransactionResults
20
+ parameter :number_pending, :type => :integer
21
+ end
22
+
23
+ def get_results(request = Request.new)
24
+ call(request, Response)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetTokenByCaller
5
+ class Request < Remit::Request
6
+ action :GetTokenByCaller
7
+ parameter :caller_reference
8
+ parameter :token_id
9
+ end
10
+
11
+ class Response < Remit::Response
12
+ parameter :token, :type => Token
13
+ end
14
+
15
+ def get_token_by_caller(request = Request.new)
16
+ call(request, Response)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetTokenUsage
5
+ class Request < Remit::Request
6
+ action :GetTokenUsage
7
+ parameter :token_id, :required => true
8
+ end
9
+
10
+ class Response < Remit::Response
11
+ parameter :token_usage_limits, :type => TokenUsageLimit
12
+ end
13
+
14
+ def get_token_usage(request = Request.new)
15
+ call(request, Response)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetTokens
5
+ class Request < Remit::Request
6
+ action :GetTokens
7
+ parameter :caller_reference
8
+ parameter :token_friendly_name
9
+ parameter :token_status
10
+ end
11
+
12
+ class Response < Remit::Response
13
+ parameter :tokens, :collection => Token
14
+ end
15
+
16
+ def get_tokens(request = Request.new)
17
+ call(request, Response)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ require 'remit/common'
2
+
3
+ module Remit
4
+ module GetTotalPrepaidLiability
5
+ class Request < Remit::Request
6
+ action :GetTotalPrepaidLiability
7
+ end
8
+
9
+ class Response < Remit::Response
10
+ class OutstandingPrepaidLiability < Remit::BaseResponse
11
+ parameter :outstanding_balance, :type => Amount
12
+ parameter :panding_in_balance, :type => Amount
13
+ end
14
+
15
+ parameter :outstanding_prepaid_liability, :type => OutstandingPrepaidLiability
16
+ end
17
+
18
+ def get_total_prepaid_liability(request = Request.new)
19
+ call(request, Response)
20
+ end
21
+ end
22
+ end