killbill-paypal-express 1.0.6 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/VERSION +1 -1
- data/killbill-paypal-express.gemspec +1 -1
- data/lib/paypal_express/api.rb +26 -26
- data/pom.xml +1 -1
- data/spec/paypal_express/remote/integration_spec.rb +32 -23
- metadata +5 -5
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.8
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.rdoc_options << '--exclude' << '.'
|
24
24
|
|
25
|
-
s.add_dependency 'killbill', '~> 1.0.
|
25
|
+
s.add_dependency 'killbill', '~> 1.0.17'
|
26
26
|
s.add_dependency 'activemerchant', '~> 2.0.0'
|
27
27
|
s.add_dependency 'activerecord', '~> 3.2.1'
|
28
28
|
s.add_dependency 'sinatra', '~> 1.3.4'
|
data/lib/paypal_express/api.rb
CHANGED
@@ -16,19 +16,19 @@ module Killbill::PaypalExpress
|
|
16
16
|
ActiveRecord::Base.connection.close
|
17
17
|
end
|
18
18
|
|
19
|
-
def process_payment(kb_account_id, kb_payment_id, kb_payment_method_id, amount_in_cents, currency, options = {})
|
19
|
+
def process_payment(kb_account_id, kb_payment_id, kb_payment_method_id, amount_in_cents, currency, call_context, options = {})
|
20
20
|
# If the payment was already made, just return the status
|
21
|
-
paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id) rescue nil
|
21
|
+
paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id.to_s) rescue nil
|
22
22
|
return paypal_express_transaction.paypal_express_response.to_payment_response unless paypal_express_transaction.nil?
|
23
23
|
|
24
|
-
options[:currency] ||= currency
|
24
|
+
options[:currency] ||= currency.respond_to?(:enum) ? currency.enum : currency.to_s
|
25
25
|
options[:payment_type] ||= 'Any'
|
26
|
-
options[:invoice_id] ||= kb_payment_id
|
26
|
+
options[:invoice_id] ||= kb_payment_id.to_s
|
27
27
|
options[:description] ||= "Kill Bill payment for #{kb_payment_id}"
|
28
28
|
options[:ip] ||= @ip
|
29
29
|
|
30
30
|
if options[:reference_id].blank?
|
31
|
-
payment_method = PaypalExpressPaymentMethod.from_kb_payment_method_id(kb_payment_method_id)
|
31
|
+
payment_method = PaypalExpressPaymentMethod.from_kb_payment_method_id(kb_payment_method_id.to_s)
|
32
32
|
options[:reference_id] = payment_method.paypal_express_baid
|
33
33
|
end
|
34
34
|
|
@@ -39,10 +39,10 @@ module Killbill::PaypalExpress
|
|
39
39
|
response.to_payment_response
|
40
40
|
end
|
41
41
|
|
42
|
-
def process_refund(kb_account_id, kb_payment_id, amount_in_cents, currency, options = {})
|
43
|
-
paypal_express_transaction = PaypalExpressTransaction.find_candidate_transaction_for_refund(kb_payment_id, amount_in_cents)
|
42
|
+
def process_refund(kb_account_id, kb_payment_id, amount_in_cents, currency, call_context, options = {})
|
43
|
+
paypal_express_transaction = PaypalExpressTransaction.find_candidate_transaction_for_refund(kb_payment_id.to_s, amount_in_cents)
|
44
44
|
|
45
|
-
options[:currency] ||= currency
|
45
|
+
options[:currency] ||= currency.respond_to?(:enum) ? currency.enum : currency.to_s
|
46
46
|
options[:refund_type] ||= paypal_express_transaction.amount_in_cents != amount_in_cents ? 'Partial' : 'Full'
|
47
47
|
|
48
48
|
identification = paypal_express_transaction.paypal_express_txn_id
|
@@ -54,25 +54,25 @@ module Killbill::PaypalExpress
|
|
54
54
|
response.to_refund_response
|
55
55
|
end
|
56
56
|
|
57
|
-
def get_payment_info(kb_account_id, kb_payment_id, options = {})
|
58
|
-
paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id)
|
57
|
+
def get_payment_info(kb_account_id, kb_payment_id, tenant_context, options = {})
|
58
|
+
paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id.to_s)
|
59
59
|
|
60
60
|
begin
|
61
61
|
transaction_id = paypal_express_transaction.paypal_express_txn_id
|
62
62
|
response = @gateway.transaction_details transaction_id
|
63
|
-
PaypalExpressResponse.from_response(:transaction_details, kb_payment_id, response).to_payment_response
|
63
|
+
PaypalExpressResponse.from_response(:transaction_details, kb_payment_id.to_s, response).to_payment_response
|
64
64
|
rescue => e
|
65
|
-
@logger.warn("Exception while retrieving Paypal Express transaction detail for payment #{kb_payment_id}, defaulting to cached response: #{e}")
|
65
|
+
@logger.warn("Exception while retrieving Paypal Express transaction detail for payment #{kb_payment_id.to_s}, defaulting to cached response: #{e}")
|
66
66
|
paypal_express_transaction.paypal_express_response.to_payment_response
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default
|
71
|
-
token = payment_method_props.
|
70
|
+
def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, call_context, options = {})
|
71
|
+
token = (payment_method_props.properties.find { |kv| kv.key == 'token' }).value
|
72
72
|
return false if token.nil?
|
73
73
|
|
74
74
|
# The payment method should have been created during the setup step (see private api)
|
75
|
-
payment_method = PaypalExpressPaymentMethod.from_kb_account_id_and_token(kb_account_id, token)
|
75
|
+
payment_method = PaypalExpressPaymentMethod.from_kb_account_id_and_token(kb_account_id.to_s, token)
|
76
76
|
|
77
77
|
# Go to Paypal to get the Payer id (GetExpressCheckoutDetails call)
|
78
78
|
paypal_express_details_response = @gateway.details_for token
|
@@ -86,29 +86,29 @@ module Killbill::PaypalExpress
|
|
86
86
|
response = save_response_and_transaction paypal_express_baid_response, :create_billing_agreement
|
87
87
|
return false unless response.success?
|
88
88
|
|
89
|
-
payment_method.kb_payment_method_id = kb_payment_method_id
|
89
|
+
payment_method.kb_payment_method_id = kb_payment_method_id.to_s
|
90
90
|
payment_method.paypal_express_payer_id = payer_id
|
91
91
|
payment_method.paypal_express_baid = response.billing_agreement_id
|
92
92
|
payment_method.save!
|
93
93
|
|
94
|
-
logger.info "Created BAID #{payment_method.paypal_express_baid} for payment method #{kb_payment_method_id} (account #{kb_account_id})"
|
94
|
+
logger.info "Created BAID #{payment_method.paypal_express_baid} for payment method #{kb_payment_method_id.to_s} (account #{kb_account_id.to_s})"
|
95
95
|
true
|
96
96
|
else
|
97
|
-
logger.warn "Unable to retrieve Payer id details for token #{token} (account #{kb_account_id})"
|
97
|
+
logger.warn "Unable to retrieve Payer id details for token #{token} (account #{kb_account_id.to_s})"
|
98
98
|
false
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
def delete_payment_method(kb_account_id, kb_payment_method_id, options = {})
|
103
|
-
PaypalExpressPaymentMethod.mark_as_deleted! kb_payment_method_id
|
102
|
+
def delete_payment_method(kb_account_id, kb_payment_method_id, call_context, options = {})
|
103
|
+
PaypalExpressPaymentMethod.mark_as_deleted! kb_payment_method_id.to_s
|
104
104
|
end
|
105
105
|
|
106
|
-
def get_payment_method_detail(kb_account_id, kb_payment_method_id, options = {})
|
107
|
-
PaypalExpressPaymentMethod.from_kb_payment_method_id(kb_payment_method_id).to_payment_method_response
|
106
|
+
def get_payment_method_detail(kb_account_id, kb_payment_method_id, tenant_context, options = {})
|
107
|
+
PaypalExpressPaymentMethod.from_kb_payment_method_id(kb_payment_method_id.to_s).to_payment_method_response
|
108
108
|
end
|
109
109
|
|
110
|
-
def get_payment_methods(kb_account_id, refresh_from_gateway
|
111
|
-
PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id).collect { |pm| pm.to_payment_method_response }
|
110
|
+
def get_payment_methods(kb_account_id, refresh_from_gateway, call_context, options = {})
|
111
|
+
PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id.to_s).collect { |pm| pm.to_payment_method_response }
|
112
112
|
end
|
113
113
|
|
114
114
|
private
|
@@ -117,12 +117,12 @@ module Killbill::PaypalExpress
|
|
117
117
|
@logger.warn "Unsuccessful #{api_call}: #{paypal_express_response.message}" unless paypal_express_response.success?
|
118
118
|
|
119
119
|
# Save the response to our logs
|
120
|
-
response = PaypalExpressResponse.from_response(api_call, kb_payment_id, paypal_express_response)
|
120
|
+
response = PaypalExpressResponse.from_response(api_call, kb_payment_id.to_s, paypal_express_response)
|
121
121
|
response.save!
|
122
122
|
|
123
123
|
if response.success and !kb_payment_id.blank? and !response.authorization.blank?
|
124
124
|
# Record the transaction
|
125
|
-
transaction = response.create_paypal_express_transaction!(:amount_in_cents => amount_in_cents, :api_call => api_call, :kb_payment_id => kb_payment_id, :paypal_express_txn_id => response.authorization)
|
125
|
+
transaction = response.create_paypal_express_transaction!(:amount_in_cents => amount_in_cents, :api_call => api_call, :kb_payment_id => kb_payment_id.to_s, :paypal_express_txn_id => response.authorization)
|
126
126
|
@logger.debug "Recorded transaction: #{transaction.inspect}"
|
127
127
|
end
|
128
128
|
response
|
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.8</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>
|
@@ -15,6 +15,15 @@ describe Killbill::PaypalExpress::PaymentPlugin do
|
|
15
15
|
@plugin.start_plugin
|
16
16
|
|
17
17
|
@pm = create_payment_method
|
18
|
+
@call_context = Killbill::Plugin::Model::CallContext.new(SecureRandom.uuid,
|
19
|
+
'token',
|
20
|
+
'rspec tester',
|
21
|
+
'TEST',
|
22
|
+
'user',
|
23
|
+
'testing',
|
24
|
+
'this is from a test',
|
25
|
+
Time.now,
|
26
|
+
Time.now)
|
18
27
|
end
|
19
28
|
|
20
29
|
after(:each) do
|
@@ -26,9 +35,9 @@ describe Killbill::PaypalExpress::PaymentPlugin do
|
|
26
35
|
currency = 'USD'
|
27
36
|
kb_payment_id = SecureRandom.uuid
|
28
37
|
|
29
|
-
payment_response = @plugin.process_payment @pm.kb_account_id, kb_payment_id, @pm.kb_payment_method_id, amount_in_cents, currency
|
30
|
-
payment_response.
|
31
|
-
payment_response.status.should ==
|
38
|
+
payment_response = @plugin.process_payment @pm.kb_account_id, kb_payment_id, @pm.kb_payment_method_id, amount_in_cents, currency, @call_context
|
39
|
+
payment_response.amount.should == amount_in_cents
|
40
|
+
payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
|
32
41
|
|
33
42
|
# Verify our table directly
|
34
43
|
response = Killbill::PaypalExpress::PaypalExpressResponse.find_by_api_call_and_kb_payment_id :charge, kb_payment_id
|
@@ -37,16 +46,16 @@ describe Killbill::PaypalExpress::PaymentPlugin do
|
|
37
46
|
response.message.should == "Success"
|
38
47
|
|
39
48
|
# Check we can retrieve the payment
|
40
|
-
payment_response = @plugin.get_payment_info @pm.kb_account_id, kb_payment_id
|
41
|
-
payment_response.
|
42
|
-
payment_response.status.should ==
|
49
|
+
payment_response = @plugin.get_payment_info @pm.kb_account_id, kb_payment_id, @call_context
|
50
|
+
payment_response.amount.should == amount_in_cents
|
51
|
+
payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
|
43
52
|
|
44
53
|
# Check we cannot refund an amount greater than the original charge
|
45
|
-
lambda { @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents + 1, currency }.should raise_error RuntimeError
|
54
|
+
lambda { @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents + 1, currency, @call_context }.should raise_error RuntimeError
|
46
55
|
|
47
|
-
refund_response = @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents, currency
|
48
|
-
refund_response.
|
49
|
-
refund_response.status.should ==
|
56
|
+
refund_response = @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents, currency, @call_context
|
57
|
+
refund_response.amount.should == amount_in_cents
|
58
|
+
refund_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
|
50
59
|
|
51
60
|
# Verify our table directly
|
52
61
|
response = Killbill::PaypalExpress::PaypalExpressResponse.find_by_api_call_and_kb_payment_id :refund, kb_payment_id
|
@@ -56,29 +65,29 @@ describe Killbill::PaypalExpress::PaymentPlugin do
|
|
56
65
|
# Try another payment to verify the BAID
|
57
66
|
second_amount_in_cents = 9423
|
58
67
|
second_kb_payment_id = SecureRandom.uuid
|
59
|
-
payment_response = @plugin.process_payment @pm.kb_account_id, second_kb_payment_id, @pm.kb_payment_method_id, second_amount_in_cents, currency
|
60
|
-
payment_response.
|
61
|
-
payment_response.status.should ==
|
68
|
+
payment_response = @plugin.process_payment @pm.kb_account_id, second_kb_payment_id, @pm.kb_payment_method_id, second_amount_in_cents, currency, @call_context
|
69
|
+
payment_response.amount.should == second_amount_in_cents
|
70
|
+
payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
|
62
71
|
|
63
72
|
# Check we can refund it as well
|
64
|
-
refund_response = @plugin.process_refund @pm.kb_account_id, second_kb_payment_id, second_amount_in_cents, currency
|
65
|
-
refund_response.
|
66
|
-
refund_response.status.should ==
|
73
|
+
refund_response = @plugin.process_refund @pm.kb_account_id, second_kb_payment_id, second_amount_in_cents, currency, @call_context
|
74
|
+
refund_response.amount.should == second_amount_in_cents
|
75
|
+
refund_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
|
67
76
|
|
68
77
|
# it "should be able to create and retrieve payment methods"
|
69
78
|
# This should be in a separate scenario but since it's so hard to create a payment method (need manual intervention),
|
70
79
|
# we can't easily delete it
|
71
|
-
pms = @plugin.get_payment_methods @pm.kb_account_id
|
80
|
+
pms = @plugin.get_payment_methods @pm.kb_account_id, false, @call_context
|
72
81
|
pms.size.should == 1
|
73
82
|
pms[0].external_payment_method_id.should == @pm.paypal_express_baid
|
74
83
|
|
75
|
-
pm_details = @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id)
|
84
|
+
pm_details = @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id, @call_context)
|
76
85
|
pm_details.external_payment_method_id.should == @pm.paypal_express_baid
|
77
86
|
|
78
|
-
@plugin.delete_payment_method @pm.kb_account_id, @pm.kb_payment_method_id
|
87
|
+
@plugin.delete_payment_method @pm.kb_account_id, @pm.kb_payment_method_id, @call_context
|
79
88
|
|
80
|
-
@plugin.get_payment_methods(@pm.kb_account_id).size.should == 0
|
81
|
-
lambda { @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id) }.should raise_error RuntimeError
|
89
|
+
@plugin.get_payment_methods(@pm.kb_account_id, false, @call_context).size.should == 0
|
90
|
+
lambda { @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id, @call_context) }.should raise_error RuntimeError
|
82
91
|
end
|
83
92
|
|
84
93
|
private
|
@@ -98,8 +107,8 @@ Note: you need to log-in with a paypal sandbox account (create one here: https:/
|
|
98
107
|
|
99
108
|
# Complete the setup process
|
100
109
|
kb_payment_method_id = SecureRandom.uuid
|
101
|
-
info = Killbill::Plugin::
|
102
|
-
response = @plugin.add_payment_method kb_account_id, kb_payment_method_id, info
|
110
|
+
info = Killbill::Plugin::Model::PaymentMethodPlugin.new nil, nil, [Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, "token", token)], nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
|
111
|
+
response = @plugin.add_payment_method kb_account_id, kb_payment_method_id, info, true, @call_context
|
103
112
|
response.should be_true
|
104
113
|
|
105
114
|
# Verify our table directly
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-paypal-express
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.8
|
4
5
|
prerelease:
|
5
|
-
version: 1.0.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Killbill core team
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: killbill
|
@@ -17,13 +17,13 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 1.0.
|
20
|
+
version: 1.0.17
|
21
21
|
none: false
|
22
22
|
requirement: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0.
|
26
|
+
version: 1.0.17
|
27
27
|
none: false
|
28
28
|
prerelease: false
|
29
29
|
type: :runtime
|
@@ -210,9 +210,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
210
|
- !ruby/object:Gem::Version
|
211
211
|
segments:
|
212
212
|
- 0
|
213
|
-
hash: 2
|
214
213
|
version: !binary |-
|
215
214
|
MA==
|
215
|
+
hash: 2
|
216
216
|
none: false
|
217
217
|
requirements: []
|
218
218
|
rubyforge_project:
|