killbill-invoice-test 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82d0509829e577cbfbd6c4401e163dff33bf1e17
4
- data.tar.gz: b6301771772e158094e2dd8ac59a58c0e962a8ca
3
+ metadata.gz: 69342817536c8fa5f97ca6ad306b9647fd6d8e73
4
+ data.tar.gz: c1237c86065acf28c511399965d5df9fc4dcad15
5
5
  SHA512:
6
- metadata.gz: b7ab718467e72483c7bfacc4738d8a29b534399145b6deebfe70e5c7909b20869a2e66b983a076241883de7e209dc4978e1605034d7b77cab510a396fbe18990
7
- data.tar.gz: 082962826a8c3a170ea286bf119dda3c4d06cba43b420a0a18a1cd431e6f132f8943dab2cfa109b42427a24aded00d23dc2b0fb1980947115425cd1b320d128c
6
+ metadata.gz: 9c29537778615c408665592664596e29e1b27e07fd74767335667df5ac7aa19d74f6a00e232c298d8a6f2d5351e7ab153be4b48cd734eb14708c0441a2ec21cd
7
+ data.tar.gz: d772ecb21c95d3f6acad82dfa7c22e187dc79048ae6a92d21b2276487d2c580722dbe03cb108ffff5ee543195a0bc141c37b9aaf17a4df38a0433ad1284641d1
data/.gitignore CHANGED
@@ -1,8 +1,8 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.swp
3
4
  .bundle
4
5
  .config
5
- .idea
6
6
  coverage
7
7
  InstalledFiles
8
8
  lib/bundler/man
@@ -12,17 +12,22 @@ spec/reports
12
12
  test/tmp
13
13
  test/version_tmp
14
14
  tmp
15
- build
15
+
16
16
  # YARD artifacts
17
17
  .yardoc
18
18
  _yardoc
19
19
  doc/
20
20
 
21
21
  .jbundler
22
- Jarfile.lock
23
- Gemfile.lock
24
- *.swp
25
- killbill-invoice-test
26
22
 
27
23
  .DS_Store
24
+
25
+ # Testing database
26
+ test.db
27
+
28
+ target
28
29
  pom.xml.asc
30
+
31
+ .idea/
32
+
33
+ Gemfile.head.lock
data/.travis.yml CHANGED
@@ -1,19 +1,41 @@
1
1
  language: ruby
2
2
 
3
+ sudo: false
4
+ cache: bundler
5
+
6
+ before_script:
7
+ - bundle exec jbundle install
8
+
9
+ script: 'bundle exec rake spec'
10
+
3
11
  notifications:
4
12
  email:
5
13
  - kill-bill-commits@googlegroups.com
6
14
 
15
+ env:
16
+ global:
17
+ - JRUBY_OPTS='-J-Xmx1024M'
18
+
7
19
  rvm:
8
- - jruby-19mode
9
- - jruby-20mode
20
+ - jruby-1.7.20
21
+ - jruby-20mode # latest 1.7.x
10
22
  - jruby-head
11
23
 
24
+ gemfile:
25
+ - Gemfile
26
+ - Gemfile.head
27
+
12
28
  jdk:
13
- - openjdk6
14
29
  - openjdk7
15
30
  - oraclejdk7
31
+ - oraclejdk8
16
32
 
17
33
  matrix:
18
34
  allow_failures:
19
35
  - rvm: jruby-head
36
+ - jdk: oraclejdk8
37
+ - gemfile: Gemfile.head
38
+ fast_finish: true
39
+
40
+ after_success:
41
+ - '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && echo "<settings><servers><server><id>sonatype-nexus-snapshots</id><username>\${env.OSSRH_USER}</username><password>\${env.OSSRH_PASS}</password></server></servers></settings>" > ~/settings.xml && MVN="mvn --settings $HOME/settings.xml" NO_RELEASE=1 travis_retry travis_wait bash release.sh | egrep -v "Download|Install|Upload" ; rm -f ~/settings.xml'
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
-
5
- #gem 'killbill', :path => '../killbill-plugin-framework-ruby'
data/Gemfile.lock ADDED
@@ -0,0 +1,78 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ killbill-invoice-test (0.1.0)
5
+ killbill (~> 7.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ axiom-types (0.1.1)
11
+ descendants_tracker (~> 0.0.4)
12
+ ice_nine (~> 0.11.0)
13
+ thread_safe (~> 0.3, >= 0.3.1)
14
+ coercible (1.0.0)
15
+ descendants_tracker (~> 0.0.1)
16
+ descendants_tracker (0.0.4)
17
+ thread_safe (~> 0.3, >= 0.3.1)
18
+ diff-lcs (1.1.3)
19
+ equalizer (0.0.11)
20
+ ethon (0.8.0)
21
+ ffi (>= 1.3.0)
22
+ ffi (1.9.10-java)
23
+ ice_nine (0.11.1)
24
+ jar-dependencies (0.3.1)
25
+ jbundler (0.9.2)
26
+ bundler (~> 1.5)
27
+ jar-dependencies (~> 0.2)
28
+ maven-tools (~> 1.0.10)
29
+ ruby-maven (~> 3.3, >= 3.3.3)
30
+ killbill (7.0.0)
31
+ rack (>= 1.5.2)
32
+ sinatra (~> 1.3.4)
33
+ typhoeus (~> 0.6.9)
34
+ tzinfo (~> 1.2.0)
35
+ maven-tools (1.0.13)
36
+ virtus (~> 1.0)
37
+ rack (1.6.4)
38
+ rack-protection (1.5.3)
39
+ rack
40
+ rake (10.4.2)
41
+ rspec (2.12.0)
42
+ rspec-core (~> 2.12.0)
43
+ rspec-expectations (~> 2.12.0)
44
+ rspec-mocks (~> 2.12.0)
45
+ rspec-core (2.12.2)
46
+ rspec-expectations (2.12.1)
47
+ diff-lcs (~> 1.1.3)
48
+ rspec-mocks (2.12.2)
49
+ ruby-maven (3.3.8)
50
+ ruby-maven-libs (~> 3.3.1)
51
+ ruby-maven-libs (3.3.3)
52
+ sinatra (1.3.6)
53
+ rack (~> 1.4)
54
+ rack-protection (~> 1.3)
55
+ tilt (~> 1.3, >= 1.3.3)
56
+ thread_safe (0.3.5-java)
57
+ tilt (1.4.1)
58
+ typhoeus (0.6.9)
59
+ ethon (>= 0.7.1)
60
+ tzinfo (1.2.2)
61
+ thread_safe (~> 0.1)
62
+ virtus (1.0.5)
63
+ axiom-types (~> 0.1)
64
+ coercible (~> 1.0)
65
+ descendants_tracker (~> 0.0, >= 0.0.3)
66
+ equalizer (~> 0.0, >= 0.0.9)
67
+
68
+ PLATFORMS
69
+ java
70
+
71
+ DEPENDENCIES
72
+ jbundler (~> 0.9.2)
73
+ killbill-invoice-test!
74
+ rake (>= 10.0.0)
75
+ rspec (~> 2.12.0)
76
+
77
+ BUNDLED WITH
78
+ 1.10.6
data/Jarfile CHANGED
@@ -1,8 +1,11 @@
1
- jar 'org.kill-bill.billing:killbill-api', '0.10.3'
2
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-notification', '0.8.2'
3
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-payment', '0.8.2'
4
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-currency', '0.8.2'
5
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-retry', '0.8.1'
6
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-invoice', '0.8.2'
7
- jar 'org.kill-bill.billing:killbill-util:tests', '0.12.1'
8
- jar 'javax.servlet:javax.servlet-api', '3.0.1'
1
+ jar 'org.kill-bill.billing:killbill-api', '0.32'
2
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-currency', '0.18'
3
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-invoice', '0.18'
4
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-notification', '0.18'
5
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-payment', '0.18'
6
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-control', '0.18'
7
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-catalog', '0.18'
8
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-entitlement', '0.18'
9
+ jar 'org.kill-bill.billing:killbill-util:tests', '0.15.10'
10
+ jar 'org.mockito:mockito-all', '1.10.19'
11
+ jar 'javax.servlet:javax.servlet-api', '3.1.0'
data/Jarfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ ---
2
+ :runtime:
3
+ - io.dropwizard.metrics:metrics-core:jar:3.1.1
4
+ - org.kill-bill.billing.plugin:killbill-plugin-api-catalog:jar:0.18
5
+ - com.fasterxml.jackson.core:jackson-core:jar:2.4.3
6
+ - joda-time:joda-time:jar:2.3
7
+ - org.weakref:jmxutils:jar:1.18
8
+ - org.kill-bill.billing.plugin:killbill-plugin-api-notification:jar:0.18
9
+ - commons-beanutils:commons-beanutils:jar:1.8.3
10
+ - org.kill-bill.billing:killbill-internal-api:jar:0.15.10
11
+ - org.kill-bill.commons:killbill-xmlloader:jar:0.11
12
+ - org.kill-bill.billing.plugin:killbill-plugin-api-entitlement:jar:0.18
13
+ - com.google.inject:guice:jar:3.0
14
+ - org.osgi:org.osgi.core:jar:5.0.0
15
+ - org.slf4j:slf4j-api:jar:1.7.12
16
+ - com.samskivert:jmustache:jar:1.5
17
+ - org.kill-bill.billing:killbill-util:jar:tests:0.15.10
18
+ - org.kill-bill.billing.plugin:killbill-plugin-api-currency:jar:0.18
19
+ - org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4:jar:1.16
20
+ - com.h2database:h2:jar:1.4.186
21
+ - javax.activation:activation:jar:1.1
22
+ - org.skife.config:config-magic:jar:0.14
23
+ - com.fasterxml.jackson.dataformat:jackson-dataformat-csv:jar:2.4.3
24
+ - org.kill-bill.billing.plugin:killbill-plugin-api-control:jar:0.18
25
+ - org.apache.commons:commons-email:jar:1.2
26
+ - org.mockito:mockito-all:jar:1.10.19
27
+ - antlr:antlr:jar:2.7.7
28
+ - aopalliance:aopalliance:jar:1.0
29
+ - com.fasterxml.jackson.core:jackson-annotations:jar:2.4.3
30
+ - org.antlr:stringtemplate:jar:3.2.1
31
+ - org.kill-bill.commons:killbill-clock:jar:0.11
32
+ - javax.mail:mail:jar:1.4.1
33
+ - org.kill-bill.billing:killbill-platform-base:jar:0.15
34
+ - io.dropwizard.metrics:metrics-ehcache:jar:3.1.1
35
+ - org.slf4j:jcl-over-slf4j:jar:1.7.12
36
+ - org.jdbi:jdbi:jar:2.62
37
+ - org.kill-bill.billing:killbill-platform-api:jar:0.15
38
+ - org.kill-bill.billing:killbill-platform-osgi:jar:0.15
39
+ - org.apache.felix:org.apache.felix.framework:jar:4.4.1
40
+ - org.joda:joda-money:jar:0.9
41
+ - org.kill-bill.commons:killbill-jdbi:jar:0.11
42
+ - org.kill-bill.commons:killbill-embeddeddb-common:jar:0.11
43
+ - org.apache.shiro:shiro-core:jar:1.2.3
44
+ - org.kill-bill.billing:killbill-platform-osgi-api:jar:0.15
45
+ - org.kill-bill.billing.plugin:killbill-plugin-api-payment:jar:0.18
46
+ - com.fasterxml.jackson.core:jackson-databind:jar:2.4.3
47
+ - com.google.guava:guava:jar:r09
48
+ - org.kill-bill.commons:killbill-locker:jar:0.11
49
+ - org.osgi:org.osgi.compendium:jar:5.0.0
50
+ - org.kill-bill.commons:killbill-queue:jar:0.11
51
+ - org.kill-bill.commons:killbill-concurrent:jar:0.11
52
+ - javax.servlet:javax.servlet-api:jar:3.1.0
53
+ - org.apache.shiro:shiro-ehcache:jar:1.2.3
54
+ - javax.inject:javax.inject:jar:1
55
+ - com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.3
56
+ - com.google.inject.extensions:guice-multibindings:jar:3.0
57
+ - net.sf.ehcache:ehcache:jar:2.9.1
58
+ - org.kill-bill.billing.plugin:killbill-plugin-api-invoice:jar:0.18
59
+ - org.kill-bill.billing:killbill-api:jar:0.32
60
+ - org.apache.shiro:shiro-guice:jar:1.2.3
61
+ - com.google.code.findbugs:annotations:jar:3.0.0
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  killbill-invoice-test-plugin
2
- ==============================
2
+ ============================
3
3
 
4
4
  Plugin to test the Kill Bill InvoicePlugin API.
5
5
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -22,9 +22,9 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.rdoc_options << '--exclude' << '.'
24
24
 
25
- s.add_dependency 'killbill', '~> 3.2.2'
25
+ s.add_dependency 'killbill', '~> 7.0'
26
26
 
27
- s.add_development_dependency 'jbundler', '~> 0.4.1'
27
+ s.add_development_dependency 'jbundler', '~> 0.9.2'
28
28
  s.add_development_dependency 'rake', '>= 10.0.0'
29
29
  s.add_development_dependency 'rspec', '~> 2.12.0'
30
30
  end
@@ -2,13 +2,102 @@ module InvoiceTest
2
2
 
3
3
  class InvoicePlugin < Killbill::Plugin::Invoice
4
4
 
5
- def get_additional_invoice_items(invoice, properties, context)
6
- additional_items = []
7
- invoice.invoice_items.each do |original_item|
8
- additional_items << build_item(original_item, original_item.amount * 7 / 100, 'Tax item', :TAX) unless original_item.amount == 0
5
+ # This implementation is idempotent, will apply tax on old invoices if needed
6
+ # and automatically handle adjustments
7
+ def get_additional_invoice_items(new_invoice, properties, context)
8
+ all_invoices = @kb_apis.invoice_user_api.get_invoices_by_account(new_invoice.account_id, context)
9
+ # Workaround for https://github.com/killbill/killbill/issues/265
10
+ all_invoices << new_invoice unless all_invoices.find { |inv| inv.id == new_invoice.id }
11
+
12
+ existing_taxable_items = []
13
+ existing_tax_items = {}
14
+ existing_adjustment_items = {}
15
+ all_invoices.each do |invoice|
16
+ invoice.invoice_items.each do |invoice_item|
17
+ existing_taxable_items << invoice_item if is_taxable_item(invoice_item)
18
+ (existing_tax_items[invoice_item.linked_item_id] ||= []) << invoice_item if is_tax_item(invoice_item)
19
+ (existing_adjustment_items[invoice_item.linked_item_id] ||= []) << invoice_item if is_adjustment_item(invoice_item)
20
+ end
9
21
  end
10
22
 
23
+ compute_tax_for_items(new_invoice, existing_taxable_items, existing_tax_items, existing_adjustment_items)
24
+ end
25
+
26
+ private
27
+
28
+ def compute_tax_for_items(current_invoice, taxable_items, tax_items, adjustment_items)
29
+ additional_items = taxable_items.map { |taxable_item| compute_tax_for_item(current_invoice, taxable_item, tax_items[taxable_item.id] || [], adjustment_items) }
30
+ additional_items.compact!
31
+
32
+ # Add all new items on the latest invoice
33
+ additional_items.map { |ii| ii.invoice_id = current_invoice.id }
34
+
11
35
  additional_items
12
36
  end
37
+
38
+ def compute_tax_for_item(current_invoice, taxable_item, tax_items, adjustment_items)
39
+ current_tax_amount = tax_items.inject(0) { |sum, tax_item| sum + net_amount(tax_item, adjustment_items) }
40
+ expected_tax_amount = compute_tax_amount(net_amount(taxable_item, adjustment_items))
41
+
42
+ build_missing_item(current_invoice, current_tax_amount, expected_tax_amount, taxable_item, tax_items, adjustment_items)
43
+ end
44
+
45
+ def build_missing_item(current_invoice, current_tax_amount, expected_tax_amount, taxable_item, tax_items, adjustment_items)
46
+ if current_tax_amount < expected_tax_amount
47
+ # Add missing TAX item
48
+ build_tax_item(taxable_item, expected_tax_amount - current_tax_amount)
49
+ elsif current_tax_amount > expected_tax_amount
50
+ # Item adjust the TAX item
51
+ adjustment_amount = current_tax_amount - expected_tax_amount
52
+ tax_item_to_adjust = find_tax_item_to_adjust(tax_items, adjustment_items, adjustment_amount)
53
+ build_adjustment_item(current_invoice, tax_item_to_adjust, adjustment_amount)
54
+ else
55
+ # Nothing to do
56
+ nil
57
+ end
58
+ end
59
+
60
+ def build_tax_item(original_item, amount)
61
+ rounded_amount = amount.round(2)
62
+ return nil if rounded_amount == 0
63
+ build_item(original_item, rounded_amount, 'Tax item', :TAX)
64
+ end
65
+
66
+ def build_adjustment_item(current_invoice, item_to_adjust, amount)
67
+ rounded_amount = amount.round(2)
68
+ return nil if rounded_amount == 0
69
+ item = build_item(item_to_adjust, -rounded_amount, 'Tax item', :ITEM_ADJ)
70
+ item.start_date = current_invoice.invoice_date
71
+ item.end_date = nil
72
+ item
73
+ end
74
+
75
+ def compute_tax_amount(net_taxable_amount)
76
+ net_taxable_amount * 7.0 / 100
77
+ end
78
+
79
+ def find_tax_item_to_adjust(tax_items, adjustment_items, amount_to_adjust)
80
+ tax_items.find { |tax_item| net_amount(tax_item, adjustment_items) >= amount_to_adjust }
81
+ end
82
+
83
+ def net_amount(invoice_item, adjustment_items)
84
+ invoice_item.amount + sum(adjustment_items[invoice_item.id])
85
+ end
86
+
87
+ def sum(invoice_items)
88
+ (invoice_items || []).inject(0) { |sum, ii| sum + ii.amount }
89
+ end
90
+
91
+ def is_taxable_item(invoice_item)
92
+ invoice_item.amount > 0 and [:EXTERNAL_CHARGE, :FIXED, :RECURRING, :USAGE].include?(invoice_item.invoice_item_type)
93
+ end
94
+
95
+ def is_tax_item(invoice_item)
96
+ invoice_item.invoice_item_type == :TAX
97
+ end
98
+
99
+ def is_adjustment_item(invoice_item)
100
+ [:ITEM_ADJ, :REPAIR_ADJ].include?(invoice_item.invoice_item_type)
101
+ end
13
102
  end
14
103
  end
data/pom.xml CHANGED
@@ -27,7 +27,7 @@
27
27
  <groupId>org.kill-bill.billing.plugin.ruby</groupId>
28
28
  <artifactId>invoice-test-plugin</artifactId>
29
29
  <packaging>pom</packaging>
30
- <version>0.0.1</version>
30
+ <version>0.1.0</version>
31
31
  <name>invoice-test-plugin</name>
32
32
  <description></description>
33
33
  <scm>
data/release.sh CHANGED
@@ -1,41 +1,61 @@
1
1
  set -e
2
2
 
3
- if [ "GNU" != "$(tar --help | grep GNU | head -1 | awk '{print $1}')" ]; then
4
- echo "Unable to release: make sure to use GNU tar"
3
+ BUNDLE=${BUNDLE-"bundle exec"}
4
+ MVN=${MVN-"mvn"}
5
+
6
+ if [ 'GNU' != "$(tar --help | grep GNU | head -1 | awk '{print $1}')" ]; then
7
+ echo 'Unable to release: make sure to use GNU tar'
5
8
  exit 1
6
9
  fi
7
10
 
8
11
  if $(ruby -e'require "java"'); then
9
12
  # Good
10
- echo "Detected JRuby"
13
+ echo 'Detected JRuby'
11
14
  else
12
- echo "Unable to release: make sure to use JRuby"
15
+ echo 'Unable to release: make sure to use JRuby'
13
16
  exit 1
14
17
  fi
15
18
 
16
19
  VERSION=`grep -E '<version>([0-9]+\.[0-9]+\.[0-9]+)</version>' pom.xml | sed 's/[\t \n]*<version>\(.*\)<\/version>[\t \n]*/\1/'`
17
- if [ "$VERSION" != "$(cat $PWD/VERSION)" ]; then
18
- echo "Unable to release: make sure the versions in pom.xml and VERSION match"
20
+ if [[ -z "$NO_RELEASE" && "$VERSION" != "$(cat $PWD/VERSION)" ]]; then
21
+ echo 'Unable to release: make sure the versions in pom.xml and VERSION match'
19
22
  exit 1
20
23
  fi
21
24
 
22
- echo "Cleaning up"
23
- rake killbill:clean ; rake build
25
+ echo 'Cleaning up'
26
+ $BUNDLE rake killbill:clean
27
+
28
+ echo 'Building gem'
29
+ $BUNDLE rake build
24
30
 
25
- echo "Pushing the gem to Rubygems"
26
- rake release
31
+ if [[ -z "$NO_RELEASE" ]]; then
32
+ echo 'Pushing the gem to Rubygems'
33
+ $BUNDLE rake release
34
+ fi
27
35
 
28
- echo "Building artifact"
29
- rake killbill:package
36
+ echo 'Building artifact'
37
+ $BUNDLE rake killbill:package
30
38
 
31
39
  ARTIFACT="$PWD/pkg/killbill-invoice-test-$VERSION.tar.gz"
32
40
  echo "Pushing $ARTIFACT to Maven Central"
33
- mvn gpg:sign-and-deploy-file \
34
- -DgroupId=org.kill-bill.billing.plugin.ruby \
35
- -DartifactId=invoice-test-plugin \
36
- -Dversion=$VERSION \
37
- -Dpackaging=tar.gz \
38
- -DrepositoryId=ossrh-releases \
39
- -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ \
40
- -Dfile=$ARTIFACT \
41
- -DpomFile=pom.xml
41
+
42
+ if [[ -z "$NO_RELEASE" ]]; then
43
+ GOAL=gpg:sign-and-deploy-file
44
+ REPOSITORY_ID=ossrh-releases
45
+ URL=https://oss.sonatype.org/service/local/staging/deploy/maven2/
46
+ else
47
+ GOAL=deploy:deploy-file
48
+ REPOSITORY_ID=sonatype-nexus-snapshots
49
+ URL=https://oss.sonatype.org/content/repositories/snapshots/
50
+ VERSION="$VERSION-SNAPSHOT"
51
+ fi
52
+
53
+ $MVN $GOAL \
54
+ -DgroupId=org.kill-bill.billing.plugin.ruby \
55
+ -DartifactId=invoice-test-plugin \
56
+ -Dversion=$VERSION \
57
+ -Dpackaging=tar.gz \
58
+ -DrepositoryId=$REPOSITORY_ID \
59
+ -Durl=$URL \
60
+ -Dfile=$ARTIFACT \
61
+ -DpomFile=pom.xml
@@ -2,9 +2,19 @@ require 'spec_helper'
2
2
  require 'logger'
3
3
 
4
4
  describe InvoiceTest::InvoicePlugin do
5
+
6
+ class FakeJavaInvoiceUserApi
7
+ attr_accessor :invoices
8
+
9
+ def get_invoices_by_account(accountId, context)
10
+ @invoices
11
+ end
12
+ end
13
+
5
14
  before(:each) do
15
+ @invoice_api = FakeJavaInvoiceUserApi.new
16
+ kb_apis = Killbill::Plugin::KillbillApi.new('killbill-invoice-test', {:invoice_user_api => @invoice_api})
6
17
 
7
- kb_apis = Killbill::Plugin::KillbillApi.new('killbill-invoice-test', {})
8
18
  @plugin = InvoiceTest::InvoicePlugin.new
9
19
  @plugin.logger = Logger.new(STDOUT)
10
20
  @plugin.kb_apis = kb_apis
@@ -18,22 +28,89 @@ describe InvoiceTest::InvoicePlugin do
18
28
  @plugin.stop_plugin
19
29
  end
20
30
 
21
- it 'should add additional item' do
22
- item = Killbill::Plugin::Model::InvoiceItem.new
23
- item.id = SecureRandom.uuid
24
- item.amount = 100
31
+ it 'should add two additional items' do
32
+ fixed_item = build_invoice_item(100, :FIXED)
33
+ recurring_item = build_invoice_item(150, :RECURRING)
34
+ invoice = build_invoice([fixed_item, recurring_item])
25
35
 
26
- invoice = Killbill::Plugin::Model::Invoice.new
27
- invoice.id = SecureRandom.uuid
28
- invoice.invoice_items = [item]
36
+ new_items = @plugin.get_additional_invoice_items(invoice, @properties, @call_context)
37
+ new_items.size.should == 2
38
+
39
+ check_invoice_item(new_items[0], 7, fixed_item)
40
+ check_invoice_item(new_items[1], 10.5, recurring_item)
41
+
42
+ check_idempotency(invoice, new_items)
43
+ end
44
+
45
+ it 'should add no additional item' do
46
+ fixed_item = build_invoice_item(100, :FIXED)
47
+ recurring_item = build_invoice_item(150, :RECURRING)
48
+ recurring_adj_item = build_invoice_item(-150, :ITEM_ADJ, recurring_item.id)
49
+ fixed_adj_item = build_invoice_item(-100, :ITEM_ADJ, fixed_item.id)
50
+ invoice = build_invoice([fixed_item, recurring_item, recurring_adj_item, fixed_adj_item])
51
+
52
+ new_items = @plugin.get_additional_invoice_items(invoice, @properties, @call_context)
53
+ new_items.size.should == 0
54
+
55
+ check_idempotency(invoice, new_items)
56
+ end
57
+
58
+ it 'should add a single additional item' do
59
+ fixed_item = build_invoice_item(100, :FIXED)
60
+ recurring_item = build_invoice_item(150, :RECURRING)
61
+ fixed_adj_item = build_invoice_item(-100, :ITEM_ADJ, fixed_item.id)
62
+ invoice = build_invoice([fixed_item, recurring_item, fixed_adj_item])
29
63
 
30
64
  new_items = @plugin.get_additional_invoice_items(invoice, @properties, @call_context)
31
65
  new_items.size.should == 1
32
66
 
33
- new_item = new_items.first
34
- new_item.should be_an_instance_of Killbill::Plugin::Model::InvoiceItem
35
- new_item.amount.should == 7
36
- new_item.invoice_item_type.should == :TAX
37
- new_item.linked_item_id.should == item.id
67
+ check_invoice_item(new_items[0], 10.5, recurring_item)
68
+
69
+ check_idempotency(invoice, new_items)
70
+ end
71
+
72
+ it 'should handle partial adjustments' do
73
+ fixed_item = build_invoice_item(100, :FIXED)
74
+ tax_item = build_invoice_item(7, :TAX, fixed_item.id)
75
+ fixed_adj_item = build_invoice_item(-20, :ITEM_ADJ, fixed_item.id)
76
+ invoice = build_invoice([fixed_item, tax_item, fixed_adj_item])
77
+
78
+ new_items = @plugin.get_additional_invoice_items(invoice, @properties, @call_context)
79
+ new_items.size.should == 1
80
+
81
+ check_invoice_item(new_items[0], -1.4, tax_item, :ITEM_ADJ)
82
+
83
+ check_idempotency(invoice, new_items)
84
+ end
85
+
86
+ private
87
+
88
+ def build_invoice(items)
89
+ invoice = Killbill::Plugin::Model::Invoice.new
90
+ invoice.id = SecureRandom.uuid
91
+ invoice.invoice_items = items
92
+ invoice
93
+ end
94
+
95
+ def build_invoice_item(amount, invoice_item_type=:FIXED, linked_item_id=nil)
96
+ item = Killbill::Plugin::Model::InvoiceItem.new
97
+ item.id = SecureRandom.uuid
98
+ item.amount = amount
99
+ item.invoice_item_type = invoice_item_type
100
+ item.linked_item_id = linked_item_id
101
+ item
102
+ end
103
+
104
+ def check_invoice_item(item, amount, original_item, invoice_item_type=:TAX)
105
+ item.should be_an_instance_of Killbill::Plugin::Model::InvoiceItem
106
+ item.amount.should == amount
107
+ item.invoice_item_type.should == invoice_item_type
108
+ item.linked_item_id.should == original_item.id
109
+ end
110
+
111
+ def check_idempotency(original_invoice, new_items)
112
+ invoice = build_invoice(original_invoice.invoice_items + new_items)
113
+ additional_items = @plugin.get_additional_invoice_items(invoice, @properties, @call_context)
114
+ additional_items.size.should == 0
38
115
  end
39
116
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-invoice-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kill Bill core team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: killbill
@@ -16,12 +16,12 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.2
19
+ version: '7.0'
20
20
  requirement: !ruby/object:Gem::Requirement
21
21
  requirements:
22
22
  - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: 3.2.2
24
+ version: '7.0'
25
25
  prerelease: false
26
26
  type: :runtime
27
27
  - !ruby/object:Gem::Dependency
@@ -30,12 +30,12 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.1
33
+ version: 0.9.2
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
36
  - - ~>
37
37
  - !ruby/object:Gem::Version
38
- version: 0.4.1
38
+ version: 0.9.2
39
39
  prerelease: false
40
40
  type: :development
41
41
  - !ruby/object:Gem::Dependency
@@ -75,7 +75,9 @@ files:
75
75
  - .gitignore
76
76
  - .travis.yml
77
77
  - Gemfile
78
+ - Gemfile.lock
78
79
  - Jarfile
80
+ - Jarfile.lock
79
81
  - README.md
80
82
  - Rakefile
81
83
  - VERSION
@@ -109,10 +111,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
111
  version: '0'
110
112
  requirements: []
111
113
  rubyforge_project:
112
- rubygems_version: 2.2.2
114
+ rubygems_version: 2.1.9
113
115
  signing_key:
114
116
  specification_version: 4
115
117
  summary: Plugin to test the invoice plugin api.
116
- test_files:
117
- - spec/invoice_test/base_plugin_spec.rb
118
- - spec/spec_helper.rb
118
+ test_files: []