killbill-paypal-express 1.0.14 → 1.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/paypal_express/api.rb +34 -1
- data/lib/paypal_express/models/paypal_express_payment_method.rb +7 -8
- data/pom.xml +1 -1
- data/spec/paypal_express/base_plugin_spec.rb +52 -4
- data/spec/spec_helper.rb +4 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.15
|
data/lib/paypal_express/api.rb
CHANGED
@@ -129,7 +129,40 @@ module Killbill::PaypalExpress
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def reset_payment_methods(kb_account_id, payment_methods)
|
132
|
-
|
132
|
+
return if payment_methods.nil?
|
133
|
+
|
134
|
+
paypal_pms = PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id.to_s)
|
135
|
+
|
136
|
+
payment_methods.delete_if do |payment_method_info_plugin|
|
137
|
+
should_be_deleted = false
|
138
|
+
paypal_pms.each do |paypal_pm|
|
139
|
+
# Do paypal_pm and payment_method_info_plugin represent the same PayPal payment method?
|
140
|
+
if paypal_pm.external_payment_method_id == payment_method_info_plugin.external_payment_method_id
|
141
|
+
# Do we already have a kb_payment_method_id?
|
142
|
+
if paypal_pm.kb_payment_method_id == payment_method_info_plugin.payment_method_id.to_s
|
143
|
+
should_be_deleted = true
|
144
|
+
break
|
145
|
+
elsif paypal_pm.kb_payment_method_id.nil?
|
146
|
+
# We didn't have the kb_payment_method_id - update it
|
147
|
+
paypal_pm.kb_payment_method_id = payment_method_info_plugin.payment_method_id.to_s
|
148
|
+
should_be_deleted = paypal_pm.save
|
149
|
+
break
|
150
|
+
# Otherwise the same BAID points to 2 different kb_payment_method_id. This should never happen,
|
151
|
+
# but we cowardly will insert a second row below
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
should_be_deleted
|
157
|
+
end
|
158
|
+
|
159
|
+
# The remaining elements in payment_methods are not in our table (this should never happen?!)
|
160
|
+
payment_methods.each do |payment_method_info_plugin|
|
161
|
+
PaypalExpressPaymentMethod.create :kb_account_id => payment_method_info_plugin.account_id.to_s,
|
162
|
+
:kb_payment_method_id => payment_method_info_plugin.payment_method_id.to_s,
|
163
|
+
:paypal_express_baid => payment_method_info_plugin.external_payment_method_id,
|
164
|
+
:paypal_express_token => 'unknown (created by reset)'
|
165
|
+
end
|
133
166
|
end
|
134
167
|
|
135
168
|
private
|
@@ -6,6 +6,8 @@ module Killbill::PaypalExpress
|
|
6
6
|
:paypal_express_baid,
|
7
7
|
:paypal_express_token
|
8
8
|
|
9
|
+
alias_attribute :external_payment_method_id, :paypal_express_baid
|
10
|
+
|
9
11
|
def self.from_kb_account_id(kb_account_id)
|
10
12
|
find_all_by_kb_account_id_and_is_deleted(kb_account_id, false)
|
11
13
|
end
|
@@ -32,10 +34,6 @@ module Killbill::PaypalExpress
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def to_payment_method_response
|
35
|
-
external_payment_method_id = paypal_express_baid
|
36
|
-
# No concept of default payment method in Paypal Express
|
37
|
-
is_default = false
|
38
|
-
|
39
37
|
properties = []
|
40
38
|
properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'payerId', paypal_express_payer_id)
|
41
39
|
properties << Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, 'baid', paypal_express_baid)
|
@@ -60,11 +58,12 @@ module Killbill::PaypalExpress
|
|
60
58
|
end
|
61
59
|
|
62
60
|
def to_payment_method_info_response
|
63
|
-
external_payment_method_id = paypal_express_baid
|
64
|
-
# No concept of default payment method in Paypal Express
|
65
|
-
is_default = false
|
66
|
-
|
67
61
|
Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, kb_payment_method_id, is_default, external_payment_method_id)
|
68
62
|
end
|
63
|
+
|
64
|
+
def is_default
|
65
|
+
# No concept of default payment method in Paypal Express
|
66
|
+
false
|
67
|
+
end
|
69
68
|
end
|
70
69
|
end
|
data/pom.xml
CHANGED
@@ -25,7 +25,7 @@
|
|
25
25
|
<groupId>com.ning.killbill.ruby</groupId>
|
26
26
|
<artifactId>paypal-express-plugin</artifactId>
|
27
27
|
<packaging>pom</packaging>
|
28
|
-
<version>1.0.
|
28
|
+
<version>1.0.15</version>
|
29
29
|
<name>paypal-express-plugin</name>
|
30
30
|
<url>http://github.com/killbill/killbill-paypal-express-plugin</url>
|
31
31
|
<description>Plugin for accessing paypal as a payment gateway</description>
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'logger'
|
3
2
|
|
4
3
|
describe Killbill::PaypalExpress::PaymentPlugin do
|
5
4
|
before(:each) do
|
@@ -10,10 +9,11 @@ describe Killbill::PaypalExpress::PaymentPlugin do
|
|
10
9
|
:signature: 'signature'
|
11
10
|
:login: 'login'
|
12
11
|
:password: 'password'
|
12
|
+
# As defined by spec_helper.rb
|
13
13
|
:database:
|
14
14
|
:adapter: 'sqlite3'
|
15
|
-
:database: '
|
16
|
-
eos
|
15
|
+
:database: 'test.db'
|
16
|
+
eos
|
17
17
|
file.close
|
18
18
|
|
19
19
|
@plugin = Killbill::PaypalExpress::PaymentPlugin.new
|
@@ -25,7 +25,55 @@ eos
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'should start and stop correctly' do
|
29
29
|
@plugin.stop_plugin
|
30
30
|
end
|
31
|
+
|
32
|
+
it 'should reset payment methods' do
|
33
|
+
kb_account_id = '129384'
|
34
|
+
|
35
|
+
@plugin.get_payment_methods(kb_account_id, false, nil).size.should == 0
|
36
|
+
verify_pms kb_account_id, 0
|
37
|
+
|
38
|
+
# Create a pm with a kb_payment_method_id
|
39
|
+
Killbill::PaypalExpress::PaypalExpressPaymentMethod.create :kb_account_id => kb_account_id,
|
40
|
+
:kb_payment_method_id => 'kb-1',
|
41
|
+
:paypal_express_token => 'doesnottmatter',
|
42
|
+
:paypal_express_baid => 'paypal-1'
|
43
|
+
verify_pms kb_account_id, 1
|
44
|
+
|
45
|
+
# Add some in KillBill and reset
|
46
|
+
payment_methods = []
|
47
|
+
# Random order... Shouldn't matter...
|
48
|
+
payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-3', false, 'paypal-3')
|
49
|
+
payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-2', false, 'paypal-2')
|
50
|
+
payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-4', false, 'paypal-4')
|
51
|
+
@plugin.reset_payment_methods kb_account_id, payment_methods
|
52
|
+
verify_pms kb_account_id, 4
|
53
|
+
|
54
|
+
# Add a payment method without a kb_payment_method_id
|
55
|
+
Killbill::PaypalExpress::PaypalExpressPaymentMethod.create :kb_account_id => kb_account_id,
|
56
|
+
:paypal_express_token => 'doesnottmatter',
|
57
|
+
:paypal_express_baid => 'paypal-5'
|
58
|
+
@plugin.get_payment_methods(kb_account_id, false, nil).size.should == 5
|
59
|
+
|
60
|
+
# Verify we can match it
|
61
|
+
payment_methods << Killbill::Plugin::Model::PaymentMethodInfoPlugin.new(kb_account_id, 'kb-5', false, 'paypal-5')
|
62
|
+
@plugin.reset_payment_methods kb_account_id, payment_methods
|
63
|
+
verify_pms kb_account_id, 5
|
64
|
+
|
65
|
+
@plugin.stop_plugin
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def verify_pms(kb_account_id, size)
|
71
|
+
pms = @plugin.get_payment_methods(kb_account_id, false, nil)
|
72
|
+
pms.size.should == size
|
73
|
+
pms.each do |pm|
|
74
|
+
pm.account_id.should == kb_account_id
|
75
|
+
pm.is_default.should == false
|
76
|
+
pm.external_payment_method_id.should == 'paypal-' + pm.payment_method_id.split('-')[1]
|
77
|
+
end
|
78
|
+
end
|
31
79
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
require 'paypal_express'
|
3
3
|
|
4
|
+
require 'logger'
|
5
|
+
|
4
6
|
require 'rspec'
|
5
7
|
|
6
8
|
RSpec.configure do |config|
|
@@ -11,8 +13,8 @@ end
|
|
11
13
|
|
12
14
|
require 'active_record'
|
13
15
|
ActiveRecord::Base.establish_connection(
|
14
|
-
|
15
|
-
|
16
|
+
:adapter => 'sqlite3',
|
17
|
+
:database => 'test.db'
|
16
18
|
)
|
17
19
|
# Create the schema
|
18
20
|
require File.expand_path(File.dirname(__FILE__) + '../../db/schema.rb')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-paypal-express
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: killbill
|