nimbleshop_splitable 0.0.5 → 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.
@@ -13,7 +13,7 @@ module NimbleshopSplitable
13
13
  end
14
14
 
15
15
  def api_notify_url(request)
16
- Util.localhost2public_url( '/nimbleshop_splitable/splitable/notify', 'http' )
16
+ Nimbleshop::Util.localhost2public_url( '/nimbleshop_splitable/splitable/notify', 'http' )
17
17
  end
18
18
 
19
19
  def create(order, request)
@@ -43,8 +43,8 @@ module NimbleshopSplitable
43
43
  def add_order_data(params, order)
44
44
  params[:total_amount] = order.total_amount_in_cents
45
45
  params[:invoice] = order.number
46
- params[:shipping] = Util.in_cents(ShippingCostCalculator.new(order).shipping_cost)
47
- params[:tax] = Util.in_cents(TaxCalculator.new(order).tax)
46
+ params[:shipping] = Nimbleshop::Util.in_cents(ShippingCostCalculator.new(order).shipping_cost)
47
+ params[:tax] = Nimbleshop::Util.in_cents(TaxCalculator.new(order).tax)
48
48
  params[:description] = 'See Splitable integrates nicely with nimbleShop'
49
49
  end
50
50
 
@@ -0,0 +1,33 @@
1
+ require 'bundler'
2
+ Bundler.setup(:test)
3
+
4
+ ENV["RAILS_ENV"] = "test"
5
+ require File.expand_path("../../../../nimbleshop_core/test/myshop/config/environment.rb", __FILE__)
6
+ require 'rails/test_help'
7
+ require 'active_record/fixtures'
8
+
9
+ require 'factory_girl'
10
+ Dir["#{File.dirname(__FILE__)}/../../../nimbleshop_core/test/factories/**"].each { |f| require File.expand_path(f) }
11
+
12
+ VCR.configure do | c |
13
+ c.ignore_hosts '127.0.0.1', 'localhost'
14
+ c.cassette_library_dir = 'test/vcr_cassettes'
15
+ c.hook_into :webmock # or :fakeweb
16
+ end
17
+
18
+ class ActiveSupport::TestCase
19
+ include FactoryGirl::Syntax::Methods
20
+ self.use_transactional_fixtures = false
21
+ setup do
22
+ DatabaseCleaner.start
23
+ ActiveRecord::Fixtures.create_fixtures("#{File.dirname(__FILE__)}/../../../nimbleshop_core/test/fixtures", ['shops', 'link_groups', 'payment_methods'])
24
+ end
25
+ teardown do
26
+ DatabaseCleaner.clean
27
+ end
28
+
29
+ def playcasette(casette)
30
+ VCR.use_cassette(casette) { yield }
31
+ end
32
+ end
33
+
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class PaymentMethodSplitableTest < ActiveSupport::TestCase
4
+
5
+ test "validations" do
6
+ pm = NimbleshopSplitable::Splitable.new(name: 'Splitable', description: 'this is description')
7
+ refute pm.valid?
8
+ assert_equal ["Api key can't be blank"], pm.errors.full_messages.sort
9
+ end
10
+
11
+ test "should save the record" do
12
+ pm = NimbleshopSplitable::Splitable.new(name: 'Splitable', description: 'this is description')
13
+ pm.api_key = 'FWERSDEED093d'
14
+ assert pm.save
15
+ assert_match /splitable/, pm.permalink
16
+ end
17
+
18
+ end
@@ -0,0 +1,123 @@
1
+ require 'test_helper'
2
+
3
+ module Processor
4
+ class SpllitableCreateTest < ActiveRecord::TestCase
5
+ setup do
6
+ @product = create(:product, price: 10)
7
+ @order = create(:order)
8
+ @request = stub(protocol: 'https', host_with_port: 'localhost:3000' )
9
+ end
10
+
11
+ test "when successful" do
12
+ @order.add(@product)
13
+ processor = NimbleshopSplitable::Processor.new(order: @order)
14
+
15
+ expected = "https://nimbleshop.splitable-draft.com/cws/0a0722b80ce3b662039884060ca49aaa7a1bb4135ea92fa47dc8"
16
+
17
+ playcasette('splitable/split-draft-create-success') do
18
+ error, split_url = processor.create_split(request: @request)
19
+ assert_nil error, "must be have no errors"
20
+ assert_equal expected, split_url
21
+ assert_equal NimbleshopSplitable::Splitable.first, @order.payment_method
22
+ assert @order.pending?
23
+ end
24
+ end
25
+
26
+ test "when failed" do
27
+ processor = NimbleshopSplitable::Processor.new(order: @order)
28
+
29
+ playcasette('splitable/split-draft-create-failure') do
30
+ error, split_url = processor.create_split(request: @request)
31
+ assert_nil split_url, "must not create split url"
32
+ assert_equal "Order must have atleast one line item", error
33
+ end
34
+ end
35
+ end
36
+
37
+ class SpllitablePaidTest < ActiveRecord::TestCase
38
+ def callback_params(order)
39
+ {
40
+ invoice: order.number,
41
+ payment_status: "paid",
42
+ api_secret: "82746e2d66cb8993",
43
+ transaction_id: "852973493383974"
44
+ }
45
+ end
46
+
47
+ setup do
48
+ @product = create(:product, price: 10)
49
+ @order = create(:order)
50
+ end
51
+
52
+ test "when transaction is paid" do
53
+ processor = NimbleshopSplitable::Processor.new(order: @order)
54
+ playcasette('splitable/split-draft-create-success') do
55
+ processor.create_split(request: @request)
56
+ end
57
+
58
+ assert @order.pending?
59
+
60
+ options = callback_params(@order)
61
+ processor = NimbleshopSplitable::Processor.new(invoice: options[:invoice])
62
+
63
+
64
+ processor.acknowledge(options)
65
+ transaction = @order.payment_transactions.last
66
+
67
+ assert_equal 'purchased', transaction.operation
68
+ assert_equal '852973493383974', transaction.transaction_gid
69
+ @order.reload
70
+ assert @order.purchased?
71
+ end
72
+ end
73
+
74
+ class SpllitableVoidTest < ActiveRecord::TestCase
75
+ def callback_params(order)
76
+ {
77
+ invoice: order.number,
78
+ payment_status: "cancelled",
79
+ api_secret: "82746e2d66cb8993",
80
+ transaction_id: "852973493383974"
81
+ }
82
+ end
83
+
84
+ setup do
85
+ @order = create(:order)
86
+ end
87
+
88
+ test "when transaction is cancelled" do
89
+ processor = NimbleshopSplitable::Processor.new(order: @order)
90
+ playcasette('splitable/split-draft-create-success') do
91
+ processor.create_split(request: @request)
92
+ end
93
+
94
+ assert @order.pending?
95
+
96
+ options = callback_params(@order)
97
+ processor = NimbleshopSplitable::Processor.new(invoice: options[:invoice])
98
+ assert processor.acknowledge(options)
99
+ transaction = @order.payment_transactions.last
100
+
101
+ assert_equal 'voided', transaction.operation
102
+ assert_equal '852973493383974', transaction.transaction_gid
103
+ @order.reload
104
+ assert @order.voided?
105
+ end
106
+
107
+ test "when an invalid order number is used" do
108
+ options = callback_params(@order)
109
+ processor = NimbleshopSplitable::Processor.new(invoice: '123')
110
+
111
+ assert_equal false, processor.acknowledge(options)
112
+ assert_equal ["Unknown invoice number"], processor.errors
113
+ end
114
+
115
+ test "when payment_status is blank" do
116
+ options = callback_params(@order).merge(payment_status: nil)
117
+ processor = NimbleshopSplitable::Processor.new(invoice: options[:invoice])
118
+
119
+ assert_equal false, processor.acknowledge(options)
120
+ assert_equal ["Parameter payment_status is blank"], processor.errors
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.splitable.com/api/splits
6
+ body:
7
+ encoding: US-ASCII
8
+ string: total_amount=299.0&invoice=75780588&shipping=299&tax=0&description=See%20Splitable%20integrates%20nicely%20with%20nimbleShop&api_key=edb5fd7b39652986&api_notify_url=http%3A%2F%2Flocalhost%3A3000%2Finstant_payment_notifications%2Fsplitable&expires_in=24
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 500
19
+ message: Internal Server Error
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Wed, 25 Apr 2012 22:51:51 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Connection:
28
+ - keep-alive
29
+ Strict-Transport-Security:
30
+ - max-age=31536000
31
+ Content-Length:
32
+ - "49"
33
+ X-Ua-Compatible:
34
+ - IE=Edge,chrome=1
35
+ Cache-Control:
36
+ - no-cache
37
+ X-Request-Id:
38
+ - 2d1f8525f8e3eaedcd6dac16f19f16a2
39
+ X-Runtime:
40
+ - "0.320299"
41
+ X-Rack-Cache:
42
+ - invalidate, pass
43
+ body:
44
+ encoding: US-ASCII
45
+ string: "{\"error\":\"Order must have atleast one line item\"}"
46
+ http_version:
47
+ recorded_at: Wed, 25 Apr 2012 22:51:51 GMT
48
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.splitable.com/api/splits
6
+ body:
7
+ encoding: US-ASCII
8
+ string: total_amount=1311.0&invoice=27376633&shipping=299&tax=12&description=See%20Splitable%20integrates%20nicely%20with%20nimbleShop&amount_1=1000&item_name_1=name2&quantity_1=1&url_1=httpslocalhost%3A3000%2Fproducts%2Fname2&api_key=edb5fd7b39652986&api_notify_url=http%3A%2F%2Flocalhost%3A3000%2Finstant_payment_notifications%2Fsplitable&expires_in=24
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Wed, 25 Apr 2012 22:51:53 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Connection:
28
+ - keep-alive
29
+ Strict-Transport-Security:
30
+ - max-age=31536000
31
+ Content-Length:
32
+ - "169"
33
+ X-Ua-Compatible:
34
+ - IE=Edge,chrome=1
35
+ Etag:
36
+ - "\"9002b0b48601ba09948887b23138de10\""
37
+ Cache-Control:
38
+ - max-age=0, private, must-revalidate
39
+ X-Request-Id:
40
+ - 6658f59fa8f4c91929427eace17a226a
41
+ X-Runtime:
42
+ - "0.380272"
43
+ X-Rack-Cache:
44
+ - invalidate, pass
45
+ body:
46
+ encoding: US-ASCII
47
+ string: "{\"split_url\":\"https://checkout.splitable.com/cws/d4439197c134c2a2c2c04ab02b8cf57bb93296d6bd6554127dd7\",\"split_id\":\"d4439197c134c2a2c2c04ab02b8cf57bb93296d6bd6554127dd7\"}"
48
+ http_version:
49
+ recorded_at: Wed, 25 Apr 2012 22:51:53 GMT
50
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.splitable-draft.com/api/splits
6
+ body:
7
+ encoding: US-ASCII
8
+ string: total_amount=299.0&invoice=97738347&shipping=299&tax=0&description=See%20Splitable%20integrates%20nicely%20with%20nimbleShop&api_key=92746e4d66cb8993&api_notify_url=http%3A%2F%2Flocalhost%3A3000%2Finstant_payment_notifications%2Fsplitable&expires_in=24
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Fri, 27 Apr 2012 22:01:21 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Connection:
28
+ - keep-alive
29
+ Strict-Transport-Security:
30
+ - max-age=31536000
31
+ Content-Length:
32
+ - "49"
33
+ X-Ua-Compatible:
34
+ - IE=Edge,chrome=1
35
+ Etag:
36
+ - "\"f63fda0da33b7457d6e2f8a6bba02ff6\""
37
+ Cache-Control:
38
+ - max-age=0, private, must-revalidate
39
+ X-Request-Id:
40
+ - c89a8400cde176553933bfd5c81a3ab6
41
+ X-Runtime:
42
+ - "0.178033"
43
+ X-Rack-Cache:
44
+ - invalidate, pass
45
+ body:
46
+ encoding: US-ASCII
47
+ string: "{\"error\":\"Order must have atleast one line item\"}"
48
+ http_version:
49
+ recorded_at: Fri, 27 Apr 2012 22:01:21 GMT
50
+ recorded_with: VCR 2.0.0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://www.splitable-draft.com/api/splits
6
+ body:
7
+ encoding: US-ASCII
8
+ string: total_amount=1311.0&invoice=31347895&shipping=299&tax=12&description=See%20Splitable%20integrates%20nicely%20with%20nimbleShop&amount_1=1000&item_name_1=name2&quantity_1=1&url_1=httpslocalhost%3A3000%2Fproducts%2Fname2&api_key=92746e4d66cb8993&api_notify_url=http%3A%2F%2Flocalhost%3A3000%2Finstant_payment_notifications%2Fsplitable&expires_in=24
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 201
19
+ message: Created
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Fri, 27 Apr 2012 22:01:23 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Connection:
28
+ - keep-alive
29
+ Strict-Transport-Security:
30
+ - max-age=31536000
31
+ Content-Length:
32
+ - "177"
33
+ X-Ua-Compatible:
34
+ - IE=Edge,chrome=1
35
+ Etag:
36
+ - "\"227f59f097dc40ad4b74196ea358ef3e\""
37
+ Cache-Control:
38
+ - max-age=0, private, must-revalidate
39
+ X-Request-Id:
40
+ - 0c1a704a8cc305581901e0a4aeefce6f
41
+ X-Runtime:
42
+ - "0.180585"
43
+ X-Rack-Cache:
44
+ - invalidate, pass
45
+ body:
46
+ encoding: US-ASCII
47
+ string: "{\"split_url\":\"https://nimbleshop.splitable-draft.com/cws/0a0722b80ce3b662039884060ca49aaa7a1bb4135ea92fa47dc8\",\"split_id\":\"0a0722b80ce3b662039884060ca49aaa7a1bb4135ea92fa47dc8\"}"
48
+ http_version:
49
+ recorded_at: Fri, 27 Apr 2012 22:01:23 GMT
50
+ recorded_with: VCR 2.0.0
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nimbleshop_splitable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Neeraj Singh
9
+ - megpha
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-07-13 00:00:00.000000000 Z
13
+ date: 2012-08-10 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: activemerchant
@@ -27,22 +28,6 @@ dependencies:
27
28
  - - ! '>='
28
29
  - !ruby/object:Gem::Version
29
30
  version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: nimbleshop_core
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - '='
36
- - !ruby/object:Gem::Version
37
- version: 0.0.5
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - '='
44
- - !ruby/object:Gem::Version
45
- version: 0.0.5
46
31
  description: Provides Splitable support to nimbleShop
47
32
  email:
48
33
  - neeraj@BigBinary.com
@@ -68,6 +53,13 @@ files:
68
53
  - lib/tasks/mock_callback.rake
69
54
  - lib/tasks/nimbleshop_splitable_tasks.rake
70
55
  - README.md
56
+ - test/test_helper.rb
57
+ - test/unit/payment_method_test.rb
58
+ - test/unit/processor_test.rb
59
+ - test/vcr_cassettes/splitable/split-create-failure.yml
60
+ - test/vcr_cassettes/splitable/split-create-success.yml
61
+ - test/vcr_cassettes/splitable/split-draft-create-failure.yml
62
+ - test/vcr_cassettes/splitable/split-draft-create-success.yml
71
63
  homepage: http://nimbleShop.org
72
64
  licenses: []
73
65
  post_install_message:
@@ -80,16 +72,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
72
  - - ! '>='
81
73
  - !ruby/object:Gem::Version
82
74
  version: '0'
75
+ segments:
76
+ - 0
77
+ hash: -1144356076095736522
83
78
  required_rubygems_version: !ruby/object:Gem::Requirement
84
79
  none: false
85
80
  requirements:
86
81
  - - ! '>='
87
82
  - !ruby/object:Gem::Version
88
83
  version: '0'
84
+ segments:
85
+ - 0
86
+ hash: -1144356076095736522
89
87
  requirements: []
90
88
  rubyforge_project:
91
89
  rubygems_version: 1.8.24
92
90
  signing_key:
93
91
  specification_version: 3
94
92
  summary: Splitable extension for Nimbleshop
95
- test_files: []
93
+ test_files:
94
+ - test/test_helper.rb
95
+ - test/unit/payment_method_test.rb
96
+ - test/unit/processor_test.rb
97
+ - test/vcr_cassettes/splitable/split-create-failure.yml
98
+ - test/vcr_cassettes/splitable/split-create-success.yml
99
+ - test/vcr_cassettes/splitable/split-draft-create-failure.yml
100
+ - test/vcr_cassettes/splitable/split-draft-create-success.yml