killbill-stripe 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +39 -0
- data/.travis.yml +19 -0
- data/Gemfile +3 -0
- data/Jarfile +6 -0
- data/NEWS +2 -0
- data/README.md +21 -0
- data/Rakefile +30 -0
- data/VERSION +1 -0
- data/config.ru +4 -0
- data/db/ddl.sql +99 -0
- data/db/schema.rb +99 -0
- data/killbill-stripe.gemspec +42 -0
- data/killbill.properties +3 -0
- data/lib/stripe/api.rb +248 -0
- data/lib/stripe/config/application.rb +76 -0
- data/lib/stripe/config/configuration.rb +38 -0
- data/lib/stripe/config/properties.rb +23 -0
- data/lib/stripe/models/stripe_payment_method.rb +182 -0
- data/lib/stripe/models/stripe_response.rb +242 -0
- data/lib/stripe/models/stripe_transaction.rb +44 -0
- data/lib/stripe/private_api.rb +52 -0
- data/lib/stripe/stripe/gateway.rb +24 -0
- data/lib/stripe/stripe_utils.rb +27 -0
- data/lib/stripe/views/stripejs.erb +88 -0
- data/lib/stripe.rb +30 -0
- data/pom.xml +44 -0
- data/release.sh +41 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/stripe/base_plugin_spec.rb +85 -0
- data/spec/stripe/remote/integration_spec.rb +208 -0
- data/spec/stripe/stripe_payment_method_spec.rb +97 -0
- data/spec/stripe/stripe_response_spec.rb +84 -0
- metadata +222 -0
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
ActiveMerchant::Billing::Base.mode = :test
|
4
|
+
|
5
|
+
class FakeJavaUserAccountApi
|
6
|
+
attr_accessor :accounts
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@accounts = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_account_by_id(id, context)
|
13
|
+
@accounts.find { |account| account.id == id.to_s }
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_account_by_key(external_key, context)
|
17
|
+
@accounts.find { |account| account.external_key == external_key.to_s }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Killbill::Stripe::PaymentPlugin do
|
22
|
+
before(:each) do
|
23
|
+
@plugin = Killbill::Stripe::PaymentPlugin.new
|
24
|
+
|
25
|
+
@account_api = FakeJavaUserAccountApi.new
|
26
|
+
svcs = {:account_user_api => @account_api}
|
27
|
+
@plugin.kb_apis = Killbill::Plugin::KillbillApi.new('stripe', svcs)
|
28
|
+
|
29
|
+
@plugin.logger = Logger.new(STDOUT)
|
30
|
+
@plugin.logger.level = Logger::INFO
|
31
|
+
@plugin.conf_dir = File.expand_path(File.dirname(__FILE__) + '../../../../')
|
32
|
+
@plugin.start_plugin
|
33
|
+
end
|
34
|
+
|
35
|
+
after(:each) do
|
36
|
+
@plugin.stop_plugin
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should be able to create and retrieve payment methods' do
|
40
|
+
pm = create_payment_method
|
41
|
+
|
42
|
+
pms = @plugin.get_payment_methods(pm.kb_account_id)
|
43
|
+
pms.size.should == 1
|
44
|
+
pms[0].external_payment_method_id.should == pm.stripe_card_id_or_token
|
45
|
+
|
46
|
+
pm_details = @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id)
|
47
|
+
pm_details.external_payment_method_id.should == pm.stripe_card_id_or_token
|
48
|
+
|
49
|
+
pms_found = @plugin.search_payment_methods pm.cc_last_4
|
50
|
+
pms_found = pms_found.iterator.to_a
|
51
|
+
pms_found.size.should == 1
|
52
|
+
pms_found.first.external_payment_method_id.should == pm_details.external_payment_method_id
|
53
|
+
|
54
|
+
@plugin.delete_payment_method(pm.kb_account_id, pm.kb_payment_method_id)
|
55
|
+
|
56
|
+
@plugin.get_payment_methods(pm.kb_account_id).size.should == 0
|
57
|
+
lambda { @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id) }.should raise_error RuntimeError
|
58
|
+
|
59
|
+
# Verify we can add multiple payment methods
|
60
|
+
pm1 = create_payment_method(pm.kb_account_id)
|
61
|
+
pm2 = create_payment_method(pm.kb_account_id)
|
62
|
+
|
63
|
+
pms = @plugin.get_payment_methods(pm.kb_account_id)
|
64
|
+
pms.size.should == 2
|
65
|
+
pms[0].external_payment_method_id.should == pm1.stripe_card_id_or_token
|
66
|
+
pms[1].external_payment_method_id.should == pm2.stripe_card_id_or_token
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should be able to charge and refund' do
|
70
|
+
pm = create_payment_method
|
71
|
+
amount = BigDecimal.new("100")
|
72
|
+
currency = 'USD'
|
73
|
+
kb_payment_id = SecureRandom.uuid
|
74
|
+
|
75
|
+
payment_response = @plugin.process_payment pm.kb_account_id, kb_payment_id, pm.kb_payment_method_id, amount, currency
|
76
|
+
payment_response.amount.should == amount
|
77
|
+
payment_response.status.should == :PROCESSED
|
78
|
+
|
79
|
+
# Verify our table directly
|
80
|
+
response = Killbill::Stripe::StripeResponse.find_by_api_call_and_kb_payment_id :charge, kb_payment_id
|
81
|
+
response.test.should be_true
|
82
|
+
response.success.should be_true
|
83
|
+
response.message.should == 'Transaction approved'
|
84
|
+
|
85
|
+
payment_response = @plugin.get_payment_info pm.kb_account_id, kb_payment_id
|
86
|
+
payment_response.amount.should == amount
|
87
|
+
payment_response.status.should == :PROCESSED
|
88
|
+
|
89
|
+
# Check we cannot refund an amount greater than the original charge
|
90
|
+
lambda { @plugin.process_refund pm.kb_account_id, kb_payment_id, amount + 1, currency }.should raise_error RuntimeError
|
91
|
+
|
92
|
+
refund_response = @plugin.process_refund pm.kb_account_id, kb_payment_id, amount, currency
|
93
|
+
refund_response.amount.should == amount
|
94
|
+
refund_response.status.should == :PROCESSED
|
95
|
+
|
96
|
+
# Verify our table directly
|
97
|
+
response = Killbill::Stripe::StripeResponse.find_by_api_call_and_kb_payment_id :refund, kb_payment_id
|
98
|
+
response.test.should be_true
|
99
|
+
response.success.should be_true
|
100
|
+
|
101
|
+
# Check we can retrieve the refund
|
102
|
+
refund_responses = @plugin.get_refund_info pm.kb_account_id, kb_payment_id
|
103
|
+
refund_responses.size.should == 1
|
104
|
+
# Apparently, Stripe returns positive amounts for refunds
|
105
|
+
refund_responses[0].amount.should == amount
|
106
|
+
refund_responses[0].status.should == :PROCESSED
|
107
|
+
|
108
|
+
# Make sure we can charge again the same payment method
|
109
|
+
second_amount = BigDecimal.new("294.71")
|
110
|
+
second_kb_payment_id = SecureRandom.uuid
|
111
|
+
|
112
|
+
payment_response = @plugin.process_payment pm.kb_account_id, second_kb_payment_id, pm.kb_payment_method_id, second_amount, currency
|
113
|
+
payment_response.amount.should == second_amount
|
114
|
+
payment_response.status.should == :PROCESSED
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def create_payment_method(kb_account_id=nil)
|
120
|
+
kb_payment_method_id = SecureRandom.uuid
|
121
|
+
|
122
|
+
if kb_account_id.nil?
|
123
|
+
kb_account_id = SecureRandom.uuid
|
124
|
+
|
125
|
+
# Create a new account
|
126
|
+
create_kb_account kb_account_id
|
127
|
+
end
|
128
|
+
|
129
|
+
# Generate a token in Stripe
|
130
|
+
cc_number = '4242424242424242'
|
131
|
+
cc_first_name = 'John'
|
132
|
+
cc_last_name = 'Doe'
|
133
|
+
cc_type = 'Visa'
|
134
|
+
cc_exp_month = 12
|
135
|
+
cc_exp_year = 2015
|
136
|
+
cc_last_4 = 4242
|
137
|
+
address1 = '5, oakriu road'
|
138
|
+
address2 = 'apt. 298'
|
139
|
+
city = 'Gdio Foia'
|
140
|
+
state = 'FL'
|
141
|
+
zip = 49302
|
142
|
+
country = 'IFP'
|
143
|
+
cc_verification_value = 1234
|
144
|
+
|
145
|
+
properties = []
|
146
|
+
properties << create_pm_kv_info('ccNumber', cc_number)
|
147
|
+
properties << create_pm_kv_info('ccFirstName', cc_first_name)
|
148
|
+
properties << create_pm_kv_info('ccLastName', cc_last_name)
|
149
|
+
properties << create_pm_kv_info('ccType', cc_type)
|
150
|
+
properties << create_pm_kv_info('ccExpirationMonth', cc_exp_month)
|
151
|
+
properties << create_pm_kv_info('ccExpirationYear', cc_exp_year)
|
152
|
+
properties << create_pm_kv_info('ccLast4', cc_last_4)
|
153
|
+
properties << create_pm_kv_info('address1', address1)
|
154
|
+
properties << create_pm_kv_info('address2', address2)
|
155
|
+
properties << create_pm_kv_info('city', city)
|
156
|
+
properties << create_pm_kv_info('state', state)
|
157
|
+
properties << create_pm_kv_info('zip', zip)
|
158
|
+
properties << create_pm_kv_info('country', country)
|
159
|
+
properties << create_pm_kv_info('ccVerificationValue', cc_verification_value)
|
160
|
+
|
161
|
+
info = Killbill::Plugin::Model::PaymentMethodPlugin.new
|
162
|
+
info.properties = properties
|
163
|
+
payment_method = @plugin.add_payment_method(kb_account_id, kb_payment_method_id, info, true)
|
164
|
+
|
165
|
+
pm = Killbill::Stripe::StripePaymentMethod.from_kb_payment_method_id kb_payment_method_id
|
166
|
+
pm.should == payment_method
|
167
|
+
pm.kb_account_id.should == kb_account_id
|
168
|
+
pm.kb_payment_method_id.should == kb_payment_method_id
|
169
|
+
pm.stripe_card_id_or_token.should_not be_nil
|
170
|
+
pm.cc_first_name.should == cc_first_name + ' ' + cc_last_name
|
171
|
+
pm.cc_last_name.should be_nil
|
172
|
+
pm.cc_type.should == cc_type
|
173
|
+
pm.cc_exp_month.should == cc_exp_month
|
174
|
+
pm.cc_exp_year.should == cc_exp_year
|
175
|
+
pm.cc_last_4.should == cc_last_4
|
176
|
+
pm.address1.should == address1
|
177
|
+
pm.address2.should == address2
|
178
|
+
pm.city.should == city
|
179
|
+
pm.state.should == state
|
180
|
+
pm.zip.should == zip.to_s
|
181
|
+
pm.country.should == country
|
182
|
+
|
183
|
+
pm
|
184
|
+
end
|
185
|
+
|
186
|
+
def create_kb_account(kb_account_id)
|
187
|
+
external_key = Time.now.to_i.to_s + '-test'
|
188
|
+
email = external_key + '@tester.com'
|
189
|
+
|
190
|
+
account = Killbill::Plugin::Model::Account.new
|
191
|
+
account.id = kb_account_id
|
192
|
+
account.external_key = external_key
|
193
|
+
account.email = email
|
194
|
+
account.name = 'Integration spec'
|
195
|
+
account.currency = :USD
|
196
|
+
|
197
|
+
@account_api.accounts << account
|
198
|
+
|
199
|
+
return external_key, kb_account_id
|
200
|
+
end
|
201
|
+
|
202
|
+
def create_pm_kv_info(key, value)
|
203
|
+
prop = Killbill::Plugin::Model::PaymentMethodKVInfo.new
|
204
|
+
prop.key = key
|
205
|
+
prop.value = value
|
206
|
+
prop
|
207
|
+
end
|
208
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Killbill::Stripe::StripePaymentMethod do
|
4
|
+
before :all do
|
5
|
+
Killbill::Stripe::StripePaymentMethod.delete_all
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should generate the right SQL query' do
|
9
|
+
# Check count query (search query numeric)
|
10
|
+
expected_query = "SELECT COUNT(DISTINCT \"stripe_payment_methods\".\"id\") FROM \"stripe_payment_methods\" WHERE (((((((((((((((\"stripe_payment_methods\".\"kb_account_id\" = '1234' OR \"stripe_payment_methods\".\"kb_payment_method_id\" = '1234') OR \"stripe_payment_methods\".\"stripe_customer_id\" = '1234') OR \"stripe_payment_methods\".\"stripe_card_id_or_token\" = '1234') OR \"stripe_payment_methods\".\"cc_type\" = '1234') OR \"stripe_payment_methods\".\"state\" = '1234') OR \"stripe_payment_methods\".\"zip\" = '1234') OR \"stripe_payment_methods\".\"cc_first_name\" LIKE '%1234%') OR \"stripe_payment_methods\".\"cc_last_name\" LIKE '%1234%') OR \"stripe_payment_methods\".\"address1\" LIKE '%1234%') OR \"stripe_payment_methods\".\"address2\" LIKE '%1234%') OR \"stripe_payment_methods\".\"city\" LIKE '%1234%') OR \"stripe_payment_methods\".\"country\" LIKE '%1234%') OR \"stripe_payment_methods\".\"cc_exp_month\" = 1234) OR \"stripe_payment_methods\".\"cc_exp_year\" = 1234) OR \"stripe_payment_methods\".\"cc_last_4\" = 1234) AND \"stripe_payment_methods\".\"kb_payment_method_id\" IS NOT NULL ORDER BY \"stripe_payment_methods\".\"id\""
|
11
|
+
# Note that Kill Bill will pass a String, even for numeric types
|
12
|
+
Killbill::Stripe::StripePaymentMethod.search_query('1234').to_sql.should == expected_query
|
13
|
+
|
14
|
+
# Check query with results (search query numeric)
|
15
|
+
expected_query = "SELECT DISTINCT \"stripe_payment_methods\".* FROM \"stripe_payment_methods\" WHERE (((((((((((((((\"stripe_payment_methods\".\"kb_account_id\" = '1234' OR \"stripe_payment_methods\".\"kb_payment_method_id\" = '1234') OR \"stripe_payment_methods\".\"stripe_customer_id\" = '1234') OR \"stripe_payment_methods\".\"stripe_card_id_or_token\" = '1234') OR \"stripe_payment_methods\".\"cc_type\" = '1234') OR \"stripe_payment_methods\".\"state\" = '1234') OR \"stripe_payment_methods\".\"zip\" = '1234') OR \"stripe_payment_methods\".\"cc_first_name\" LIKE '%1234%') OR \"stripe_payment_methods\".\"cc_last_name\" LIKE '%1234%') OR \"stripe_payment_methods\".\"address1\" LIKE '%1234%') OR \"stripe_payment_methods\".\"address2\" LIKE '%1234%') OR \"stripe_payment_methods\".\"city\" LIKE '%1234%') OR \"stripe_payment_methods\".\"country\" LIKE '%1234%') OR \"stripe_payment_methods\".\"cc_exp_month\" = 1234) OR \"stripe_payment_methods\".\"cc_exp_year\" = 1234) OR \"stripe_payment_methods\".\"cc_last_4\" = 1234) AND \"stripe_payment_methods\".\"kb_payment_method_id\" IS NOT NULL ORDER BY \"stripe_payment_methods\".\"id\" LIMIT 10 OFFSET 0"
|
16
|
+
# Note that Kill Bill will pass a String, even for numeric types
|
17
|
+
Killbill::Stripe::StripePaymentMethod.search_query('1234', 0, 10).to_sql.should == expected_query
|
18
|
+
|
19
|
+
# Check count query (search query string)
|
20
|
+
expected_query = "SELECT COUNT(DISTINCT \"stripe_payment_methods\".\"id\") FROM \"stripe_payment_methods\" WHERE ((((((((((((\"stripe_payment_methods\".\"kb_account_id\" = 'XXX' OR \"stripe_payment_methods\".\"kb_payment_method_id\" = 'XXX') OR \"stripe_payment_methods\".\"stripe_customer_id\" = 'XXX') OR \"stripe_payment_methods\".\"stripe_card_id_or_token\" = 'XXX') OR \"stripe_payment_methods\".\"cc_type\" = 'XXX') OR \"stripe_payment_methods\".\"state\" = 'XXX') OR \"stripe_payment_methods\".\"zip\" = 'XXX') OR \"stripe_payment_methods\".\"cc_first_name\" LIKE '%XXX%') OR \"stripe_payment_methods\".\"cc_last_name\" LIKE '%XXX%') OR \"stripe_payment_methods\".\"address1\" LIKE '%XXX%') OR \"stripe_payment_methods\".\"address2\" LIKE '%XXX%') OR \"stripe_payment_methods\".\"city\" LIKE '%XXX%') OR \"stripe_payment_methods\".\"country\" LIKE '%XXX%') AND \"stripe_payment_methods\".\"kb_payment_method_id\" IS NOT NULL ORDER BY \"stripe_payment_methods\".\"id\""
|
21
|
+
Killbill::Stripe::StripePaymentMethod.search_query('XXX').to_sql.should == expected_query
|
22
|
+
|
23
|
+
# Check query with results (search query string)
|
24
|
+
expected_query = "SELECT DISTINCT \"stripe_payment_methods\".* FROM \"stripe_payment_methods\" WHERE ((((((((((((\"stripe_payment_methods\".\"kb_account_id\" = 'XXX' OR \"stripe_payment_methods\".\"kb_payment_method_id\" = 'XXX') OR \"stripe_payment_methods\".\"stripe_customer_id\" = 'XXX') OR \"stripe_payment_methods\".\"stripe_card_id_or_token\" = 'XXX') OR \"stripe_payment_methods\".\"cc_type\" = 'XXX') OR \"stripe_payment_methods\".\"state\" = 'XXX') OR \"stripe_payment_methods\".\"zip\" = 'XXX') OR \"stripe_payment_methods\".\"cc_first_name\" LIKE '%XXX%') OR \"stripe_payment_methods\".\"cc_last_name\" LIKE '%XXX%') OR \"stripe_payment_methods\".\"address1\" LIKE '%XXX%') OR \"stripe_payment_methods\".\"address2\" LIKE '%XXX%') OR \"stripe_payment_methods\".\"city\" LIKE '%XXX%') OR \"stripe_payment_methods\".\"country\" LIKE '%XXX%') AND \"stripe_payment_methods\".\"kb_payment_method_id\" IS NOT NULL ORDER BY \"stripe_payment_methods\".\"id\" LIMIT 10 OFFSET 0"
|
25
|
+
Killbill::Stripe::StripePaymentMethod.search_query('XXX', 0, 10).to_sql.should == expected_query
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should search all fields' do
|
29
|
+
do_search('foo').size.should == 0
|
30
|
+
|
31
|
+
pm = Killbill::Stripe::StripePaymentMethod.create :kb_account_id => '11-22-33-44',
|
32
|
+
:kb_payment_method_id => '55-66-77-88',
|
33
|
+
:stripe_customer_id => '123xka',
|
34
|
+
:stripe_card_id_or_token => 38102343,
|
35
|
+
:cc_first_name => 'ccFirstName',
|
36
|
+
:cc_last_name => 'ccLastName',
|
37
|
+
:cc_type => 'ccType',
|
38
|
+
:cc_exp_month => 10,
|
39
|
+
:cc_exp_year => 11,
|
40
|
+
:cc_last_4 => 1234,
|
41
|
+
:address1 => 'address1',
|
42
|
+
:address2 => 'address2',
|
43
|
+
:city => 'city',
|
44
|
+
:state => 'state',
|
45
|
+
:zip => 'zip',
|
46
|
+
:country => 'country'
|
47
|
+
|
48
|
+
do_search('foo').size.should == 0
|
49
|
+
do_search(pm.stripe_card_id_or_token).size.should == 1
|
50
|
+
do_search('ccType').size.should == 1
|
51
|
+
# Exact match only for cc_last_4
|
52
|
+
do_search('123').size.should == 0
|
53
|
+
do_search('1234').size.should == 1
|
54
|
+
# Test partial match
|
55
|
+
do_search('address').size.should == 1
|
56
|
+
do_search('Name').size.should == 1
|
57
|
+
|
58
|
+
pm2 = Killbill::Stripe::StripePaymentMethod.create :kb_account_id => '22-33-44-55',
|
59
|
+
:kb_payment_method_id => '66-77-88-99',
|
60
|
+
:stripe_customer_id => '123xka',
|
61
|
+
:stripe_card_id_or_token => 49384029302,
|
62
|
+
:cc_first_name => 'ccFirstName',
|
63
|
+
:cc_last_name => 'ccLastName',
|
64
|
+
:cc_type => 'ccType',
|
65
|
+
:cc_exp_month => 10,
|
66
|
+
:cc_exp_year => 11,
|
67
|
+
:cc_last_4 => 1234,
|
68
|
+
:address1 => 'address1',
|
69
|
+
:address2 => 'address2',
|
70
|
+
:city => 'city',
|
71
|
+
:state => 'state',
|
72
|
+
:zip => 'zip',
|
73
|
+
:country => 'country'
|
74
|
+
|
75
|
+
do_search('foo').size.should == 0
|
76
|
+
do_search(pm.stripe_card_id_or_token).size.should == 1
|
77
|
+
do_search(pm2.stripe_card_id_or_token).size.should == 1
|
78
|
+
do_search('ccType').size.should == 2
|
79
|
+
# Exact match only for cc_last_4
|
80
|
+
do_search('123').size.should == 0
|
81
|
+
do_search('1234').size.should == 2
|
82
|
+
# Test partial match
|
83
|
+
do_search('cc').size.should == 2
|
84
|
+
do_search('address').size.should == 2
|
85
|
+
do_search('Name').size.should == 2
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def do_search(search_key)
|
91
|
+
pagination = Killbill::Stripe::StripePaymentMethod.search(search_key)
|
92
|
+
pagination.current_offset.should == 0
|
93
|
+
results = pagination.iterator.to_a
|
94
|
+
pagination.total_nb_records.should == results.size
|
95
|
+
results
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Killbill::Stripe::StripeResponse do
|
4
|
+
before :all do
|
5
|
+
Killbill::Stripe::StripeResponse.delete_all
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should generate the right SQL query' do
|
9
|
+
# Check count query (search query numeric)
|
10
|
+
expected_query = "SELECT COUNT(DISTINCT \"stripe_responses\".\"id\") FROM \"stripe_responses\" WHERE ((\"stripe_responses\".\"authorization\" = '1234' OR \"stripe_responses\".\"params_id\" = '1234') OR \"stripe_responses\".\"params_card_id\" = '1234') AND \"stripe_responses\".\"api_call\" = 'charge' AND \"stripe_responses\".\"success\" = 't' ORDER BY \"stripe_responses\".\"id\""
|
11
|
+
# Note that Kill Bill will pass a String, even for numeric types
|
12
|
+
Killbill::Stripe::StripeResponse.search_query('charge', '1234').to_sql.should == expected_query
|
13
|
+
|
14
|
+
# Check query with results (search query numeric)
|
15
|
+
expected_query = "SELECT DISTINCT \"stripe_responses\".* FROM \"stripe_responses\" WHERE ((\"stripe_responses\".\"authorization\" = '1234' OR \"stripe_responses\".\"params_id\" = '1234') OR \"stripe_responses\".\"params_card_id\" = '1234') AND \"stripe_responses\".\"api_call\" = 'charge' AND \"stripe_responses\".\"success\" = 't' ORDER BY \"stripe_responses\".\"id\" LIMIT 10 OFFSET 0"
|
16
|
+
# Note that Kill Bill will pass a String, even for numeric types
|
17
|
+
Killbill::Stripe::StripeResponse.search_query('charge', '1234', 0, 10).to_sql.should == expected_query
|
18
|
+
|
19
|
+
# Check count query (search query string)
|
20
|
+
expected_query = "SELECT COUNT(DISTINCT \"stripe_responses\".\"id\") FROM \"stripe_responses\" WHERE ((\"stripe_responses\".\"authorization\" = 'XXX' OR \"stripe_responses\".\"params_id\" = 'XXX') OR \"stripe_responses\".\"params_card_id\" = 'XXX') AND \"stripe_responses\".\"api_call\" = 'charge' AND \"stripe_responses\".\"success\" = 't' ORDER BY \"stripe_responses\".\"id\""
|
21
|
+
Killbill::Stripe::StripeResponse.search_query('charge', 'XXX').to_sql.should == expected_query
|
22
|
+
|
23
|
+
# Check query with results (search query string)
|
24
|
+
expected_query = "SELECT DISTINCT \"stripe_responses\".* FROM \"stripe_responses\" WHERE ((\"stripe_responses\".\"authorization\" = 'XXX' OR \"stripe_responses\".\"params_id\" = 'XXX') OR \"stripe_responses\".\"params_card_id\" = 'XXX') AND \"stripe_responses\".\"api_call\" = 'charge' AND \"stripe_responses\".\"success\" = 't' ORDER BY \"stripe_responses\".\"id\" LIMIT 10 OFFSET 0"
|
25
|
+
Killbill::Stripe::StripeResponse.search_query('charge', 'XXX', 0, 10).to_sql.should == expected_query
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should search all fields' do
|
29
|
+
do_search('foo').size.should == 0
|
30
|
+
|
31
|
+
pm = Killbill::Stripe::StripeResponse.create :api_call => 'charge',
|
32
|
+
:kb_payment_id => '11-22-33-44',
|
33
|
+
:authorization => 'aa-bb-cc-dd',
|
34
|
+
:params_id => '55-66-77-88',
|
35
|
+
:params_card_id => 38102343,
|
36
|
+
:success => true
|
37
|
+
|
38
|
+
# Wrong api_call
|
39
|
+
ignored1 = Killbill::Stripe::StripeResponse.create :api_call => 'add_payment_method',
|
40
|
+
:kb_payment_id => pm.kb_payment_id,
|
41
|
+
:authorization => pm.authorization,
|
42
|
+
:params_id => pm.params_id,
|
43
|
+
:params_card_id => pm.params_card_id,
|
44
|
+
:success => true
|
45
|
+
|
46
|
+
# Not successful
|
47
|
+
ignored2 = Killbill::Stripe::StripeResponse.create :api_call => 'charge',
|
48
|
+
:kb_payment_id => pm.kb_payment_id,
|
49
|
+
:authorization => pm.authorization,
|
50
|
+
:params_id => pm.params_id,
|
51
|
+
:params_card_id => pm.params_card_id,
|
52
|
+
:success => false
|
53
|
+
|
54
|
+
do_search('foo').size.should == 0
|
55
|
+
do_search(pm.authorization).size.should == 1
|
56
|
+
do_search(pm.params_id).size.should == 1
|
57
|
+
do_search(pm.params_card_id).size.should == 1
|
58
|
+
|
59
|
+
pm2 = Killbill::Stripe::StripeResponse.create :api_call => 'charge',
|
60
|
+
:kb_payment_id => '11-22-33-44',
|
61
|
+
:authorization => 'AA-BB-CC-DD',
|
62
|
+
:params_id => '11-22-33-44',
|
63
|
+
:params_card_id => pm.params_card_id,
|
64
|
+
:success => true
|
65
|
+
|
66
|
+
do_search('foo').size.should == 0
|
67
|
+
do_search(pm.authorization).size.should == 1
|
68
|
+
do_search(pm.params_id).size.should == 1
|
69
|
+
do_search(pm.params_card_id).size.should == 2
|
70
|
+
do_search(pm2.authorization).size.should == 1
|
71
|
+
do_search(pm2.params_id).size.should == 1
|
72
|
+
do_search(pm2.params_card_id).size.should == 2
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def do_search(search_key)
|
78
|
+
pagination = Killbill::Stripe::StripeResponse.search(search_key)
|
79
|
+
pagination.current_offset.should == 0
|
80
|
+
results = pagination.iterator.to_a
|
81
|
+
pagination.total_nb_records.should == results.size
|
82
|
+
results
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: killbill-stripe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kill Bill core team
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: killbill
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.0.0
|
25
|
+
prerelease: false
|
26
|
+
type: :runtime
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activemerchant
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.42.3
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 1.42.3
|
39
|
+
prerelease: false
|
40
|
+
type: :runtime
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.1
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ~>
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 3.2.1
|
53
|
+
prerelease: false
|
54
|
+
type: :runtime
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: money
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 6.0.0
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 6.0.0
|
67
|
+
prerelease: false
|
68
|
+
type: :runtime
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.4
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ~>
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.3.4
|
81
|
+
prerelease: false
|
82
|
+
type: :runtime
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activerecord-jdbcmysql-adapter
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.2.9
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.2.9
|
95
|
+
prerelease: false
|
96
|
+
type: :runtime
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: jbundler
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.4.1
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ~>
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 0.4.1
|
109
|
+
prerelease: false
|
110
|
+
type: :development
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 10.0.0
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 10.0.0
|
123
|
+
prerelease: false
|
124
|
+
type: :development
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.12.0
|
132
|
+
requirement: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ~>
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 2.12.0
|
137
|
+
prerelease: false
|
138
|
+
type: :development
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: activerecord-jdbcsqlite3-adapter
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.2.6
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ~>
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 1.2.6
|
151
|
+
prerelease: false
|
152
|
+
type: :development
|
153
|
+
description: Kill Bill payment plugin for Stripe.
|
154
|
+
email: killbilling-users@googlegroups.com
|
155
|
+
executables: []
|
156
|
+
extensions: []
|
157
|
+
extra_rdoc_files: []
|
158
|
+
files:
|
159
|
+
- .gitignore
|
160
|
+
- .travis.yml
|
161
|
+
- Gemfile
|
162
|
+
- Jarfile
|
163
|
+
- NEWS
|
164
|
+
- README.md
|
165
|
+
- Rakefile
|
166
|
+
- VERSION
|
167
|
+
- config.ru
|
168
|
+
- db/ddl.sql
|
169
|
+
- db/schema.rb
|
170
|
+
- killbill-stripe.gemspec
|
171
|
+
- killbill.properties
|
172
|
+
- lib/stripe.rb
|
173
|
+
- lib/stripe/api.rb
|
174
|
+
- lib/stripe/config/application.rb
|
175
|
+
- lib/stripe/config/configuration.rb
|
176
|
+
- lib/stripe/config/properties.rb
|
177
|
+
- lib/stripe/models/stripe_payment_method.rb
|
178
|
+
- lib/stripe/models/stripe_response.rb
|
179
|
+
- lib/stripe/models/stripe_transaction.rb
|
180
|
+
- lib/stripe/private_api.rb
|
181
|
+
- lib/stripe/stripe/gateway.rb
|
182
|
+
- lib/stripe/stripe_utils.rb
|
183
|
+
- lib/stripe/views/stripejs.erb
|
184
|
+
- pom.xml
|
185
|
+
- release.sh
|
186
|
+
- spec/spec_helper.rb
|
187
|
+
- spec/stripe/base_plugin_spec.rb
|
188
|
+
- spec/stripe/remote/integration_spec.rb
|
189
|
+
- spec/stripe/stripe_payment_method_spec.rb
|
190
|
+
- spec/stripe/stripe_response_spec.rb
|
191
|
+
homepage: http://kill-bill.org
|
192
|
+
licenses:
|
193
|
+
- Apache License (2.0)
|
194
|
+
metadata: {}
|
195
|
+
post_install_message:
|
196
|
+
rdoc_options:
|
197
|
+
- --exclude
|
198
|
+
- .
|
199
|
+
require_paths:
|
200
|
+
- lib
|
201
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
202
|
+
requirements:
|
203
|
+
- - '>='
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: 1.9.3
|
206
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
|
+
requirements:
|
208
|
+
- - '>='
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: '0'
|
211
|
+
requirements: []
|
212
|
+
rubyforge_project:
|
213
|
+
rubygems_version: 2.2.2
|
214
|
+
signing_key:
|
215
|
+
specification_version: 4
|
216
|
+
summary: Plugin to use Stripe as a gateway.
|
217
|
+
test_files:
|
218
|
+
- spec/spec_helper.rb
|
219
|
+
- spec/stripe/base_plugin_spec.rb
|
220
|
+
- spec/stripe/remote/integration_spec.rb
|
221
|
+
- spec/stripe/stripe_payment_method_spec.rb
|
222
|
+
- spec/stripe/stripe_response_spec.rb
|