killbill-stripe 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ba27ab150e0ca41ad6f189062e69b711f377937
4
- data.tar.gz: b8fefa955f17569be7f8ea193eb7a399431c27b3
3
+ metadata.gz: e0cda4e3c446746c694b4366902447a04c5e4866
4
+ data.tar.gz: 57e193eb8e5e7c812239398e8aec10fca5763b94
5
5
  SHA512:
6
- metadata.gz: 3e7b7b4152da1e02731a199b303c3f5bee3ef3d2808d924e449c6cc5cfc310975401b9106c8471ef4f1b86dbc795ad8353042a20e9772c0edd166e6cdfd9ed9a
7
- data.tar.gz: 771695b85455bb7e6d605f60e12389065a5a605e6f49c1854f725ac1949715b282a0bda40ed357a0305f4096337264aa684dd9ed4178bd0794e46078e5c87648
6
+ metadata.gz: 044f52bfe5b64b23b624a943dc292624e9d2bfe04d653070806a5415874afd3dc893ed64e457a1ccbae20f4fa9f05007a5a6a31d3ce72f9ef0f11833fc05791e
7
+ data.tar.gz: de10c6649729229eed9e9f5cb2539229fea2d69e92f7e8de2b1f6f1a046150a43fdba28fefdf1856e01c5e4d8808ced58b311fbeef512057ea11063760d75904
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- killbill-stripe (4.0.0)
4
+ killbill-stripe (4.1.0)
5
5
  actionpack (~> 4.1.0)
6
6
  actionview (~> 4.1.0)
7
- activemerchant (~> 1.48.0)
7
+ activemerchant (~> 1.55.0)
8
8
  activerecord (~> 4.1.0)
9
9
  activerecord-bogacs (~> 0.3)
10
10
  activerecord-jdbc-adapter (~> 1.3, < 1.5)
@@ -19,34 +19,34 @@ PATH
19
19
  GEM
20
20
  remote: https://rubygems.org/
21
21
  specs:
22
- actionpack (4.1.15)
23
- actionview (= 4.1.15)
24
- activesupport (= 4.1.15)
22
+ actionpack (4.1.16)
23
+ actionview (= 4.1.16)
24
+ activesupport (= 4.1.16)
25
25
  rack (~> 1.5.2)
26
26
  rack-test (~> 0.6.2)
27
- actionview (4.1.15)
28
- activesupport (= 4.1.15)
27
+ actionview (4.1.16)
28
+ activesupport (= 4.1.16)
29
29
  builder (~> 3.1)
30
30
  erubis (~> 2.7.0)
31
31
  active_utils (3.0.0)
32
32
  activesupport (>= 3.2)
33
33
  i18n
34
- activemerchant (1.48.0)
34
+ activemerchant (1.55.0)
35
35
  activesupport (>= 3.2.14, < 5.0.0)
36
36
  builder (>= 2.1.2, < 4.0.0)
37
37
  i18n (>= 0.6.9)
38
38
  nokogiri (~> 1.4)
39
- activemodel (4.1.15)
40
- activesupport (= 4.1.15)
39
+ activemodel (4.1.16)
40
+ activesupport (= 4.1.16)
41
41
  builder (~> 3.1)
42
- activerecord (4.1.15)
43
- activemodel (= 4.1.15)
44
- activesupport (= 4.1.15)
42
+ activerecord (4.1.16)
43
+ activemodel (= 4.1.16)
44
+ activesupport (= 4.1.16)
45
45
  arel (~> 5.0.0)
46
46
  activerecord-bogacs (0.5.0)
47
- activerecord-jdbc-adapter (1.3.20)
47
+ activerecord-jdbc-adapter (1.3.21)
48
48
  activerecord (>= 2.2)
49
- activesupport (4.1.15)
49
+ activesupport (4.1.16)
50
50
  i18n (~> 0.6, >= 0.6.9)
51
51
  json (~> 1.7, >= 1.7.7)
52
52
  minitest (~> 5.1)
@@ -65,9 +65,9 @@ GEM
65
65
  diff-lcs (1.1.3)
66
66
  equalizer (0.0.11)
67
67
  erubis (2.7.0)
68
- ethon (0.9.0)
68
+ ethon (0.9.1)
69
69
  ffi (>= 1.3.0)
70
- ffi (1.9.10-java)
70
+ ffi (1.9.14-java)
71
71
  i18n (0.7.0)
72
72
  ice_nine (0.11.2)
73
73
  jar-dependencies (0.3.4)
@@ -81,19 +81,19 @@ GEM
81
81
  jdbc-sqlite3 (3.8.11.2)
82
82
  jruby-openssl (0.9.17-java)
83
83
  json (1.8.3-java)
84
- killbill (8.0.0)
84
+ killbill (8.3.0)
85
85
  rack (>= 1.5.2)
86
86
  sinatra (~> 1.3.4)
87
87
  typhoeus (~> 0.6.9)
88
88
  tzinfo (~> 1.2.0)
89
89
  maven-tools (1.1.6)
90
90
  virtus (~> 1.0)
91
- minitest (5.9.0)
91
+ minitest (5.9.1)
92
92
  monetize (1.1.0)
93
93
  money (~> 6.5.0)
94
94
  money (6.5.1)
95
95
  i18n (>= 0.6.4, <= 0.7.0)
96
- nokogiri (1.6.8-java)
96
+ nokogiri (1.6.8.1-java)
97
97
  offsite_payments (2.1.0)
98
98
  actionpack (>= 3.2.20, < 5.0.0)
99
99
  active_utils (~> 3.0.0)
@@ -148,4 +148,4 @@ DEPENDENCIES
148
148
  rspec (~> 2.12.0)
149
149
 
150
150
  BUNDLED WITH
151
- 1.10.6
151
+ 1.11.2
data/Jarfile CHANGED
@@ -1,12 +1,12 @@
1
- jar 'org.kill-bill.billing:killbill-api', '0.34'
2
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-currency', '0.19'
3
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-invoice', '0.19'
4
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-notification', '0.19'
5
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-payment', '0.19'
6
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-control', '0.19'
7
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-catalog', '0.19'
8
- jar 'org.kill-bill.billing.plugin:killbill-plugin-api-entitlement', '0.19'
9
- jar 'org.kill-bill.billing:killbill-util:tests', '0.17.0'
10
- jar 'org.kill-bill.billing:killbill-util', '0.17.0'
1
+ jar 'org.kill-bill.billing:killbill-api', '0.50'
2
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-currency', '0.23'
3
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-invoice', '0.23'
4
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-notification', '0.23'
5
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-payment', '0.23'
6
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-control', '0.23'
7
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-catalog', '0.23'
8
+ jar 'org.kill-bill.billing.plugin:killbill-plugin-api-entitlement', '0.23'
9
+ jar 'org.kill-bill.billing:killbill-util:tests', '0.17.8'
10
+ jar 'org.kill-bill.billing:killbill-util', '0.17.8'
11
11
  jar 'org.mockito:mockito-all', '1.10.19'
12
12
  jar 'javax.servlet:javax.servlet-api', '3.1.0'
@@ -1,66 +1,66 @@
1
1
  ---
2
2
  :runtime:
3
- - org.kill-bill.billing:killbill-platform-base:jar:0.27
4
- - org.javassist:javassist:jar:3.19.0-GA
5
- - org.apache.shiro:shiro-core:jar:1.2.3
3
+ - io.dropwizard.metrics:metrics-core:jar:3.1.1
6
4
  - joda-time:joda-time:jar:2.3
7
- - org.kill-bill.billing.plugin:killbill-plugin-api-control:jar:0.19
8
- - net.sf.ehcache:ehcache:jar:2.9.1
9
- - aopalliance:aopalliance:jar:1.0
10
- - com.google.code.findbugs:annotations:jar:3.0.0
5
+ - org.weakref:jmxutils:jar:1.18
6
+ - commons-beanutils:commons-beanutils:jar:1.8.3
7
+ - org.kill-bill.billing:killbill-platform-api:jar:0.34
8
+ - com.google.inject:guice:jar:3.0
11
9
  - org.osgi:org.osgi.core:jar:5.0.0
12
- - org.kill-bill.billing.plugin:killbill-plugin-api-currency:jar:0.19
13
- - com.zaxxer:HikariCP-java6:jar:2.3.7
14
- - org.bouncycastle:bcprov-jdk15on:jar:1.54
15
- - org.apache.shiro:shiro-guice:jar:1.2.3
16
- - org.bouncycastle:bcpkix-jdk15on:jar:1.54
17
- - org.kill-bill.billing.plugin:killbill-plugin-api-catalog:jar:0.19
18
- - org.apache.commons:commons-email:jar:1.2
10
+ - com.fasterxml.jackson.core:jackson-databind:jar:2.4.5
11
+ - org.kill-bill.billing.plugin:killbill-plugin-api-currency:jar:0.23
12
+ - com.samskivert:jmustache:jar:1.5
13
+ - org.kill-bill.billing:killbill-util:jar:tests:0.17.8
14
+ - org.kill-bill.commons:killbill-clock:jar:0.20
15
+ - com.fasterxml.jackson.dataformat:jackson-dataformat-csv:jar:2.4.5
16
+ - org.kill-bill.billing:killbill-platform-osgi-api:jar:0.34
17
+ - org.kill-bill.billing.plugin:killbill-plugin-api-entitlement:jar:0.23
18
+ - org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4:jar:1.16
19
+ - com.h2database:h2:jar:1.4.186
20
+ - com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.5
21
+ - javax.activation:activation:jar:1.1
22
+ - org.kill-bill.billing:killbill-internal-api:jar:0.17.8
23
+ - org.javassist:javassist:jar:3.19.0-GA
19
24
  - org.skife.config:config-magic:jar:0.14
25
+ - org.apache.commons:commons-email:jar:1.2
26
+ - org.mockito:mockito-all:jar:1.10.19
20
27
  - antlr:antlr:jar:2.7.7
21
- - org.kill-bill.billing:killbill-platform-api:jar:0.27
22
- - org.antlr:stringtemplate:jar:3.2.1
23
- - org.apache.shiro:shiro-ehcache:jar:1.2.3
24
- - org.joda:joda-money:jar:0.9
25
- - org.jdbi:jdbi:jar:2.62
28
+ - aopalliance:aopalliance:jar:1.0
29
+ - com.zaxxer:HikariCP-java6:jar:2.3.7
30
+ - org.slf4j:slf4j-api:jar:1.7.21
26
31
  - com.fasterxml.jackson.core:jackson-annotations:jar:2.4.3
27
- - com.fasterxml.jackson.dataformat:jackson-dataformat-csv:jar:2.4.3
28
- - com.google.inject:guice:jar:3.0
29
- - com.fasterxml.jackson.core:jackson-databind:jar:2.4.3
30
- - org.kill-bill.billing.plugin:killbill-plugin-api-entitlement:jar:0.19
31
- - org.apache.felix:org.apache.felix.framework:jar:4.4.1
32
- - org.kill-bill.billing:killbill-api:jar:0.34
33
- - com.samskivert:jmustache:jar:1.5
34
- - org.kill-bill.commons:killbill-queue:jar:0.16
35
- - com.h2database:h2:jar:1.4.186
36
- - org.kill-bill.commons:killbill-jdbi:jar:0.16
37
- - org.kill-bill.billing:killbill-platform-osgi-api:jar:0.27
32
+ - org.antlr:stringtemplate:jar:3.2.1
38
33
  - org.slf4j:jcl-over-slf4j:jar:1.7.21
39
- - org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4:jar:1.16
40
- - org.kill-bill.commons:killbill-embeddeddb-common:jar:0.16
41
- - org.kill-bill.billing:killbill-util:jar:0.17.0
42
- - com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.4.3
43
- - org.kill-bill.billing:killbill-internal-api:jar:0.17.0
44
- - org.kill-bill.commons:killbill-concurrent:jar:0.16
45
- - com.fasterxml.jackson.core:jackson-core:jar:2.4.3
46
- - com.google.guava:guava:jar:r09
47
34
  - javax.mail:mail:jar:1.4.1
48
- - org.kill-bill.billing.plugin:killbill-plugin-api-notification:jar:0.19
49
- - javax.activation:activation:jar:1.1
50
- - org.kill-bill.commons:killbill-xmlloader:jar:0.16
51
- - io.dropwizard.metrics:metrics-core:jar:3.1.1
52
- - org.kill-bill.billing:killbill-platform-osgi:jar:0.27
53
- - org.kill-bill.commons:killbill-clock:jar:0.16
54
- - org.weakref:jmxutils:jar:1.18
55
- - com.google.inject.extensions:guice-multibindings:jar:3.0
56
- - javax.inject:javax.inject:jar:1
57
- - org.slf4j:slf4j-api:jar:1.7.21
58
- - commons-beanutils:commons-beanutils:jar:1.8.3
59
- - javax.servlet:javax.servlet-api:jar:3.1.0
60
35
  - io.dropwizard.metrics:metrics-ehcache:jar:3.1.1
61
- - org.kill-bill.commons:killbill-locker:jar:0.16
62
- - org.kill-bill.billing.plugin:killbill-plugin-api-invoice:jar:0.19
63
- - org.kill-bill.billing:killbill-util:jar:tests:0.17.0
64
- - org.mockito:mockito-all:jar:1.10.19
65
- - org.kill-bill.billing.plugin:killbill-plugin-api-payment:jar:0.19
36
+ - org.kill-bill.billing:killbill-platform-osgi:jar:0.34
37
+ - org.jdbi:jdbi:jar:2.62
38
+ - com.fasterxml.jackson.core:jackson-core:jar:2.4.5
39
+ - org.bouncycastle:bcpkix-jdk15on:jar:1.54
40
+ - org.apache.felix:org.apache.felix.framework:jar:4.4.1
41
+ - org.joda:joda-money:jar:0.9
42
+ - org.kill-bill.billing.plugin:killbill-plugin-api-payment:jar:0.23
43
+ - org.kill-bill.billing:killbill-util:jar:0.17.8
44
+ - org.bouncycastle:bcprov-jdk15on:jar:1.54
45
+ - org.apache.shiro:shiro-core:jar:1.2.3
46
+ - org.kill-bill.billing:killbill-platform-base:jar:0.34
47
+ - org.kill-bill.billing.plugin:killbill-plugin-api-control:jar:0.23
48
+ - org.kill-bill.commons:killbill-jdbi:jar:0.20
49
+ - com.google.guava:guava:jar:r09
50
+ - org.kill-bill.commons:killbill-queue:jar:0.20
66
51
  - org.osgi:org.osgi.compendium:jar:5.0.0
52
+ - org.kill-bill.commons:killbill-xmlloader:jar:0.20
53
+ - javax.servlet:javax.servlet-api:jar:3.1.0
54
+ - org.apache.shiro:shiro-ehcache:jar:1.2.3
55
+ - javax.inject:javax.inject:jar:1
56
+ - org.kill-bill.billing.plugin:killbill-plugin-api-invoice:jar:0.23
57
+ - org.kill-bill.billing:killbill-api:jar:0.50
58
+ - com.google.inject.extensions:guice-multibindings:jar:3.0
59
+ - net.sf.ehcache:ehcache:jar:2.9.1
60
+ - org.kill-bill.commons:killbill-locker:jar:0.20
61
+ - org.kill-bill.commons:killbill-embeddeddb-common:jar:0.20
62
+ - org.apache.shiro:shiro-guice:jar:1.2.3
63
+ - org.kill-bill.commons:killbill-concurrent:jar:0.20
64
+ - org.kill-bill.billing.plugin:killbill-plugin-api-catalog:jar:0.23
65
+ - org.kill-bill.billing.plugin:killbill-plugin-api-notification:jar:0.23
66
+ - com.google.code.findbugs:annotations:jar:3.0.0
data/NEWS CHANGED
@@ -1,3 +1,9 @@
1
+ 4.1.0
2
+ Initial release for Kill Bill 0.18.x
3
+
4
+ 4.0.0
5
+ Initial release for Kill Bill 0.17.x
6
+
1
7
  3.0.2
2
8
  Allow override of the Stripe customer id in the add_payment_method call
3
9
 
data/README.md CHANGED
@@ -5,15 +5,17 @@ Plugin to use [Stripe](https://stripe.com/) as a gateway.
5
5
 
6
6
  Release builds are available on [Maven Central](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.kill-bill.billing.plugin.ruby%22%20AND%20a%3A%22stripe-plugin%22) with coordinates `org.kill-bill.billing.plugin.ruby:stripe-plugin`.
7
7
 
8
+ A full end-to-end integration demo is available [here](https://github.com/killbill/killbill-stripe-demo).
9
+
8
10
  Kill Bill compatibility
9
11
  -----------------------
10
12
 
11
13
  | Plugin version | Kill Bill version | Stripe version |
12
14
  | -------------: | -----------------: | --------------------------------------------------------: |
13
- | 1.0.y | 0.14.z | [2015-02-18](https://stripe.com/docs/upgrades#2015-02-18) |
14
- | 2.0.y | 0.15.z | [2015-02-18](https://stripe.com/docs/upgrades#2015-02-18) |
15
- | 3.0.y | 0.16.z | [2015-02-18](https://stripe.com/docs/upgrades#2015-02-18) |
16
- | 4.0.y | 0.18.z (and 0.17.y)| [2015-02-18](https://stripe.com/docs/upgrades#2015-02-18) |
15
+ | 1.x.y | 0.14.z | [2015-02-18](https://stripe.com/docs/upgrades#2015-02-18) |
16
+ | 2.x.y | 0.15.z | [2015-02-18](https://stripe.com/docs/upgrades#2015-02-18) |
17
+ | 3.x.y | 0.16.z | [2015-02-18](https://stripe.com/docs/upgrades#2015-02-18) |
18
+ | 4.x.y | 0.17.z | [2015-02-18](https://stripe.com/docs/upgrades#2015-02-18) |
17
19
 
18
20
  Requirements
19
21
  ------------
@@ -33,7 +35,9 @@ curl -v \
33
35
  -H 'Content-Type: text/plain' \
34
36
  -d ':stripe:
35
37
  :api_secret_key: "your-secret-key"
36
- :api_publishable_key: "your-publishable-key"' \
38
+ :api_publishable_key: "your-publishable-key"
39
+ :fees_amount: "default-fees-amount-for-connect"
40
+ :fees_percent: "default-fees-percent-for-connect"' \
37
41
  http://127.0.0.1:8080/1.0/kb/tenants/uploadPluginConfig/killbill-stripe
38
42
  ```
39
43
 
@@ -42,6 +46,9 @@ To get your credentials:
42
46
  1. Go to [stripe.com](http://stripe.com/) and create an account. This account will be used as a sandbox environment for testing.
43
47
  2. In your Stripe account, click on **Your Account** (top right), then click on **Account Settings** and then on the **API Keys** tab. Write down your keys.
44
48
 
49
+ For Connect, you can configure a default fees amount (`fees_amount`) or percentage (`fees_percent`, such as .3 for 30%). These can be modified on a per request basis by passing the plugin property `fees_amount` or `fees_percent`.
50
+ You'll also need to add a row to the `stripe_application_fees` table and add a percent (such as .3 for 30%) to the `application_fee` field.
51
+
45
52
  To go to production, create a `stripe.yml` configuration file under `/var/tmp/bundles/plugins/ruby/killbill-stripe/x.y.z/` containing the following:
46
53
 
47
54
  ```
@@ -54,7 +61,7 @@ Usage
54
61
 
55
62
  You would typically implement [Stripe.js](https://stripe.com/docs/stripe.js) to tokenize credit cards.
56
63
 
57
- After receiving the token from Stripe, call:
64
+ After receiving the token from Stripe, create a Kill Bill payment method associated with it as such:
58
65
 
59
66
  ```
60
67
  curl -v \
@@ -73,15 +80,49 @@ curl -v \
73
80
  }]
74
81
  }
75
82
  }' \
76
- "http://127.0.0.1:8080/1.0/kb/accounts/2a55045a-ce1d-4344-942d-b825536328f9/paymentMethods?isDefault=true"
83
+ "http://127.0.0.1:8080/1.0/kb/accounts/<KB_ACCOUNT_ID>/paymentMethods?isDefault=true"
77
84
  ```
78
85
 
79
86
  An example implementation is exposed at:
80
87
 
81
88
  ```
82
- http://127.0.0.1:8080/plugins/killbill-stripe?kb_account_id=2a55045a-ce1d-4344-942d-b825536328f9&kb_tenant_id=a86d9fd1-718d-4178-a9eb-46c61aa2548f
89
+ http://127.0.0.1:8080/plugins/killbill-stripe?kb_account_id=<KB_ACCOUNT_ID>&kb_tenant_id=<KB_TENANT_ID>
83
90
  ```
84
91
 
92
+ After entering you credit card, this demo page will:
93
+
94
+ * Tokenize it in Stripe (JS call)
95
+ * Call Kill Bill during the redirect to create a payment method for that token
96
+ * Output the result of the tokenization call
97
+
98
+ ### Connect
99
+
100
+ Managed accounts must first have their own account in Kill Bill. Then, create them in Stripe using `POST /plugins/killbill-stripe/accounts`:
101
+
102
+ ```
103
+ curl -v -X POST \
104
+ -d '{
105
+ "legal_entity": {
106
+ "address": {
107
+ "city": "San Francisco",
108
+ "country": "US"
109
+ },
110
+ "dob": {
111
+ "day": 31,
112
+ "month": 12,
113
+ "year": 1969
114
+ },
115
+ "first_name": "Jane",
116
+ "last_name": "Doe"",
117
+ "type": "individual"
118
+ }' \
119
+ http://127.0.0.1:8080/plugins/killbill-stripe/accounts?kb_account_id=<KB_ACCOUNT_ID>&kb_tenant_id=<KB_TENANT_ID>
120
+ ```
121
+
122
+ When charging customers, you can now pass the Kill Bill account id of the managed account as the `destination` plugin property.
123
+
124
+ See the [Stripe documentation](https://stripe.com/docs/connect/managed-accounts#creating-a-managed-account) for more details.
125
+
85
126
  Plugin properties
86
127
  -----------------
87
128
 
@@ -111,3 +152,8 @@ Plugin properties
111
152
  | payment_instrument_name | ApplePay tokenization attribute |
112
153
  | payment_network | ApplePay tokenization attribute |
113
154
  | transaction_identifier | ApplePay tokenization attribute |
155
+ | destination | [Connect] KB account id of the receiving account |
156
+ | fees_amount | [Connect] Amount in cents of fees to collect |
157
+ | fees_percent | [Connect] Percentage amount of fees to collect |
158
+ | reverse_transfer | [Connect] True if the transfer should be reversed when refunding |
159
+ | refund_application_fee | [Connect] True if fees should be refunded when refunding |
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.0
1
+ 4.1.0
@@ -34,7 +34,8 @@ Gem::Specification.new do |s|
34
34
  end
35
35
  s.add_dependency 'actionpack', '~> 4.1.0'
36
36
  s.add_dependency 'actionview', '~> 4.1.0'
37
- s.add_dependency 'activemerchant', '~> 1.48.0'
37
+ # 1.56.0 and above requires Ruby 2.0
38
+ s.add_dependency 'activemerchant', '~> 1.55.0'
38
39
  s.add_dependency 'offsite_payments', '~> 2.1.0'
39
40
  s.add_dependency 'monetize', '~> 1.1.0'
40
41
  s.add_dependency 'money', '~> 6.5.1'
@@ -16,9 +16,12 @@ require 'yaml'
16
16
  require 'killbill'
17
17
  require 'killbill/helpers/active_merchant'
18
18
 
19
+ require 'stripe/ext/active_merchant/active_merchant'
20
+
19
21
  require 'stripe/api'
20
22
  require 'stripe/private_api'
21
23
 
22
24
  require 'stripe/models/payment_method'
23
25
  require 'stripe/models/response'
24
26
  require 'stripe/models/transaction'
27
+
@@ -1,3 +1,4 @@
1
+ include Killbill::Plugin::ActiveMerchant
1
2
  module Killbill #:nodoc:
2
3
  module Stripe #:nodoc:
3
4
  class PaymentPlugin < ::Killbill::Plugin::ActiveMerchant::PaymentPlugin
@@ -25,10 +26,8 @@ module Killbill #:nodoc:
25
26
  def authorize_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
26
27
  pm = @payment_method_model.from_kb_payment_method_id(kb_payment_method_id, context.tenant_id)
27
28
 
28
- # Pass extra parameters for the gateway here
29
- options = {
30
- :customer => pm.stripe_customer_id
31
- }
29
+ options = {}
30
+ populate_defaults(pm, amount, properties, context, options)
32
31
 
33
32
  properties = merge_properties(properties, options)
34
33
  super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
@@ -45,10 +44,8 @@ module Killbill #:nodoc:
45
44
  def purchase_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
46
45
  pm = @payment_method_model.from_kb_payment_method_id(kb_payment_method_id, context.tenant_id)
47
46
 
48
- # Pass extra parameters for the gateway here
49
- options = {
50
- :customer => pm.stripe_customer_id
51
- }
47
+ options = {}
48
+ populate_defaults(pm, amount, properties, context, options)
52
49
 
53
50
  properties = merge_properties(properties, options)
54
51
  super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
@@ -74,6 +71,12 @@ module Killbill #:nodoc:
74
71
  # Pass extra parameters for the gateway here
75
72
  options = {}
76
73
 
74
+ reverse_transfer = find_value_from_properties(properties, :reverse_transfer)
75
+ options[:reverse_transfer] = ::Killbill::Plugin::ActiveMerchant::Utils.normalize(reverse_transfer)
76
+
77
+ refund_application_fee = find_value_from_properties(properties, :refund_application_fee)
78
+ options[:refund_application_fee] = ::Killbill::Plugin::ActiveMerchant::Utils.normalize(refund_application_fee)
79
+
77
80
  properties = merge_properties(properties, options)
78
81
  super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
79
82
  end
@@ -97,10 +100,11 @@ module Killbill #:nodoc:
97
100
  def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context)
98
101
  # Do we have a customer for that account already?
99
102
  stripe_customer_id = find_value_from_properties(payment_method_props.properties, :customer) || StripePaymentMethod.stripe_customer_id_from_kb_account_id(kb_account_id, context.tenant_id)
103
+ email = find_value_from_properties(payment_method_props.properties, :email) || @kb_apis.account_user_api.get_account_by_id(kb_account_id, @kb_apis.create_context(context.tenant_id)).email
100
104
 
101
105
  # Pass extra parameters for the gateway here
102
106
  options = {
103
- :email => @kb_apis.account_user_api.get_account_by_id(kb_account_id, @kb_apis.create_context(context.tenant_id)).email,
107
+ :email => email,
104
108
  # This will either update the current customer if present, or create a new one
105
109
  :customer => stripe_customer_id,
106
110
  # Magic field, see also private_api.rb (works only when creating an account)
@@ -182,26 +186,66 @@ module Killbill #:nodoc:
182
186
  super(kb_account_id, descriptor_fields, properties, context)
183
187
  end
184
188
 
185
- def process_notification(notification, properties, context)
186
- # Pass extra parameters for the gateway here
187
- options = {}
188
- properties = merge_properties(properties, options)
189
+ def process_notification(notification_json, properties, context)
190
+ notification = JSON.parse(notification_json)
191
+ gw_response = ::ActiveMerchant::Billing::Response.new(true,
192
+ nil,
193
+ notification,
194
+ :test => !notification['livemode'],
195
+ :authorization => notification['request'],
196
+ :avs_result => nil,
197
+ :cvv_result => nil,
198
+ :emv_authorization => nil,
199
+ :error_code => nil)
200
+ save_response_and_transaction(gw_response, "webhook.#{notification['type']}".to_sym, nil, context.tenant_id, nil)
189
201
 
190
- super(notification, properties, context) do |gw_notification, service|
191
- # Retrieve the payment
192
- # gw_notification.kb_payment_id =
193
- #
194
- # Set the response body
195
- # gw_notification.entity =
196
- end
202
+ gw_notification = ::Killbill::Plugin::Model::GatewayNotification.new
203
+ gw_notification.kb_payment_id = nil
204
+ gw_notification.status = 200
205
+ gw_notification.headers = {}
206
+ gw_notification.properties = []
207
+ gw_notification
197
208
  end
198
209
 
199
210
  private
200
211
 
212
+ def before_gateways(kb_transaction, last_transaction, payment_source, amount_in_cents, currency, options, context)
213
+ super(kb_transaction, last_transaction, payment_source, amount_in_cents, currency, options, context)
214
+ options[:idempotency_key] ||= kb_transaction.external_key
215
+ end
216
+
201
217
  def get_payment_source(kb_payment_method_id, properties, options, context)
202
218
  return nil if options[:customer_id]
203
219
  super(kb_payment_method_id, properties, options, context)
204
220
  end
221
+
222
+ def populate_defaults(pm, amount, properties, context, options)
223
+ options[:customer] ||= pm.stripe_customer_id
224
+ options[:destination] ||= get_destination(properties, context)
225
+ options[:application_fee] ||= get_application_fee(amount, properties) unless options[:destination].nil?
226
+ end
227
+
228
+ def get_destination(properties, context)
229
+ stripe_account_id = find_value_from_properties(properties, :destination)
230
+ if stripe_account_id.nil?
231
+ config(context.tenant_id)[:stripe][:stripe_destination]
232
+ elsif stripe_account_id =~ /[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}/
233
+ # Stripe doesn't use UUIDs - assume the destination is a Kill Bill account id
234
+ ::Killbill::Stripe::StripeResponse.managed_stripe_account_id_from_kb_account_id(stripe_account_id, context.tenant_id)
235
+ else
236
+ stripe_account_id
237
+ end
238
+ end
239
+
240
+ def get_application_fee(amount, properties)
241
+ fees_amount = find_value_from_properties(properties, :fees_amount)
242
+ return fees_amount unless fees_amount.nil?
243
+
244
+ fees_percent = find_value_from_properties(properties, :fees_percent)
245
+ return (fees_percent * amount * 100).to_i unless fees_percent.nil?
246
+
247
+ config(context.tenant_id)[:stripe][:fees_amount] || (config(context.tenant_id)[:stripe][:fees_percent].to_f * amount * 100)
248
+ end
205
249
  end
206
250
  end
207
251
  end