NewMonarch-remit 0.0.1

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 +79 -0
  3. data/lib/remit.rb +133 -0
  4. data/lib/remit/cancel_token.rb +18 -0
  5. data/lib/remit/common.rb +87 -0
  6. data/lib/remit/data_types.rb +164 -0
  7. data/lib/remit/discard_results.rb +18 -0
  8. data/lib/remit/error_codes.rb +116 -0
  9. data/lib/remit/fund_prepaid.rb +31 -0
  10. data/lib/remit/get_account_activity.rb +60 -0
  11. data/lib/remit/get_account_balance.rb +29 -0
  12. data/lib/remit/get_all_credit_instruments.rb +18 -0
  13. data/lib/remit/get_all_prepaid_instruments.rb +18 -0
  14. data/lib/remit/get_debt_balance.rb +23 -0
  15. data/lib/remit/get_outstanding_debt_balance.rb +22 -0
  16. data/lib/remit/get_payment_instruction.rb +21 -0
  17. data/lib/remit/get_pipeline.rb +181 -0
  18. data/lib/remit/get_prepaid_balance.rb +23 -0
  19. data/lib/remit/get_results.rb +27 -0
  20. data/lib/remit/get_token_by_caller.rb +19 -0
  21. data/lib/remit/get_token_usage.rb +18 -0
  22. data/lib/remit/get_tokens.rb +20 -0
  23. data/lib/remit/get_total_prepaid_liability.rb +22 -0
  24. data/lib/remit/get_transaction.rb +42 -0
  25. data/lib/remit/install_payment_instruction.rb +22 -0
  26. data/lib/remit/ipn_request.rb +56 -0
  27. data/lib/remit/pay.rb +35 -0
  28. data/lib/remit/pipeline_response.rb +62 -0
  29. data/lib/remit/refund.rb +38 -0
  30. data/lib/remit/reserve.rb +30 -0
  31. data/lib/remit/retry_transaction.rb +18 -0
  32. data/lib/remit/settle.rb +20 -0
  33. data/lib/remit/settle_debt.rb +30 -0
  34. data/lib/remit/subscribe_for_caller_notification.rb +18 -0
  35. data/lib/remit/unsubscribe_for_caller_notification.rb +17 -0
  36. data/lib/remit/write_off_debt.rb +28 -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 +40 -0
  41. data/spec/units/get_pipeline_spec.rb +165 -0
  42. data/spec/units/get_results_spec.rb +47 -0
  43. data/spec/units/ipn_request_spec.rb +34 -0
  44. data/spec/units/pay_spec.rb +70 -0
  45. data/spec/units/units_helper.rb +4 -0
  46. metadata +115 -0
@@ -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
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,116 @@
1
+ # scraped and categorized from http://docs.amazonwebservices.com/AmazonFPS/2007-01-08/FPSDeveloperGuide/index.html?ErrorCodesTable.html
2
+ # you can use these categories to specify default error handling in your application such as asking users to retry or sending an exception email.
3
+ module Remit::ErrorCodes
4
+ class << self
5
+ def sender_error?(code)
6
+ SENDER.include? code.to_sym
7
+ end
8
+
9
+ def recipient_error?(code)
10
+ RECIPIENT.include? code.to_sym
11
+ end
12
+
13
+ def caller_error?(code)
14
+ CALLER.include?(code.to_sym)
15
+ end
16
+
17
+ def amazon_error?(code)
18
+ AMAZON.include? code.to_sym
19
+ end
20
+
21
+ def api_error?(code)
22
+ API.include? code.to_sym
23
+ end
24
+
25
+ def unknown_error?(code)
26
+ UNKNOWN.include? code.to_sym
27
+ end
28
+ end
29
+
30
+ SENDER = [
31
+ :InactiveAccount_Sender, # The sender's account is in suspended or closed state.
32
+ :InactiveInstrument, # The payment instrument used for this transaction is no longer active.
33
+ :InstrumentExpired, # The prepaid or the postpaid instrument has expired.
34
+ :InstrumentNotActive, # The prepaid or postpaid instrument used in the transaction is not active.
35
+ :InvalidAccountState_Sender, # Sender account cannot participate in the transaction.
36
+ :InvalidInstrumentForAccountType, # The sender account can use only credit cards
37
+ :InvalidInstrumentState, # The prepaid or credit instrument should be active
38
+ :InvalidTokenId_Sender, # The send token specified is either invalid or canceled or the token is not active.
39
+ :PaymentInstrumentNotCC, # The payment method specified in the transaction is not a credit card. You can only use a credit card for this transaction.
40
+ :PaymentInstrumentMissing, # There needs to be a payment instrument defined in the token which defines the payment method.
41
+ :TokenNotActive_Sender, # The sender token is canceled.
42
+ :UnverifiedAccount_Sender, # The sender's account must have a verified U.S. credit card or a verified U.S bank account before this transaction can be initiated
43
+ :UnverifiedBankAccount, # A verified bank account should be used for this transaction
44
+ :UnverifiedEmailAddress_Sender, # The sender account must have a verified e-mail address for this payment
45
+ ]
46
+
47
+ RECIPIENT = [
48
+ :InactiveAccount_Recipient, # The recipient's account is in suspended or closed state.
49
+ :InvalidAccountState_Recipient, # Recipient account cannot participate in the transaction
50
+ :InvalidRecipientRoleForAccountType, # The recipient account is not allowed to receive payments
51
+ :InvalidRecipientForCCTransaction, # This account cannot receive credit card payments.
52
+ :InvalidTokenId_Recipient, # The recipient token specified is either invalid or canceled.
53
+ :TokenNotActive_Recipient, # The recipient token is canceled.
54
+ :UnverifiedAccount_Recipient, # The recipient's account must have a verified bank account or a credit card before this transaction can be initiated.
55
+ :UnverifiedEmailAddress_Recipient, # The recipient account must have a verified e-mail address for receiving payments.
56
+ ]
57
+
58
+ CALLER = [
59
+ :InactiveAccount_Caller, # The caller's account is in suspended or closed state.
60
+ :InvalidAccountState_Caller, # The caller account cannot participate in the transaction
61
+ :InvalidTokenId_Caller, # The caller token specified is either invalid or canceled or the specified token is not active.
62
+ :TokenNotActive_Caller, # The caller token is canceled.
63
+ :UnverifiedEmailAddress_Caller, # The caller account must have a verified e-mail address
64
+ ]
65
+
66
+ AMAZON = [
67
+ :InternalError # A retriable error that happens due to some transient problem in the system.
68
+ ]
69
+
70
+ # bad syntax or logic
71
+ API = [
72
+ :AmountOutOfRange, # The transaction amount is more than the allowed range.
73
+ :BadRule, # One of the GK constructs is not well defined
74
+ :CannotSpecifyUsageForSingleUseToken, # Token usages cannot be specified for a single use token.
75
+ :ConcurrentModification, # A retriable error can happen due to concurrent modification of data by two processes.
76
+ :DuplicateRequest, # A different request associated with this caller reference already exists.
77
+ :IncompatibleTokens, # The transaction could not be completed because the tokens have incompatible payment instructions.
78
+ :InstrumentAccessDenied, # The external calling application is not the recipient for this postpaid or prepaid instrument. The caller should be the liability holder
79
+ :InvalidCallerReference, # The CallerReferece does not have a token associated with it.
80
+ :InvalidDateRange, # The end date specified is before the start date or the start date is in the future.
81
+ :InvalidEvent, # The event specified was not subscribed using the SubscribeForCallerNotification operation.
82
+ :InvalidParams, # One or more parameters in the request is invalid.
83
+ :InvalidPaymentInstrument, # The payment method used in the transaction is invalid.
84
+ :InvalidPaymentMethod, # Payment method specified in the GK construct is invalid.
85
+ :InvalidSenderRoleForAccountType, # This token cannot be used for this operation.
86
+ :InvalidTokenId, # The token that you are trying to cancel was not installed by you.
87
+ :InvalidTokenType, # Invalid operation performed on the token. Example, getting the token usage information on a single use token.
88
+ :InvalidTransactionId, # The specified transaction could not be found or the caller did not execute the transaction or this is not a Pay or Reserve call.
89
+ :InvalidTransactionState, # The transaction is not completed or it has been temporarily failed.
90
+ :InvalidUsageDuration, # The duration cannot be less than one hour.
91
+ :InvalidUsageLimitCount, # The usage count is null or empty.
92
+ :InvalidUsageStartTime, # The start time specified for the token is not valid.
93
+ :InvalidUsageType, # The usage type specified is invalid.
94
+ :OriginalTransactionIncomplete, # The original transaction is still in progress.
95
+ :OriginalTransactionFailed, # The original transaction has failed
96
+ :PaymentMethodNotDefined, # Payment method is not defined in the transaction.
97
+ :RefundAmountExceeded, # The refund amount is more than the refundable amount.
98
+ :SameTokenIdUsedMultipleTimes, # This token is already used in earlier transactions.
99
+ :SenderNotOriginalRecipient, # The sender in the refund transaction is not the recipient of the original transaction.
100
+ :SettleAmountGreaterThanReserveAmount, # The amount being settled is greater than the reserved amount.
101
+ :TransactionDenied, # This transaction is not allowed.
102
+ :TransactionExpired, # Returned when the Caller attempts to explicitly retry a transaction that is temporarily declined and is in queue for implicit retry.
103
+ :TransactionFullyRefundedAlready, # The complete refund for this transaction is already completed
104
+ :TransactionTypeNotRefundable, # You cannot refund this transaction.
105
+ :TokenAccessDenied, # Permission is denied to cancel the token.
106
+ :TokenUsageError, # The token usage limit is exceeded.
107
+ :UsageNotDefined, # For a multi-use token or a recurring token the usage limits are not specified in the GateKeeper text.
108
+ ]
109
+
110
+ # these errors don't specify who is at fault
111
+ UNKNOWN = [
112
+ :InvalidAccountState, # The account is either suspended or closed. Payment instructions cannot be installed on this account.
113
+ :InsufficientBalance, # The sender, caller, or recipient's account balance has insufficient funds to complete the transaction.
114
+ :AccountLimitsExceeded, # The spending or the receiving limit on the account is exceeded
115
+ ]
116
+ 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
10
+ parameter :caller_token_id
11
+ parameter :charge_fee_to
12
+ parameter :funding_amount
13
+ parameter :meta_data
14
+ parameter :prepaid_instrument_id
15
+ parameter :recipient_description
16
+ parameter :recipient_reference
17
+ parameter :sender_description
18
+ parameter :sender_reference
19
+ parameter :sender_token_id
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
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
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
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,181 @@
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
+
39
+ def initialize(api, pipeline, options)
40
+ @api = api
41
+ @pipeline = pipeline
42
+
43
+ options.each do |k,v|
44
+ self.send("#{k}=", v)
45
+ end
46
+ end
47
+
48
+ def url
49
+ uri = URI.parse(@pipeline)
50
+
51
+ query = {}
52
+ self.class.parameters.each do |p|
53
+ val = self.send(p)
54
+
55
+ # Convert Time values to seconds from Epoch
56
+ val = val.to_i if val.class == Time
57
+
58
+ query[self.class.convert_key(p.to_s)] = val
59
+ end
60
+
61
+ # Remove any unused optional parameters
62
+ query.reject! { |key, value| value.nil? }
63
+
64
+ uri.query = SignedQuery.new(@api.pipeline, @api.secret_key, query).to_s
65
+ uri.to_s
66
+ end
67
+ end
68
+
69
+ class SingleUsePipeline < Pipeline
70
+ parameter :caller_reference
71
+ parameter :payment_reason
72
+ parameter :payment_method
73
+ parameter :transaction_amount
74
+ parameter :recipient_token
75
+
76
+ def pipeline_name
77
+ Remit::PipelineName::SINGLE_USE
78
+ end
79
+ end
80
+
81
+ class MultiUsePipeline < Pipeline
82
+ parameter :caller_reference
83
+ parameter :payment_reason
84
+ parameter :recipient_token_list
85
+ parameter :amount_type
86
+ parameter :transaction_amount
87
+ parameter :validity_start
88
+ parameter :validity_expiry
89
+ parameter :payment_method
90
+ parameter :global_amount_limit
91
+ parameter :usage_limit_type_1
92
+ parameter :usage_limit_period_1
93
+ parameter :usage_limit_value_1
94
+ parameter :usage_limit_type_2
95
+ parameter :usage_limit_period_2
96
+ parameter :usage_limit_value_2
97
+ parameter :is_recipient_cobranding
98
+
99
+ def pipeline_name
100
+ Remit::PipelineName::MULTI_USE
101
+ end
102
+ end
103
+
104
+ class RecipientPipeline < Pipeline
105
+ parameter :caller_reference
106
+ parameter :validity_start # Time or seconds from Epoch
107
+ parameter :validity_expiry # Time or seconds from Epoch
108
+ parameter :payment_method
109
+ parameter :recipient_pays_fee
110
+ parameter :caller_reference_refund
111
+ parameter :max_variable_fee
112
+ parameter :max_fixed_fee
113
+
114
+ def pipeline_name
115
+ Remit::PipelineName::RECIPIENT
116
+ end
117
+ end
118
+
119
+ class RecurringUsePipeline < Pipeline
120
+ parameter :caller_reference
121
+ parameter :payment_reason
122
+ parameter :recipient_token
123
+ parameter :transaction_amount
124
+ parameter :validity_start # Time or seconds from Epoch
125
+ parameter :validity_expiry # Time or seconds from Epoch
126
+ parameter :payment_method
127
+ parameter :recurring_period
128
+
129
+ def pipeline_name
130
+ Remit::PipelineName::RECURRING
131
+ end
132
+ end
133
+
134
+ class PostpaidPipeline < Pipeline
135
+ parameter :caller_reference_sender
136
+ parameter :caller_reference_settlement
137
+ parameter :payment_reason
138
+ parameter :payment_method
139
+ parameter :validity_start # Time or seconds from Epoch
140
+ parameter :validity_expiry # Time or seconds from Epoch
141
+ parameter :credit_limit
142
+ parameter :global_amount_limit
143
+ parameter :usage_limit_type1
144
+ parameter :usage_limit_period1
145
+ parameter :usage_limit_value1
146
+ parameter :usage_limit_type2
147
+ parameter :usage_limit_period2
148
+ parameter :usage_limit_value2
149
+
150
+ def pipeline_name
151
+ Remit::PipelineName::SETUP_POSTPAID
152
+ end
153
+ end
154
+
155
+ def get_single_use_pipeline(options)
156
+ self.get_pipeline(SingleUsePipeline, options)
157
+ end
158
+
159
+ def get_multi_use_pipeline(options)
160
+ self.get_pipeline(MultiUsePipeline, options)
161
+ end
162
+
163
+ def get_recipient_pipeline(options)
164
+ self.get_pipeline(RecipientPipeline, options)
165
+ end
166
+
167
+ def get_recurring_use_pipeline(options)
168
+ self.get_pipeline(RecurringUsePipeline, options)
169
+ end
170
+
171
+ def get_postpaid_pipeline(options)
172
+ self.get_pipeline(PostpaidPipeline, options)
173
+ end
174
+
175
+ def get_pipeline(pipeline_subclass, options)
176
+ pipeline = pipeline_subclass.new(self, @pipeline, {
177
+ :caller_key => @access_key
178
+ }.merge(options))
179
+ end
180
+ end
181
+ end