tylerhunt-remit 0.0.1 → 0.0.4

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 (48) hide show
  1. data/LICENSE +1 -1
  2. data/README.markdown +91 -0
  3. data/lib/remit.rb +51 -41
  4. data/lib/remit/common.rb +16 -16
  5. data/lib/remit/data_types.rb +59 -2
  6. data/lib/remit/error_codes.rb +118 -0
  7. data/lib/remit/get_pipeline.rb +65 -7
  8. data/lib/remit/ipn_request.rb +49 -0
  9. data/lib/remit/{cancel_token.rb → operations/cancel_token.rb} +1 -1
  10. data/lib/remit/{discard_results.rb → operations/discard_results.rb} +1 -1
  11. data/lib/remit/{fund_prepaid.rb → operations/fund_prepaid.rb} +6 -6
  12. data/lib/remit/{get_account_activity.rb → operations/get_account_activity.rb} +1 -1
  13. data/lib/remit/{get_account_balance.rb → operations/get_account_balance.rb} +0 -0
  14. data/lib/remit/{get_all_credit_instruments.rb → operations/get_all_credit_instruments.rb} +0 -0
  15. data/lib/remit/{get_all_prepaid_instruments.rb → operations/get_all_prepaid_instruments.rb} +0 -0
  16. data/lib/remit/{get_debt_balance.rb → operations/get_debt_balance.rb} +1 -1
  17. data/lib/remit/{get_outstanding_debt_balance.rb → operations/get_outstanding_debt_balance.rb} +0 -0
  18. data/lib/remit/{get_payment_instruction.rb → operations/get_payment_instruction.rb} +1 -1
  19. data/lib/remit/{get_prepaid_balance.rb → operations/get_prepaid_balance.rb} +1 -1
  20. data/lib/remit/{get_results.rb → operations/get_results.rb} +4 -3
  21. data/lib/remit/{get_token_by_caller.rb → operations/get_token_by_caller.rb} +0 -0
  22. data/lib/remit/{get_token_usage.rb → operations/get_token_usage.rb} +1 -1
  23. data/lib/remit/{get_tokens.rb → operations/get_tokens.rb} +0 -0
  24. data/lib/remit/{get_total_prepaid_liability.rb → operations/get_total_prepaid_liability.rb} +0 -0
  25. data/lib/remit/{get_transaction.rb → operations/get_transaction.rb} +1 -1
  26. data/lib/remit/{install_payment_instruction.rb → operations/install_payment_instruction.rb} +3 -3
  27. data/lib/remit/operations/pay.rb +35 -0
  28. data/lib/remit/{refund.rb → operations/refund.rb} +6 -8
  29. data/lib/remit/{reserve.rb → operations/reserve.rb} +6 -6
  30. data/lib/remit/{retry_transaction.rb → operations/retry_transaction.rb} +1 -1
  31. data/lib/remit/{settle.rb → operations/settle.rb} +2 -2
  32. data/lib/remit/{settle_debt.rb → operations/settle_debt.rb} +6 -6
  33. data/lib/remit/{subscribe_for_caller_notification.rb → operations/subscribe_for_caller_notification.rb} +2 -2
  34. data/lib/remit/{unsubscribe_for_caller_notification.rb → operations/unsubscribe_for_caller_notification.rb} +1 -1
  35. data/lib/remit/{write_off_debt.rb → operations/write_off_debt.rb} +4 -4
  36. data/lib/remit/pipeline_response.rb +52 -0
  37. data/spec/{get_account_activity_spec.rb → integrations/get_account_activity_spec.rb} +4 -4
  38. data/spec/{get_tokens_spec.rb → integrations/get_tokens_spec.rb} +3 -3
  39. data/spec/integrations/integrations_helper.rb +8 -0
  40. data/spec/spec_helper.rb +20 -10
  41. data/spec/{get_pipeline_spec.rb → units/get_pipeline_spec.rb} +83 -24
  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 +49 -45
  47. data/README +0 -38
  48. data/lib/remit/pay.rb +0 -34
@@ -5,17 +5,17 @@ module Remit
5
5
  class Request < Remit::Request
6
6
  action :SettleDebt
7
7
  parameter :caller_description
8
- parameter :caller_reference
9
- parameter :caller_token_id
10
- parameter :charge_fee_to
11
- parameter :credit_instrument_id
8
+ parameter :caller_reference, :required => true
9
+ parameter :caller_token_id, :required => true
10
+ parameter :charge_fee_to, :required => true
11
+ parameter :credit_instrument_id, :required => true
12
12
  parameter :meta_data
13
13
  parameter :recipient_description
14
14
  parameter :recipient_reference
15
15
  parameter :sender_description
16
16
  parameter :sender_reference
17
- parameter :sender_token_id
18
- parameter :settlement_amount
17
+ parameter :sender_token_id, :required => true
18
+ parameter :settlement_amount, :type => Remit::RequestTypes::Amount, :required => true
19
19
  parameter :transaction_date
20
20
  end
21
21
 
@@ -4,8 +4,8 @@ module Remit
4
4
  module SubscribeForCallerNotification
5
5
  class Request < Remit::Request
6
6
  action :SubscribeForCallerNotification
7
- parameter :notification_operation_name
8
- parameter :web_service_api_url
7
+ parameter :notification_operation_name, :required => true
8
+ parameter :web_service_api_url, :required => true
9
9
  end
10
10
 
11
11
  class Response < Remit::Response
@@ -4,7 +4,7 @@ module Remit
4
4
  module UnsubscribeForCallerNotification
5
5
  class Request < Remit::Request
6
6
  action :UnSubscribeForCallerNotification
7
- parameter :notification_operation_name
7
+ parameter :notification_operation_name, :required => true
8
8
  end
9
9
 
10
10
  class Response < Remit::Response
@@ -4,12 +4,12 @@ module Remit
4
4
  module WriteOffDebt
5
5
  class Request < Remit::Request
6
6
  action :WriteOffDebt
7
- parameter :caller_token_id
8
- parameter :credit_instrument_id
9
- parameter :adjustment_amount
7
+ parameter :caller_token_id, :required => true
8
+ parameter :credit_instrument_id, :required => true
9
+ parameter :adjustment_amount, :required => true
10
10
  parameter :transaction_date
11
11
  parameter :sender_reference
12
- parameter :caller_reference
12
+ parameter :caller_reference, :required => true
13
13
  parameter :recipient_reference
14
14
  parameter :sender_description
15
15
  parameter :recipient_description
@@ -0,0 +1,52 @@
1
+ module Remit
2
+ class PipelineResponse
3
+ def initialize(uri, secret_key)
4
+ @uri = URI.parse(uri)
5
+ @secret_key = secret_key
6
+ end
7
+
8
+ # Returns +true+ if the response is correctly signed (awsSignature).
9
+ #
10
+ #--
11
+ # The unescape_value method is used here because the awsSignature value
12
+ # pulled from the request is filtered through the same method.
13
+ #++
14
+ def valid?
15
+ return false unless given_signature
16
+ Relax::Query.unescape_value(correct_signature) == given_signature
17
+ end
18
+
19
+ # Returns +true+ if the response returns a successful state.
20
+ def successful?
21
+ [
22
+ Remit::PipelineStatusCode::SUCCESS_ABT,
23
+ Remit::PipelineStatusCode::SUCCESS_ACH,
24
+ Remit::PipelineStatusCode::SUCCESS_CC,
25
+ Remit::PipelineStatusCode::SUCCESS_RECIPIENT_TOKEN_INSTALLED
26
+ ].include?(request_query[:status])
27
+ end
28
+
29
+ def method_missing(method, *args) #:nodoc:
30
+ if request_query.has_key?(method.to_sym)
31
+ request_query[method.to_sym]
32
+ else
33
+ super
34
+ end
35
+ end
36
+
37
+ def request_query(reload = false)
38
+ @query ||= Remit::SignedQuery.parse(@uri, @secret_key, @uri.query || '')
39
+ end
40
+ private :request_query
41
+
42
+ def given_signature
43
+ request_query[:awsSignature]
44
+ end
45
+ private :given_signature
46
+
47
+ def correct_signature
48
+ Remit::SignedQuery.new(@uri.path, @secret_key, request_query).sign
49
+ end
50
+ private :correct_signature
51
+ end
52
+ end
@@ -1,12 +1,12 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/integrations_helper'
2
2
 
3
3
  describe 'a GetAccountActivity call' do
4
- it_should_behave_like 'a successful request'
4
+ it_should_behave_like 'a successful response'
5
5
 
6
6
  before(:all) do
7
- request = Remit::API::GetAccountActivityRequest.new
7
+ request = Remit::GetAccountActivity::Request.new
8
8
  request.start_date = Date.today - 7
9
- @response = @remit.get_account_activity(request)
9
+ @response = remit.get_account_activity(request)
10
10
  end
11
11
 
12
12
  it 'should have a collection of transactions' do
@@ -1,10 +1,10 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/integrations_helper'
2
2
 
3
3
  describe 'a GetTokens call' do
4
- it_should_behave_like 'a successful request'
4
+ it_should_behave_like 'a successful response'
5
5
 
6
6
  before(:all) do
7
- @response = @remit.get_tokens
7
+ @response = remit.get_tokens
8
8
  end
9
9
 
10
10
  it 'should have a collection of tokens' do
@@ -0,0 +1,8 @@
1
+ ACCESS_KEY = ENV['AWS_ACCESS_KEY'] || ENV['AMAZON_ACCESS_KEY_ID']
2
+ SECRET_KEY = ENV['AWS_SECRET_KEY'] || ENV['AMAZON_SECRET_ACCESS_KEY']
3
+
4
+ unless ACCESS_KEY and SECRET_KEY
5
+ raise RuntimeError, "You must set your AWS_ACCESS_KEY and AWS_SECRET_KEY environment variables to run integration tests"
6
+ end
7
+
8
+ require File.dirname(__FILE__) + '/../spec_helper'
data/spec/spec_helper.rb CHANGED
@@ -1,19 +1,15 @@
1
+ require 'rubygems'
1
2
  require 'spec'
2
3
 
3
4
  require File.dirname(__FILE__) + '/../lib/remit'
4
5
 
5
- fail unless ENV.include?('AWS_ACCESS_KEY') and ENV.include?('AWS_SECRET_KEY')
6
-
7
- ACCESS_KEY = ENV['AWS_ACCESS_KEY'] unless defined?(ACCESS_KEY)
8
- SECRET_KEY = ENV['AWS_SECRET_KEY'] unless defined?(SECRET_KEY)
9
-
10
- describe 'a successful request', :shared => true do
11
- before(:all) do
12
- @remit = Remit::API.new(ACCESS_KEY, SECRET_KEY, true)
13
- end
6
+ def remit
7
+ @remit ||= Remit::API.new(ACCESS_KEY, SECRET_KEY, true)
8
+ end
14
9
 
10
+ describe 'a successful response', :shared => true do
15
11
  it 'should return success' do
16
- @response.status.should eql('Success')
12
+ @response.status.should == 'Success'
17
13
  end
18
14
 
19
15
  it 'should not have any errors' do
@@ -24,3 +20,17 @@ describe 'a successful request', :shared => true do
24
20
  @response.request_id.should_not be_nil
25
21
  end
26
22
  end
23
+
24
+ describe 'a failed response', :shared => true do
25
+ it "is not successful" do
26
+ @response.should_not be_successful
27
+ end
28
+
29
+ it "has a request id" do
30
+ @response.request_id.should_not be_empty
31
+ end
32
+
33
+ it "has errors" do
34
+ @response.errors.should_not be_empty
35
+ end
36
+ end
@@ -1,17 +1,15 @@
1
- require File.dirname(__FILE__) + '/spec_helper'
1
+ require File.dirname(__FILE__) + '/units_helper'
2
2
 
3
3
  describe 'A pipeline', :shared => true do
4
4
  before do
5
- @remit = Remit::API.new(ACCESS_KEY, SECRET_KEY, true)
6
-
7
5
  @pipeline_options = {
8
- :return_URL => 'http://example.com/'
6
+ :return_url => 'http://example.com/'
9
7
  }
10
8
  end
11
9
 
12
10
  it 'should sign its URL' do
13
11
  uri = URI.parse(@pipeline.url)
14
- pipeline = Remit::SignedQuery.parse(uri, @remit.secret_key, uri.query)
12
+ pipeline = Remit::SignedQuery.parse(uri, remit.secret_key, uri.query)
15
13
  query = Relax::Query.parse(uri)
16
14
 
17
15
  pipeline[:awsSignature].should == query[:awsSignature]
@@ -25,19 +23,74 @@ describe 'A single-use pipeline' do
25
23
  @pipeline_options.merge!({
26
24
  :transaction_amount => 10,
27
25
  :caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
28
- :recipient_token => 'N5PCME5A5Q6FE2QEB7CD64JLGFTUGXBE61HTCJMGGAK2R5IPEQ8EKIVP3QAVD7JP',
29
- :pipeline_name => Remit::PipelineName::SINGLE_USE
26
+ :recipient_token => 'N5PCME5A5Q6FE2QEB7CD64JLGFTUGXBE61HTCJMGGAK2R5IPEQ8EKIVP3QAVD7JP'
27
+ })
28
+
29
+ @pipeline = remit.get_single_use_pipeline(@pipeline_options)
30
+ end
31
+
32
+ it 'should ignore unused parameters' do
33
+ uri = URI.parse(@pipeline.url)
34
+ query = Relax::Query.parse(uri)
35
+
36
+ query[:paymentReason].should be_nil
37
+ end
38
+
39
+ it 'should have the right name' do
40
+ @pipeline.pipeline_name.should == Remit::PipelineName::SINGLE_USE
41
+ end
42
+ end
43
+
44
+ describe 'A multi-use pipeline' do
45
+ it_should_behave_like 'A pipeline'
46
+
47
+ before do
48
+ @pipeline_options.merge!({
49
+ :transaction_amount => 10,
50
+ :caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
51
+ :recipient_token_list => 'N5PCME5A5Q6FE2QEB7CD64JLGFTUGXBE61HTCJMGGAK2R5IPEQ8EKIVP3QAVD7JP'
30
52
  })
31
53
 
32
- @pipeline = @remit.get_single_use_pipeline(@pipeline_options)
54
+ @pipeline = remit.get_multi_use_pipeline(@pipeline_options)
33
55
  end
34
56
 
35
57
  it 'should ignore unused parameters' do
36
58
  uri = URI.parse(@pipeline.url)
37
59
  query = Relax::Query.parse(uri)
38
-
60
+
39
61
  query[:paymentReason].should be_nil
40
62
  end
63
+
64
+ it 'should have the right name' do
65
+ @pipeline.pipeline_name.should == Remit::PipelineName::MULTI_USE
66
+ end
67
+ end
68
+
69
+ describe 'A recipient pipeline' do
70
+ it_should_behave_like 'A pipeline'
71
+
72
+ before do
73
+ @validity_start = Time.now + (3600 * 24) # 1 day from now
74
+ @validity_expiry = Time.now + (2600 * 24 * 180) # ~6 months from now
75
+
76
+ @pipeline_options.merge!({
77
+ :validity_start => @validity_start,
78
+ :validity_expiry => @validity_expiry,
79
+ :caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
80
+ :max_variable_fee => '0.25',
81
+ :recipient_pays_fee => true
82
+ })
83
+
84
+ @pipeline = remit.get_recipient_pipeline(@pipeline_options)
85
+ end
86
+
87
+ it 'should have the recipient pay marketplace fees' do
88
+ @pipeline.url.should match(/recipientPaysFee=true/)
89
+ end
90
+
91
+ it 'should have the right name' do
92
+ @pipeline.pipeline_name.should == Remit::PipelineName::RECIPIENT
93
+ end
41
94
  end
42
95
 
43
96
  describe 'A recurring-use pipeline' do
@@ -47,9 +100,8 @@ describe 'A recurring-use pipeline' do
47
100
  @validity_start = Time.now + (3600 * 24) # 1 day from now
48
101
  @validity_expiry = Time.now + (3600 * 24 * 180) # ~6 months from now
49
102
  @recurring_period = '1 Month'
50
-
103
+
51
104
  @pipeline_options.merge!({
52
- :pipeline_name => Remit::PipelineName::RECURRING,
53
105
  :validity_start => @validity_start,
54
106
  :validity_expiry => @validity_expiry,
55
107
  :recurring_period => @recurring_period,
@@ -57,50 +109,57 @@ describe 'A recurring-use pipeline' do
57
109
  :caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
58
110
  :recipient_token => 'N5PCME5A5Q6FE2QEB7CD64JLGFTUGXBE61HTCJMGGAK2R5IPEQ8EKIVP3QAVD7JP'
59
111
  })
60
-
61
- @pipeline = @remit.get_recurring_use_pipeline(@pipeline_options)
112
+
113
+ @pipeline = remit.get_recurring_use_pipeline(@pipeline_options)
62
114
  end
63
115
 
64
116
  it 'should convert times to seconds from epoch' do
65
117
  uri = URI.parse(@pipeline.url)
66
118
  query = Relax::Query.parse(uri)
67
-
119
+
68
120
  @validity_start.to_i.to_s.should == query[:validityStart]
69
121
  @validity_expiry.to_i.to_s.should == query[:validityExpiry]
70
122
  end
71
-
123
+
72
124
  it 'should allow time in seconds' do
73
125
  options = @pipeline_options.merge({
74
126
  :validity_start => @validity_start.to_i,
75
127
  :validity_expiry => @validity_expiry.to_i
76
128
  })
77
- @pipeline = @remit.get_recurring_use_pipeline(options)
78
-
129
+ @pipeline = remit.get_recurring_use_pipeline(options)
130
+
79
131
  uri = URI.parse(@pipeline.url)
80
132
  query = Relax::Query.parse(uri)
81
-
133
+
82
134
  @validity_start.to_i.to_s.should == query[:validityStart]
83
135
  @validity_expiry.to_i.to_s.should == query[:validityExpiry]
84
136
  end
137
+
138
+ it 'should have the right name' do
139
+ @pipeline.pipeline_name.should == Remit::PipelineName::RECURRING
140
+ end
85
141
  end
86
142
 
87
143
  describe 'A postpaid pipeline' do
88
144
  it_should_behave_like 'A pipeline'
89
-
145
+
90
146
  before do
91
147
  @credit_limit = 100
92
148
  @global_amount_limit = 100
93
-
149
+
94
150
  @pipeline_options.merge!({
95
- :pipeline_name => Remit::PipelineName::SETUP_POSTPAID,
96
151
  :credit_limit => @credit_limit,
97
152
  :global_amount_limit => @global_amount_limit
98
153
  })
99
-
100
- @pipeline = @remit.get_postpaid_pipeline(@pipeline_options)
154
+
155
+ @pipeline = remit.get_postpaid_pipeline(@pipeline_options)
101
156
  end
102
-
157
+
103
158
  it 'should create a PostpaidPipeline' do
104
159
  @pipeline.class.should == Remit::GetPipeline::PostpaidPipeline
105
160
  end
161
+
162
+ it 'should have the right name' do
163
+ @pipeline.pipeline_name.should == Remit::PipelineName::SETUP_POSTPAID
164
+ end
106
165
  end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the GetResults API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = <<-XML
9
+ <?xml version=\"1.0\"?>
10
+ <ns3:GetResultsResponse xmlns:ns3=\"http://fps.amazonaws.com/doc/2007-01-08/\">
11
+ <TransactionResults>
12
+ <TransactionId>abc123</TransactionId>
13
+ <Operation>Pay</Operation>
14
+ <CallerReference>1827</CallerReference>
15
+ <Status>Success</Status>
16
+ </TransactionResults>
17
+ <NumberPending>1</NumberPending>
18
+ <Status>Success</Status>
19
+ <RequestId>f89727ba-9ff6-4ca8-87a3-0fd6c9de6b95:0</RequestId>
20
+ </ns3:GetResultsResponse>
21
+ XML
22
+
23
+ @response = Remit::GetResults::Response.new(doc)
24
+ end
25
+
26
+ it "has one result" do
27
+ @response.number_pending.should == 1
28
+ @response.transaction_results.size == "1"
29
+ end
30
+
31
+ describe "the result" do
32
+ before do
33
+ @result = @response.transaction_results.first
34
+ end
35
+
36
+ it "references a previous transaction" do
37
+ @result.transaction_id.should == "abc123"
38
+ end
39
+
40
+ it "references a pay transaction" do
41
+ @result.operation_type.should == 'Pay'
42
+ end
43
+
44
+ it "reports the transaction's new status" do
45
+ @result.transaction_status.should == 'Success'
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe 'an IPN request' do
4
+ before(:each) do
5
+ @request_params = {
6
+ "action" => "notice",
7
+ "buyerName" => "Fps Buyer",
8
+ "callerReference" => "4-8-1-3.5",
9
+ "controller" => "amazon_fps/ipn",
10
+ "operation" => "PAY",
11
+ "paymentMethod" => "CC",
12
+ "recipientEmail" => "recipient@email.url",
13
+ "recipientName" => "Fps Business",
14
+ "signature" => "DA7ZbuQaBDt2/+Mty9XweJyqI1E=",
15
+ "status" => "SUCCESS",
16
+ "transactionAmount" => "USD 3.50",
17
+ "transactionDate" => "1224687134",
18
+ "transactionId" => "13KIGL9RC25853BGPPOS2VSKBKF2JERR3HO"
19
+ }
20
+ @request = Remit::IpnRequest.new(@request_params, 'THISISMYTESTKEY')
21
+ end
22
+
23
+ it 'should be a valid request' do
24
+ @request.should be_valid
25
+ end
26
+
27
+ it 'should pass through access to given parameters' do
28
+ @request.status.should == 'SUCCESS'
29
+ @request.operation.should == 'PAY'
30
+ @request.transactionId.should == '13KIGL9RC25853BGPPOS2VSKBKF2JERR3HO'
31
+ end
32
+ end