remit2 0.0.7

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 (45) hide show
  1. data/LICENSE +20 -0
  2. data/README.markdown +26 -0
  3. data/lib/remit2.rb +119 -0
  4. data/lib/remit2/data_types.rb +142 -0
  5. data/lib/remit2/error_codes.rb +118 -0
  6. data/lib/remit2/get_pipeline.rb +195 -0
  7. data/lib/remit2/ipn_request.rb +45 -0
  8. data/lib/remit2/operations/cancel_subscription_and_refund.rb +26 -0
  9. data/lib/remit2/operations/cancel_token.rb +16 -0
  10. data/lib/remit2/operations/discard_results.rb +16 -0
  11. data/lib/remit2/operations/fund_prepaid.rb +29 -0
  12. data/lib/remit2/operations/get_account_activity.rb +58 -0
  13. data/lib/remit2/operations/get_account_balance.rb +27 -0
  14. data/lib/remit2/operations/get_all_credit_instruments.rb +16 -0
  15. data/lib/remit2/operations/get_all_prepaid_instruments.rb +16 -0
  16. data/lib/remit2/operations/get_debt_balance.rb +21 -0
  17. data/lib/remit2/operations/get_outstanding_debt_balance.rb +20 -0
  18. data/lib/remit2/operations/get_payment_instruction.rb +19 -0
  19. data/lib/remit2/operations/get_prepaid_balance.rb +21 -0
  20. data/lib/remit2/operations/get_results.rb +25 -0
  21. data/lib/remit2/operations/get_token_by_caller.rb +23 -0
  22. data/lib/remit2/operations/get_token_usage.rb +16 -0
  23. data/lib/remit2/operations/get_tokens.rb +18 -0
  24. data/lib/remit2/operations/get_total_prepaid_liability.rb +20 -0
  25. data/lib/remit2/operations/get_transaction.rb +40 -0
  26. data/lib/remit2/operations/install_payment_instruction.rb +20 -0
  27. data/lib/remit2/operations/pay.rb +38 -0
  28. data/lib/remit2/operations/refund.rb +28 -0
  29. data/lib/remit2/operations/reserve.rb +28 -0
  30. data/lib/remit2/operations/retry_transaction.rb +16 -0
  31. data/lib/remit2/operations/settle.rb +18 -0
  32. data/lib/remit2/operations/settle_debt.rb +28 -0
  33. data/lib/remit2/operations/write_off_debt.rb +26 -0
  34. data/lib/remit2/pipeline_response.rb +52 -0
  35. data/lib/remit2/request.rb +12 -0
  36. data/lib/remit2/response.rb +54 -0
  37. data/lib/remit2/signature.rb +35 -0
  38. data/spec/spec_helper.rb +32 -0
  39. data/spec/units/cancel_subscription_and_refund_spec.rb +26 -0
  40. data/spec/units/get_pipeline_spec.rb +164 -0
  41. data/spec/units/ipn_request_spec.rb +35 -0
  42. data/spec/units/pay_spec.rb +67 -0
  43. data/spec/units/remit_spec.rb +25 -0
  44. data/spec/units/units_helper.rb +4 -0
  45. metadata +119 -0
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the CancelSubscriptionAndRefund API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = <<-XML
9
+ <CancelSubscriptionAndRefundResponse xmlns="http://fps.amazonaws.com/doc/2008-09-17/">
10
+ <CancelSubscriptionAndRefundResult>
11
+ <RefundTransactionId>154588GALWND3ML3EJ3NFDZ7SMQZHLMLJZP</RefundTransactionId>
12
+ </CancelSubscriptionAndRefundResult>
13
+ <ResponseMetadata>
14
+ <RequestId>b5d6e665-6343-41db-bac7-17e251f353bf:0</RequestId>
15
+ </ResponseMetadata>
16
+ </CancelSubscriptionAndRefundResponse>
17
+ XML
18
+
19
+ @response = Remit::CancelSubscriptionAndRefund::Response.new(doc)
20
+ end
21
+
22
+ it "has a refund transaction id" do
23
+ @response.refund_transaction_id.should == '154588GALWND3ML3EJ3NFDZ7SMQZHLMLJZP'
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,164 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe 'A pipeline', :shared => true do
4
+ before do
5
+ @pipeline_options = {
6
+ :return_url => 'http://example.com/'
7
+ }
8
+ end
9
+
10
+ it 'should sign its URL' do
11
+ uri = URI.parse(@pipeline.url)
12
+ uri.query.should =~ /signature=/
13
+ uri.query.should =~ /signatureVersion=2/
14
+ uri.query.should =~ /signatureMethod=HmacSHA256/
15
+ end
16
+ end
17
+
18
+ describe 'A single-use pipeline' do
19
+ it_should_behave_like 'A pipeline'
20
+
21
+ before do
22
+ @pipeline_options.merge!({
23
+ :transaction_amount => 10,
24
+ :caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
25
+ :recipient_token => 'N5PCME5A5Q6FE2QEB7CD64JLGFTUGXBE61HTCJMGGAK2R5IPEQ8EKIVP3QAVD7JP'
26
+ })
27
+
28
+ @pipeline = remit.get_single_use_pipeline(@pipeline_options)
29
+ end
30
+
31
+ it 'should ignore unused parameters' do
32
+ uri = URI.parse(@pipeline.url)
33
+ query = Relax::Query.parse(uri)
34
+
35
+ query[:paymentReason].should be_nil
36
+ end
37
+
38
+ it 'should have the right name' do
39
+ @pipeline.pipeline_name.should == Remit::PipelineName::SINGLE_USE
40
+ end
41
+ end
42
+
43
+ describe 'A multi-use pipeline' do
44
+ it_should_behave_like 'A pipeline'
45
+
46
+ before do
47
+ @pipeline_options.merge!({
48
+ :transaction_amount => 10,
49
+ :caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
50
+ :recipient_token_list => 'N5PCME5A5Q6FE2QEB7CD64JLGFTUGXBE61HTCJMGGAK2R5IPEQ8EKIVP3QAVD7JP'
51
+ })
52
+
53
+ @pipeline = remit.get_multi_use_pipeline(@pipeline_options)
54
+ end
55
+
56
+ it 'should ignore unused parameters' do
57
+ uri = URI.parse(@pipeline.url)
58
+ query = Relax::Query.parse(uri)
59
+
60
+ query[:paymentReason].should be_nil
61
+ end
62
+
63
+ it 'should have the right name' do
64
+ @pipeline.pipeline_name.should == Remit::PipelineName::MULTI_USE
65
+ end
66
+ end
67
+
68
+ describe 'A recipient pipeline' do
69
+ it_should_behave_like 'A pipeline'
70
+
71
+ before do
72
+ @validity_start = Time.now + (3600 * 24) # 1 day from now
73
+ @validity_expiry = Time.now + (2600 * 24 * 180) # ~6 months from now
74
+
75
+ @pipeline_options.merge!({
76
+ :validity_start => @validity_start,
77
+ :validity_expiry => @validity_expiry,
78
+ :caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
79
+ :max_variable_fee => '0.25',
80
+ :recipient_pays_fee => true
81
+ })
82
+
83
+ @pipeline = remit.get_recipient_pipeline(@pipeline_options)
84
+ end
85
+
86
+ it 'should have the recipient pay marketplace fees' do
87
+ @pipeline.url.should match(/recipientPaysFee=true/)
88
+ end
89
+
90
+ it 'should have the right name' do
91
+ @pipeline.pipeline_name.should == Remit::PipelineName::RECIPIENT
92
+ end
93
+ end
94
+
95
+ describe 'A recurring-use pipeline' do
96
+ it_should_behave_like 'A pipeline'
97
+
98
+ before do
99
+ @validity_start = Time.now + (3600 * 24) # 1 day from now
100
+ @validity_expiry = Time.now + (3600 * 24 * 180) # ~6 months from now
101
+ @recurring_period = '1 Month'
102
+
103
+ @pipeline_options.merge!({
104
+ :validity_start => @validity_start,
105
+ :validity_expiry => @validity_expiry,
106
+ :recurring_period => @recurring_period,
107
+ :transaction_amount => 10,
108
+ :caller_reference => 'N2PCBEIA5864E27EL7C86PJL1FGUGPBL61QTJJM5GQK265SPEN8ZKIJPMQARDVJK',
109
+ :recipient_token => 'N5PCME5A5Q6FE2QEB7CD64JLGFTUGXBE61HTCJMGGAK2R5IPEQ8EKIVP3QAVD7JP'
110
+ })
111
+
112
+ @pipeline = remit.get_recurring_use_pipeline(@pipeline_options)
113
+ end
114
+
115
+ it 'should convert times to seconds from epoch' do
116
+ uri = URI.parse(@pipeline.url)
117
+ query = Relax::Query.parse(uri)
118
+
119
+ @validity_start.to_i.to_s.should == query[:validityStart]
120
+ @validity_expiry.to_i.to_s.should == query[:validityExpiry]
121
+ end
122
+
123
+ it 'should allow time in seconds' do
124
+ options = @pipeline_options.merge({
125
+ :validity_start => @validity_start.to_i,
126
+ :validity_expiry => @validity_expiry.to_i
127
+ })
128
+ @pipeline = remit.get_recurring_use_pipeline(options)
129
+
130
+ uri = URI.parse(@pipeline.url)
131
+ query = Relax::Query.parse(uri)
132
+
133
+ @validity_start.to_i.to_s.should == query[:validityStart]
134
+ @validity_expiry.to_i.to_s.should == query[:validityExpiry]
135
+ end
136
+
137
+ it 'should have the right name' do
138
+ @pipeline.pipeline_name.should == Remit::PipelineName::RECURRING
139
+ end
140
+ end
141
+
142
+ describe 'A postpaid pipeline' do
143
+ it_should_behave_like 'A pipeline'
144
+
145
+ before do
146
+ @credit_limit = 100
147
+ @global_amount_limit = 100
148
+
149
+ @pipeline_options.merge!({
150
+ :credit_limit => @credit_limit,
151
+ :global_amount_limit => @global_amount_limit
152
+ })
153
+
154
+ @pipeline = remit.get_postpaid_pipeline(@pipeline_options)
155
+ end
156
+
157
+ it 'should create a PostpaidPipeline' do
158
+ @pipeline.class.should == Remit::GetPipeline::PostpaidPipeline
159
+ end
160
+
161
+ it 'should have the right name' do
162
+ @pipeline.pipeline_name.should == Remit::PipelineName::SETUP_POSTPAID
163
+ end
164
+ end
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe 'an IPN request' do
4
+ before(:each) do
5
+ @request_params = {
6
+ "statusMessage"=>"The transaction was successful and the payment instrument was charged.",
7
+ "buyerName"=>"Some Buyer",
8
+ "paymentReason"=>"My Reason",
9
+ "callerReference"=>"asdf1234",
10
+ "transactionDate"=>"1275778668",
11
+ "transactionAmount"=>"USD 4.00",
12
+ "signature"=>"iQDcQv0lnyFet2shDSVtk8VZB7c=",
13
+ "recipientName"=>"John Doe",
14
+ "transactionId"=>"13KIGL9RC25853BGPPOS2VSKBKF2JERR3HO",
15
+ "recipientEmail"=>"me@example.com",
16
+ "notificationType"=>"TransactionStatus",
17
+ "transactionStatus"=>"SUCCESS",
18
+ "operation"=>"PAY",
19
+ "paymentMethod"=>"CC",
20
+ "statusCode"=>"Success"
21
+ }
22
+
23
+ @request = Remit::IpnRequest.new(@request_params, 'THISISMYTESTKEY')
24
+ end
25
+
26
+ it 'should be a valid request' do
27
+ @request.should be_valid
28
+ end
29
+
30
+ it 'should pass through access to given parameters' do
31
+ @request.transactionStatus.should == 'SUCCESS'
32
+ @request.operation.should == 'PAY'
33
+ @request.transactionId.should == '13KIGL9RC25853BGPPOS2VSKBKF2JERR3HO'
34
+ end
35
+ end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the Pay API" do
4
+ describe "a successful response" do
5
+ it_should_behave_like 'a successful response'
6
+
7
+ before do
8
+ doc = <<-XML
9
+ <PayResponse xmlns="http://fps.amazonaws.com/doc/2008-09-17/">
10
+ <PayResult>
11
+ <TransactionId>154588GALWND3ML3EJ3NFDZ7SMQZHLMLJZP</TransactionId>
12
+ <TransactionStatus>Pending</TransactionStatus>
13
+ </PayResult>
14
+ <ResponseMetadata>
15
+ <RequestId>b5d6e665-6343-41db-bac7-17e251f353bf:0</RequestId>
16
+ </ResponseMetadata>
17
+ </PayResponse>
18
+ XML
19
+
20
+ @response = Remit::Pay::Response.new(doc)
21
+ end
22
+
23
+ it "has a transaction id" do
24
+ @response.transaction_id.should == '154588GALWND3ML3EJ3NFDZ7SMQZHLMLJZP'
25
+ end
26
+
27
+ it "has a transaction status" do
28
+ @response.transaction_status.should == 'Pending'
29
+ end
30
+
31
+ it "has inner shortcuts" do
32
+ @response.inner.should_not be_nil
33
+ end
34
+ end
35
+
36
+ describe "for a failed request" do
37
+ describe "InvalidRequest" do
38
+ it_should_behave_like 'a failed response'
39
+
40
+ before do
41
+ doc = <<-XML
42
+ <?xml version="1.0"?>
43
+ <Response>
44
+ <Errors>
45
+ <Error>
46
+ <Code>InvalidRequest</Code>
47
+ <Message>The request doesn't conform to the interface specification in the WSDL. Element/Parameter "http://fps.amazonaws.com/doc/2008-09-17/:TemporaryDeclinePolicy" in request is either invalid or is found at unexpected location</Message>
48
+ </Error>
49
+ </Errors>
50
+ <RequestID>b643bbc6-d5cd-46b4-9c02-4203a52a9b49</RequestID>
51
+ </Response>
52
+ XML
53
+
54
+ @response = Remit::Pay::Response.new(doc)
55
+ @error = @response.errors.first
56
+ end
57
+
58
+ it "should have an error code of 'InvalidRequest'" do
59
+ @error.code.should == 'InvalidRequest'
60
+ end
61
+
62
+ it "should have a message" do
63
+ @error.message.should == "The request doesn't conform to the interface specification in the WSDL. Element/Parameter \"http://fps.amazonaws.com/doc/2008-09-17/:TemporaryDeclinePolicy\" in request is either invalid or is found at unexpected location"
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/units_helper'
2
+
3
+ describe "the Remit API" do
4
+ describe "a request" do
5
+ before(:each) do
6
+ @api = Remit::API.new(ACCESS_KEY, SECRET_KEY, true)
7
+
8
+ # Generate a sample request
9
+ @request = Remit::Pay::Request.new(
10
+ :caller_reference => "ref",
11
+ :sender_token_id => "sender-token",
12
+ :transaction_amount => Remit::RequestTypes::Amount.new(:currency_code => "US", :value => "10")
13
+ )
14
+ end
15
+
16
+ it "should calculate correct string to sign" do
17
+ signature = /GET\nfps.sandbox.amazonaws.com\n\/\nAWSAccessKeyId=foo&Action=Pay&CallerReference=ref&SenderTokenId=sender-token&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=(.*)&TransactionAmount.CurrencyCode=US&TransactionAmount.Value=10&Version=2008-09-17/
18
+
19
+ q = @api.query(@request)
20
+ s = @api.string_to_sign("https://fps.sandbox.amazonaws.com/", "GET", q)
21
+ s.to_s.should =~ signature
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,4 @@
1
+ ACCESS_KEY = 'foo'
2
+ SECRET_KEY = 'bar'
3
+
4
+ require File.dirname(__FILE__) + '/../spec_helper'
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remit2
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 7
9
+ version: 0.0.7
10
+ platform: ruby
11
+ authors:
12
+ - Micah Wedemeyer
13
+ - Tyler Hunt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-06 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: relax
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 0
31
+ - 7
32
+ version: 0.0.7
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description:
36
+ email: micah@peachshake.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.markdown
44
+ files:
45
+ - lib/remit2.rb
46
+ - lib/remit2/data_types.rb
47
+ - lib/remit2/error_codes.rb
48
+ - lib/remit2/get_pipeline.rb
49
+ - lib/remit2/ipn_request.rb
50
+ - lib/remit2/operations/cancel_subscription_and_refund.rb
51
+ - lib/remit2/operations/cancel_token.rb
52
+ - lib/remit2/operations/discard_results.rb
53
+ - lib/remit2/operations/fund_prepaid.rb
54
+ - lib/remit2/operations/get_account_activity.rb
55
+ - lib/remit2/operations/get_account_balance.rb
56
+ - lib/remit2/operations/get_all_credit_instruments.rb
57
+ - lib/remit2/operations/get_all_prepaid_instruments.rb
58
+ - lib/remit2/operations/get_debt_balance.rb
59
+ - lib/remit2/operations/get_outstanding_debt_balance.rb
60
+ - lib/remit2/operations/get_payment_instruction.rb
61
+ - lib/remit2/operations/get_prepaid_balance.rb
62
+ - lib/remit2/operations/get_results.rb
63
+ - lib/remit2/operations/get_token_by_caller.rb
64
+ - lib/remit2/operations/get_token_usage.rb
65
+ - lib/remit2/operations/get_tokens.rb
66
+ - lib/remit2/operations/get_total_prepaid_liability.rb
67
+ - lib/remit2/operations/get_transaction.rb
68
+ - lib/remit2/operations/install_payment_instruction.rb
69
+ - lib/remit2/operations/pay.rb
70
+ - lib/remit2/operations/refund.rb
71
+ - lib/remit2/operations/reserve.rb
72
+ - lib/remit2/operations/retry_transaction.rb
73
+ - lib/remit2/operations/settle.rb
74
+ - lib/remit2/operations/settle_debt.rb
75
+ - lib/remit2/operations/write_off_debt.rb
76
+ - lib/remit2/pipeline_response.rb
77
+ - lib/remit2/request.rb
78
+ - lib/remit2/response.rb
79
+ - lib/remit2/signature.rb
80
+ - LICENSE
81
+ - README.markdown
82
+ has_rdoc: true
83
+ homepage: http://github.com/micahwedemeyer/remit2
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options:
88
+ - --charset=UTF-8
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project: remit2
108
+ rubygems_version: 1.3.6
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: An API for using the Amazon Flexible Payment Service (FPS) - updated for version 2008-09-17 of the API.
112
+ test_files:
113
+ - spec/units/cancel_subscription_and_refund_spec.rb
114
+ - spec/units/get_pipeline_spec.rb
115
+ - spec/units/ipn_request_spec.rb
116
+ - spec/units/pay_spec.rb
117
+ - spec/units/remit_spec.rb
118
+ - spec/spec_helper.rb
119
+ - spec/units/units_helper.rb