killbill-stripe 0.1.0 → 0.2.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 +4 -4
- data/.gitignore +0 -3
- data/Gemfile +1 -1
- data/Jarfile +7 -5
- data/LICENSE +201 -0
- data/NEWS +1 -1
- data/README.md +26 -7
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/config.ru +1 -1
- data/db/ddl.sql +28 -5
- data/db/schema.rb +41 -17
- data/killbill-stripe.gemspec +14 -7
- data/lib/stripe.rb +10 -16
- data/lib/stripe/api.rb +143 -203
- data/lib/stripe/{config/application.rb → application.rb} +35 -20
- data/lib/stripe/models/payment_method.rb +58 -0
- data/lib/stripe/models/response.rb +80 -0
- data/lib/stripe/models/transaction.rb +11 -0
- data/lib/stripe/private_api.rb +28 -46
- data/pom.xml +3 -3
- data/release.sh +8 -8
- data/spec/spec_helper.rb +3 -16
- data/spec/stripe/base_plugin_spec.rb +26 -20
- data/spec/stripe/remote/integration_spec.rb +120 -167
- data/stripe.yml +21 -0
- metadata +104 -26
- data/lib/stripe/config/configuration.rb +0 -38
- data/lib/stripe/config/properties.rb +0 -23
- data/lib/stripe/models/stripe_payment_method.rb +0 -182
- data/lib/stripe/models/stripe_response.rb +0 -242
- data/lib/stripe/models/stripe_transaction.rb +0 -44
- data/lib/stripe/stripe/gateway.rb +0 -24
- data/lib/stripe/stripe_utils.rb +0 -27
- data/spec/stripe/stripe_payment_method_spec.rb +0 -97
- data/spec/stripe/stripe_response_spec.rb +0 -84
@@ -1,23 +1,29 @@
|
|
1
|
+
# -- encoding : utf-8 --
|
2
|
+
|
3
|
+
set :views, File.expand_path(File.dirname(__FILE__) + '/views')
|
4
|
+
|
5
|
+
include Killbill::Plugin::ActiveMerchant::Sinatra
|
6
|
+
|
1
7
|
configure do
|
2
8
|
# Usage: rackup -Ilib -E test
|
3
9
|
if development? or test?
|
4
|
-
|
10
|
+
# Make sure the plugin is initialized
|
11
|
+
plugin = ::Killbill::Stripe::PaymentPlugin.new
|
12
|
+
plugin.logger = Logger.new(STDOUT)
|
13
|
+
plugin.logger.level = Logger::INFO
|
14
|
+
plugin.conf_dir = File.dirname(File.dirname(__FILE__)) + '/..'
|
15
|
+
plugin.start_plugin
|
5
16
|
end
|
6
17
|
end
|
7
18
|
|
8
19
|
helpers do
|
9
|
-
def plugin
|
10
|
-
Killbill::Stripe::PrivatePaymentPlugin.
|
20
|
+
def plugin(session = {})
|
21
|
+
::Killbill::Stripe::PrivatePaymentPlugin.new(:stripe,
|
22
|
+
::Killbill::Stripe::StripePaymentMethod,
|
23
|
+
::Killbill::Stripe::StripeTransaction,
|
24
|
+
::Killbill::Stripe::StripeResponse,
|
25
|
+
session)
|
11
26
|
end
|
12
|
-
|
13
|
-
def required_parameter!(parameter_name, parameter_value, message='must be specified!')
|
14
|
-
halt 400, "#{parameter_name} #{message}" if parameter_value.blank?
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
after do
|
19
|
-
# return DB connections to the Pool if required
|
20
|
-
ActiveRecord::Base.connection.close
|
21
27
|
end
|
22
28
|
|
23
29
|
# http://127.0.0.1:9292/plugins/killbill-stripe
|
@@ -26,11 +32,11 @@ get '/plugins/killbill-stripe' do
|
|
26
32
|
required_parameter! :kb_account_id, kb_account_id
|
27
33
|
|
28
34
|
# URL to Stripe.js
|
29
|
-
stripejs_url =
|
35
|
+
stripejs_url = config[:stripe][:stripejs_url] || 'https://js.stripe.com/v2/'
|
30
36
|
required_parameter! :stripejs_url, stripejs_url, 'is not configured'
|
31
37
|
|
32
38
|
# Public API key
|
33
|
-
publishable_key =
|
39
|
+
publishable_key = config[:stripe][:api_publishable_key]
|
34
40
|
required_parameter! :publishable_key, publishable_key, 'is not configured'
|
35
41
|
|
36
42
|
# Redirect
|
@@ -38,12 +44,12 @@ get '/plugins/killbill-stripe' do
|
|
38
44
|
required_parameter! :success_page, success_page, 'is not specified'
|
39
45
|
|
40
46
|
locals = {
|
41
|
-
:stripejs_url
|
47
|
+
:stripejs_url => stripejs_url,
|
42
48
|
:publishable_key => publishable_key,
|
43
|
-
:kb_account_id
|
44
|
-
:success_page
|
49
|
+
:kb_account_id => kb_account_id,
|
50
|
+
:success_page => success_page
|
45
51
|
}
|
46
|
-
erb :stripejs, :
|
52
|
+
erb :stripejs, :locals => locals
|
47
53
|
end
|
48
54
|
|
49
55
|
# This is mainly for testing. Your application should redirect from the Stripe.js checkout above
|
@@ -59,7 +65,7 @@ end
|
|
59
65
|
|
60
66
|
# curl -v http://127.0.0.1:9292/plugins/killbill-stripe/1.0/pms/1
|
61
67
|
get '/plugins/killbill-stripe/1.0/pms/:id', :provides => 'json' do
|
62
|
-
if pm = Killbill::Stripe::StripePaymentMethod.find_by_id(params[:id].to_i)
|
68
|
+
if pm = ::Killbill::Stripe::StripePaymentMethod.find_by_id(params[:id].to_i)
|
63
69
|
pm.to_json
|
64
70
|
else
|
65
71
|
status 404
|
@@ -68,9 +74,18 @@ end
|
|
68
74
|
|
69
75
|
# curl -v http://127.0.0.1:9292/plugins/killbill-stripe/1.0/transactions/1
|
70
76
|
get '/plugins/killbill-stripe/1.0/transactions/:id', :provides => 'json' do
|
71
|
-
if transaction = Killbill::Stripe::StripeTransaction.find_by_id(params[:id].to_i)
|
77
|
+
if transaction = ::Killbill::Stripe::StripeTransaction.find_by_id(params[:id].to_i)
|
72
78
|
transaction.to_json
|
73
79
|
else
|
74
80
|
status 404
|
75
81
|
end
|
76
82
|
end
|
83
|
+
|
84
|
+
# curl -v http://127.0.0.1:9292/plugins/killbill-stripe/1.0/responses/1
|
85
|
+
get '/plugins/killbill-stripe/1.0/responses/:id', :provides => 'json' do
|
86
|
+
if transaction = ::Killbill::Stripe::StripeResponse.find_by_id(params[:id].to_i)
|
87
|
+
transaction.to_json
|
88
|
+
else
|
89
|
+
status 404
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Killbill #:nodoc:
|
2
|
+
module Stripe #:nodoc:
|
3
|
+
class StripePaymentMethod < ::Killbill::Plugin::ActiveMerchant::ActiveRecord::PaymentMethod
|
4
|
+
|
5
|
+
self.table_name = 'stripe_payment_methods'
|
6
|
+
|
7
|
+
def self.from_response(kb_account_id, kb_payment_method_id, kb_tenant_id, cc_or_token, response, options, extra_params = {}, model = ::Killbill::Stripe::StripePaymentMethod)
|
8
|
+
stripe_customer_id = self.stripe_customer_id_from_kb_account_id(kb_account_id, kb_tenant_id)
|
9
|
+
unless stripe_customer_id.blank?
|
10
|
+
card_response = response.responses.first.params
|
11
|
+
customer_response = response.responses.last.params
|
12
|
+
else
|
13
|
+
card_response = response.params['cards']['data'][0]
|
14
|
+
customer_response = response.params
|
15
|
+
end
|
16
|
+
|
17
|
+
super(kb_account_id,
|
18
|
+
kb_payment_method_id,
|
19
|
+
kb_tenant_id,
|
20
|
+
cc_or_token,
|
21
|
+
response,
|
22
|
+
options,
|
23
|
+
{
|
24
|
+
:stripe_customer_id => customer_response['id'],
|
25
|
+
:token => card_response['id'],
|
26
|
+
:cc_first_name => card_response['name'],
|
27
|
+
:cc_last_name => nil,
|
28
|
+
:cc_type => card_response['type'],
|
29
|
+
:cc_exp_month => card_response['exp_month'],
|
30
|
+
:cc_exp_year => card_response['exp_year'],
|
31
|
+
:cc_last_4 => card_response['last4'],
|
32
|
+
:address1 => card_response['address_line1'],
|
33
|
+
:address2 => card_response['address_line2'],
|
34
|
+
:city => card_response['address_city'],
|
35
|
+
:state => card_response['address_state'],
|
36
|
+
:zip => card_response['address_zip'],
|
37
|
+
:country => card_response['address_country']
|
38
|
+
}.merge!(extra_params),
|
39
|
+
model)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.search_where_clause(t, search_key)
|
43
|
+
super.or(t[:stripe_customer_id].eq(search_key))
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.stripe_customer_id_from_kb_account_id(kb_account_id, tenant_id)
|
47
|
+
pms = from_kb_account_id(kb_account_id, tenant_id)
|
48
|
+
return nil if pms.empty?
|
49
|
+
|
50
|
+
stripe_customer_ids = Set.new
|
51
|
+
pms.each { |pm| stripe_customer_ids << pm.stripe_customer_id }
|
52
|
+
raise "No Stripe customer id found for account #{kb_account_id}" if stripe_customer_ids.empty?
|
53
|
+
raise "Kill Bill account #{kb_account_id} mapping to multiple Stripe customers: #{stripe_customer_ids}" if stripe_customer_ids.size > 1
|
54
|
+
stripe_customer_ids.first
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Killbill #:nodoc:
|
2
|
+
module Stripe #:nodoc:
|
3
|
+
class StripeResponse < ::Killbill::Plugin::ActiveMerchant::ActiveRecord::Response
|
4
|
+
|
5
|
+
self.table_name = 'stripe_responses'
|
6
|
+
|
7
|
+
has_one :stripe_transaction
|
8
|
+
|
9
|
+
def self.from_response(api_call, kb_account_id, kb_payment_id, kb_payment_transaction_id, transaction_type, payment_processor_account_id, kb_tenant_id, response, extra_params = {}, model = ::Killbill::Stripe::StripeResponse)
|
10
|
+
super(api_call,
|
11
|
+
kb_account_id,
|
12
|
+
kb_payment_id,
|
13
|
+
kb_payment_transaction_id,
|
14
|
+
transaction_type,
|
15
|
+
payment_processor_account_id,
|
16
|
+
kb_tenant_id,
|
17
|
+
response,
|
18
|
+
{
|
19
|
+
:params_id => extract(response, 'id'),
|
20
|
+
:params_object => extract(response, 'object'),
|
21
|
+
:params_created => extract(response, 'created'),
|
22
|
+
:params_livemode => extract(response, 'livemode'),
|
23
|
+
:params_paid => extract(response, 'paid'),
|
24
|
+
:params_amount => extract(response, 'amount'),
|
25
|
+
:params_currency => extract(response, 'currency'),
|
26
|
+
:params_refunded => extract(response, 'refunded'),
|
27
|
+
:params_card_id => extract(response, 'card', 'id'),
|
28
|
+
:params_card_object => extract(response, 'card', 'object'),
|
29
|
+
:params_card_last4 => extract(response, 'card', 'last4'),
|
30
|
+
:params_card_type => extract(response, 'card', 'type'),
|
31
|
+
:params_card_exp_month => extract(response, 'card', 'exp_month'),
|
32
|
+
:params_card_exp_year => extract(response, 'card', 'exp_year'),
|
33
|
+
:params_card_fingerprint => extract(response, 'card', 'fingerprint'),
|
34
|
+
:params_card_customer => extract(response, 'card', 'customer'),
|
35
|
+
:params_card_country => extract(response, 'card', 'country'),
|
36
|
+
:params_card_name => extract(response, 'card', 'name'),
|
37
|
+
:params_card_address_line1 => extract(response, 'card', 'address_line1'),
|
38
|
+
:params_card_address_line2 => extract(response, 'card', 'address_line2'),
|
39
|
+
:params_card_address_city => extract(response, 'card', 'address_city'),
|
40
|
+
:params_card_address_state => extract(response, 'card', 'address_state'),
|
41
|
+
:params_card_address_zip => extract(response, 'card', 'address_zip'),
|
42
|
+
:params_card_address_country => extract(response, 'card', 'address_country'),
|
43
|
+
:params_card_cvc_check => extract(response, 'card', 'cvc_check'),
|
44
|
+
:params_card_address_line1_check => extract(response, 'card', 'address_line1_check'),
|
45
|
+
:params_card_address_zip_check => extract(response, 'card', 'address_zip_check'),
|
46
|
+
:params_captured => extract(response, 'captured'),
|
47
|
+
:params_refunds => extract(response, 'refunds'),
|
48
|
+
:params_balance_transaction => extract(response, 'balance_transaction'),
|
49
|
+
:params_failure_message => extract(response, 'failure_message'),
|
50
|
+
:params_failure_code => extract(response, 'failure_code'),
|
51
|
+
:params_amount_refunded => extract(response, 'amount_refunded'),
|
52
|
+
:params_customer => extract(response, 'customer'),
|
53
|
+
:params_email => extract(response, 'email'),
|
54
|
+
:params_delinquent => extract(response, 'delinquent'),
|
55
|
+
:params_subscription => extract(response, 'subscription'),
|
56
|
+
:params_discount => extract(response, 'discount'),
|
57
|
+
:params_account_balance => extract(response, 'account_balance'),
|
58
|
+
:params_cards => extract(response, 'cards'),
|
59
|
+
:params_invoice => extract(response, 'invoice'),
|
60
|
+
:params_description => extract(response, 'description'),
|
61
|
+
:params_dispute => extract(response, 'dispute'),
|
62
|
+
:params_metadata => extract(response, 'metadata'),
|
63
|
+
:params_error_type => extract(response, 'error', 'type'),
|
64
|
+
:params_error_message => extract(response, 'error', 'message')
|
65
|
+
}.merge!(extra_params),
|
66
|
+
model)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.search_where_clause(t, search_key)
|
70
|
+
where_clause = t[:params_id].eq(search_key)
|
71
|
+
.or(t[:params_card_id].eq(search_key))
|
72
|
+
|
73
|
+
# Only search successful payments and refunds
|
74
|
+
where_clause = where_clause.and(t[:success].eq(true))
|
75
|
+
|
76
|
+
super.or(where_clause)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/stripe/private_api.rb
CHANGED
@@ -1,52 +1,34 @@
|
|
1
|
-
module Killbill
|
2
|
-
|
3
|
-
|
1
|
+
module Killbill #:nodoc:
|
2
|
+
module Stripe #:nodoc:
|
3
|
+
class PrivatePaymentPlugin < ::Killbill::Plugin::ActiveMerchant::PrivatePaymentPlugin
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
def add_payment_method(params)
|
6
|
+
stripe_customer_id = StripePaymentMethod.stripe_customer_id_from_kb_account_id(params[:kbAccountId], params[:kbTenantId])
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
# This will either update the current customer if present, or create a new one
|
9
|
+
stripe_response = gateway.store params[:stripeToken], {:description => params[:kbAccountId], :customer => stripe_customer_id}
|
10
|
+
response = save_response stripe_response, :add_payment_method
|
11
|
+
raise response.message unless response.success
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
def save_response(stripe_response, api_call)
|
34
|
-
logger.warn "Unsuccessful #{api_call}: #{stripe_response.message}" unless stripe_response.success?
|
35
|
-
|
36
|
-
# Save the response to our logs
|
37
|
-
response = StripeResponse.from_response(api_call, nil, stripe_response)
|
38
|
-
response.save!
|
39
|
-
response
|
40
|
-
end
|
41
|
-
|
42
|
-
def gateway
|
43
|
-
# The gateway should have been configured when the plugin started
|
44
|
-
Killbill::Stripe.gateway
|
45
|
-
end
|
46
|
-
|
47
|
-
def logger
|
48
|
-
# The logger should have been configured when the plugin started
|
49
|
-
Killbill::Stripe.logger
|
13
|
+
# Create the payment method (not associated to a Kill Bill payment method yet)
|
14
|
+
Killbill::Stripe::StripePaymentMethod.create! :kb_account_id => params[:kbAccountId],
|
15
|
+
:kb_payment_method_id => nil,
|
16
|
+
:kb_tenant_id => params[:kbTenantId],
|
17
|
+
:stripe_customer_id => stripe_customer_id,
|
18
|
+
:token => params[:stripeToken],
|
19
|
+
:cc_first_name => params[:stripeCardName],
|
20
|
+
:cc_last_name => nil,
|
21
|
+
:cc_type => params[:stripeCardType],
|
22
|
+
:cc_exp_month => params[:stripeCardExpMonth],
|
23
|
+
:cc_exp_year => params[:stripeCardExpYear],
|
24
|
+
:cc_last_4 => params[:stripeCardLast4],
|
25
|
+
:address1 => params[:stripeCardAddressLine1],
|
26
|
+
:address2 => params[:stripeCardAddressLine2],
|
27
|
+
:city => params[:stripeCardAddressCity],
|
28
|
+
:state => params[:stripeCardAddressState],
|
29
|
+
:zip => params[:stripeCardAddressZip],
|
30
|
+
:country => params[:stripeCardAddressCountry] || params[:stripeCardCountry]
|
31
|
+
end
|
50
32
|
end
|
51
33
|
end
|
52
34
|
end
|
data/pom.xml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<!--
|
3
|
-
~ Copyright
|
3
|
+
~ Copyright 2014 The Billing Project, LLC
|
4
4
|
~
|
5
|
-
~
|
5
|
+
~ The Billing Project licenses this file to you under the Apache License, version 2.0
|
6
6
|
~ (the "License"); you may not use this file except in compliance with the
|
7
7
|
~ License. You may obtain a copy of the License at:
|
8
8
|
~
|
@@ -25,7 +25,7 @@
|
|
25
25
|
<groupId>org.kill-bill.billing.plugin.ruby</groupId>
|
26
26
|
<artifactId>stripe-plugin</artifactId>
|
27
27
|
<packaging>pom</packaging>
|
28
|
-
<version>0.
|
28
|
+
<version>0.2.0</version>
|
29
29
|
<name>stripe-plugin</name>
|
30
30
|
<url>http://github.com/killbill/killbill-stripe-plugin</url>
|
31
31
|
<description>Plugin for accessing Stripe as a payment gateway</description>
|
data/release.sh
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
set -e
|
2
2
|
|
3
|
-
if [
|
4
|
-
echo
|
3
|
+
if [ 'GNU' != "$(tar --help | grep GNU | head -1 | awk '{print $1}')" ]; then
|
4
|
+
echo 'Unable to release: make sure to use GNU tar'
|
5
5
|
exit 1
|
6
6
|
fi
|
7
7
|
|
8
8
|
if $(ruby -e'require "java"'); then
|
9
9
|
# Good
|
10
|
-
echo
|
10
|
+
echo 'Detected JRuby'
|
11
11
|
else
|
12
|
-
echo
|
12
|
+
echo 'Unable to release: make sure to use JRuby'
|
13
13
|
exit 1
|
14
14
|
fi
|
15
15
|
|
16
16
|
VERSION=`grep -E '<version>([0-9]+\.[0-9]+\.[0-9]+)</version>' pom.xml | sed 's/[\t \n]*<version>\(.*\)<\/version>[\t \n]*/\1/'`
|
17
17
|
if [ "$VERSION" != "$(cat $PWD/VERSION)" ]; then
|
18
|
-
echo
|
18
|
+
echo 'Unable to release: make sure the versions in pom.xml and VERSION match'
|
19
19
|
exit 1
|
20
20
|
fi
|
21
21
|
|
22
|
-
echo
|
22
|
+
echo 'Cleaning up'
|
23
23
|
rake killbill:clean ; rake build
|
24
24
|
|
25
|
-
echo
|
25
|
+
echo 'Pushing the gem to Rubygems'
|
26
26
|
rake release
|
27
27
|
|
28
|
-
echo
|
28
|
+
echo 'Building artifact'
|
29
29
|
rake killbill:package
|
30
30
|
|
31
31
|
ARTIFACT="$PWD/pkg/killbill-stripe-$VERSION.tar.gz"
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
require 'stripe'
|
3
|
+
require 'killbill/helpers/active_merchant/killbill_spec_helper'
|
3
4
|
|
4
5
|
require 'logger'
|
5
6
|
|
@@ -13,25 +14,11 @@ end
|
|
13
14
|
|
14
15
|
require 'active_record'
|
15
16
|
ActiveRecord::Base.establish_connection(
|
16
|
-
|
17
|
-
|
17
|
+
:adapter => 'sqlite3',
|
18
|
+
:database => 'test.db'
|
18
19
|
)
|
19
20
|
# For debugging
|
20
21
|
#ActiveRecord::Base.logger = Logger.new(STDOUT)
|
21
22
|
# Create the schema
|
22
23
|
require File.expand_path(File.dirname(__FILE__) + '../../db/schema.rb')
|
23
24
|
|
24
|
-
begin
|
25
|
-
require 'securerandom'
|
26
|
-
SecureRandom.uuid
|
27
|
-
rescue LoadError, NoMethodError
|
28
|
-
# See http://jira.codehaus.org/browse/JRUBY-6176
|
29
|
-
module SecureRandom
|
30
|
-
def self.uuid
|
31
|
-
ary = self.random_bytes(16).unpack("NnnnnN")
|
32
|
-
ary[2] = (ary[2] & 0x0fff) | 0x4000
|
33
|
-
ary[3] = (ary[3] & 0x3fff) | 0x8000
|
34
|
-
"%08x-%04x-%04x-%04x-%04x%08x" % ary
|
35
|
-
end unless respond_to?(:uuid)
|
36
|
-
end
|
37
|
-
end
|
@@ -14,10 +14,12 @@ describe Killbill::Stripe::PaymentPlugin do
|
|
14
14
|
eos
|
15
15
|
file.close
|
16
16
|
|
17
|
-
@plugin
|
18
|
-
@plugin.logger
|
17
|
+
@plugin = Killbill::Stripe::PaymentPlugin.new
|
18
|
+
@plugin.logger = Logger.new(STDOUT)
|
19
19
|
@plugin.logger.level = Logger::INFO
|
20
|
-
@plugin.conf_dir
|
20
|
+
@plugin.conf_dir = File.dirname(file)
|
21
|
+
@account_api = ::Killbill::Plugin::ActiveMerchant::RSpec::FakeJavaUserAccountApi.new
|
22
|
+
@plugin.kb_apis = Killbill::Plugin::KillbillApi.new('stripe', {})
|
21
23
|
|
22
24
|
# Start the plugin here - since the config file will be deleted
|
23
25
|
@plugin.start_plugin
|
@@ -30,15 +32,18 @@ describe Killbill::Stripe::PaymentPlugin do
|
|
30
32
|
|
31
33
|
it 'should reset payment methods' do
|
32
34
|
kb_account_id = '129384'
|
35
|
+
kb_tenant_id = '092384'
|
36
|
+
context = @plugin.kb_apis.create_context(kb_tenant_id)
|
33
37
|
|
34
|
-
@plugin.get_payment_methods(kb_account_id).size.should == 0
|
35
|
-
verify_pms kb_account_id, 0
|
38
|
+
@plugin.get_payment_methods(kb_account_id, false, [], context).size.should == 0
|
39
|
+
verify_pms kb_account_id, 0, context
|
36
40
|
|
37
41
|
# Create a pm with a kb_payment_method_id
|
38
|
-
Killbill::Stripe::StripePaymentMethod.create :kb_account_id
|
42
|
+
Killbill::Stripe::StripePaymentMethod.create :kb_account_id => kb_account_id,
|
43
|
+
:kb_tenant_id => kb_tenant_id,
|
39
44
|
:kb_payment_method_id => 'kb-1',
|
40
|
-
:
|
41
|
-
verify_pms kb_account_id, 1
|
45
|
+
:token => 'stripe-1'
|
46
|
+
verify_pms kb_account_id, 1, context
|
42
47
|
|
43
48
|
# Add some in KillBill and reset
|
44
49
|
payment_methods = []
|
@@ -46,26 +51,27 @@ describe Killbill::Stripe::PaymentPlugin do
|
|
46
51
|
payment_methods << create_pm_info_plugin(kb_account_id, 'kb-3', false, 'stripe-3')
|
47
52
|
payment_methods << create_pm_info_plugin(kb_account_id, 'kb-2', false, 'stripe-2')
|
48
53
|
payment_methods << create_pm_info_plugin(kb_account_id, 'kb-4', false, 'stripe-4')
|
49
|
-
@plugin.reset_payment_methods kb_account_id, payment_methods
|
50
|
-
verify_pms kb_account_id, 4
|
54
|
+
@plugin.reset_payment_methods kb_account_id, payment_methods, [], context
|
55
|
+
verify_pms kb_account_id, 4, context
|
51
56
|
|
52
57
|
# Add a payment method without a kb_payment_method_id
|
53
58
|
Killbill::Stripe::StripePaymentMethod.create :kb_account_id => kb_account_id,
|
54
|
-
:
|
55
|
-
|
59
|
+
:kb_tenant_id => kb_tenant_id,
|
60
|
+
:token => 'stripe-5'
|
61
|
+
@plugin.get_payment_methods(kb_account_id, false, nil, context).size.should == 5
|
56
62
|
|
57
63
|
# Verify we can match it
|
58
64
|
payment_methods << create_pm_info_plugin(kb_account_id, 'kb-5', false, 'stripe-5')
|
59
|
-
@plugin.reset_payment_methods kb_account_id, payment_methods
|
60
|
-
verify_pms kb_account_id, 5
|
65
|
+
@plugin.reset_payment_methods kb_account_id, payment_methods, [], context
|
66
|
+
verify_pms kb_account_id, 5, context
|
61
67
|
|
62
68
|
@plugin.stop_plugin
|
63
69
|
end
|
64
70
|
|
65
71
|
private
|
66
72
|
|
67
|
-
def verify_pms(kb_account_id, size)
|
68
|
-
pms = @plugin.get_payment_methods(kb_account_id)
|
73
|
+
def verify_pms(kb_account_id, size, context)
|
74
|
+
pms = @plugin.get_payment_methods(kb_account_id, false, [], context)
|
69
75
|
pms.size.should == size
|
70
76
|
pms.each do |pm|
|
71
77
|
pm.account_id.should == kb_account_id
|
@@ -75,10 +81,10 @@ describe Killbill::Stripe::PaymentPlugin do
|
|
75
81
|
end
|
76
82
|
|
77
83
|
def create_pm_info_plugin(kb_account_id, kb_payment_method_id, is_default, external_payment_method_id)
|
78
|
-
pm_info_plugin
|
79
|
-
pm_info_plugin.account_id
|
80
|
-
pm_info_plugin.payment_method_id
|
81
|
-
pm_info_plugin.is_default
|
84
|
+
pm_info_plugin = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
|
85
|
+
pm_info_plugin.account_id = kb_account_id
|
86
|
+
pm_info_plugin.payment_method_id = kb_payment_method_id
|
87
|
+
pm_info_plugin.is_default = is_default
|
82
88
|
pm_info_plugin.external_payment_method_id = external_payment_method_id
|
83
89
|
pm_info_plugin
|
84
90
|
end
|