killbill-paypal-express 1.0.17 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Jarfile +4 -2
- data/NEWS +2 -0
- data/VERSION +1 -1
- data/killbill-paypal-express.gemspec +1 -1
- data/lib/paypal_express/api.rb +35 -35
- data/lib/paypal_express/models/paypal_express_payment_method.rb +37 -32
- data/lib/paypal_express/models/paypal_express_response.rb +71 -56
- data/pom.xml +1 -1
- data/spec/paypal_express/base_plugin_spec.rb +13 -4
- data/spec/paypal_express/remote/integration_spec.rb +26 -31
- metadata +5 -4
data/Jarfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
-
jar 'com.ning.billing:killbill-api', '0.
|
2
|
-
jar 'com.ning.billing:killbill-
|
1
|
+
jar 'com.ning.billing:killbill-api', '0.3.0'
|
2
|
+
jar 'com.ning.billing.plugin:killbill-plugin-api-notification', '0.2.4'
|
3
|
+
jar 'com.ning.billing.plugin:killbill-plugin-api-payment', '0.2.4'
|
4
|
+
jar 'com.ning.billing:killbill-util:tests', '0.2.6-SNAPSHOT'
|
3
5
|
jar 'javax.servlet:javax.servlet-api', '3.0.1'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
@@ -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.
|
25
|
+
s.add_dependency 'killbill', '~> 1.1.2'
|
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, call_context, options = {})
|
19
|
+
def process_payment(kb_account_id, kb_payment_id, kb_payment_method_id, amount_in_cents, currency, call_context = nil, 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
|
21
|
+
paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id) 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.to_s
|
25
25
|
options[:payment_type] ||= 'Any'
|
26
|
-
options[:invoice_id] ||= kb_payment_id
|
26
|
+
options[:invoice_id] ||= kb_payment_id
|
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)
|
32
32
|
options[:reference_id] = payment_method.paypal_express_baid
|
33
33
|
end
|
34
34
|
|
@@ -39,23 +39,23 @@ module Killbill::PaypalExpress
|
|
39
39
|
response.to_payment_response
|
40
40
|
end
|
41
41
|
|
42
|
-
def get_payment_info(kb_account_id, kb_payment_id, tenant_context, options = {})
|
43
|
-
paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id
|
42
|
+
def get_payment_info(kb_account_id, kb_payment_id, tenant_context = nil, options = {})
|
43
|
+
paypal_express_transaction = PaypalExpressTransaction.from_kb_payment_id(kb_payment_id)
|
44
44
|
|
45
45
|
begin
|
46
46
|
transaction_id = paypal_express_transaction.paypal_express_txn_id
|
47
47
|
response = @gateway.transaction_details transaction_id
|
48
|
-
PaypalExpressResponse.from_response(:transaction_details, kb_payment_id
|
48
|
+
PaypalExpressResponse.from_response(:transaction_details, kb_payment_id, response).to_payment_response
|
49
49
|
rescue => e
|
50
|
-
@logger.warn("Exception while retrieving Paypal Express transaction detail for payment #{kb_payment_id
|
50
|
+
@logger.warn("Exception while retrieving Paypal Express transaction detail for payment #{kb_payment_id}, defaulting to cached response: #{e}")
|
51
51
|
paypal_express_transaction.paypal_express_response.to_payment_response
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def process_refund(kb_account_id, kb_payment_id, amount_in_cents, currency, call_context, options = {})
|
56
|
-
paypal_express_transaction = PaypalExpressTransaction.find_candidate_transaction_for_refund(kb_payment_id
|
55
|
+
def process_refund(kb_account_id, kb_payment_id, amount_in_cents, currency, call_context = nil, options = {})
|
56
|
+
paypal_express_transaction = PaypalExpressTransaction.find_candidate_transaction_for_refund(kb_payment_id, amount_in_cents)
|
57
57
|
|
58
|
-
options[:currency] ||= currency.
|
58
|
+
options[:currency] ||= currency.to_s
|
59
59
|
options[:refund_type] ||= paypal_express_transaction.amount_in_cents != amount_in_cents ? 'Partial' : 'Full'
|
60
60
|
|
61
61
|
identification = paypal_express_transaction.paypal_express_txn_id
|
@@ -67,25 +67,25 @@ module Killbill::PaypalExpress
|
|
67
67
|
response.to_refund_response
|
68
68
|
end
|
69
69
|
|
70
|
-
def get_refund_info(kb_account_id, kb_payment_id, tenant_context, options = {})
|
71
|
-
paypal_express_transaction = PaypalExpressTransaction.refund_from_kb_payment_id(kb_payment_id
|
70
|
+
def get_refund_info(kb_account_id, kb_payment_id, tenant_context = nil, options = {})
|
71
|
+
paypal_express_transaction = PaypalExpressTransaction.refund_from_kb_payment_id(kb_payment_id)
|
72
72
|
|
73
73
|
begin
|
74
74
|
transaction_id = paypal_express_transaction.paypal_express_txn_id
|
75
75
|
response = @gateway.transaction_details transaction_id
|
76
|
-
PaypalExpressResponse.from_response(:transaction_details, kb_payment_id
|
76
|
+
PaypalExpressResponse.from_response(:transaction_details, kb_payment_id, response).to_refund_response
|
77
77
|
rescue => e
|
78
|
-
@logger.warn("Exception while retrieving Paypal Express transaction detail for payment #{kb_payment_id
|
78
|
+
@logger.warn("Exception while retrieving Paypal Express transaction detail for payment #{kb_payment_id}, defaulting to cached response: #{e}")
|
79
79
|
paypal_express_transaction.paypal_express_response.to_refund_response
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, call_context, options = {})
|
83
|
+
def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default = false, call_context = nil, options = {})
|
84
84
|
token = (payment_method_props.properties.find { |kv| kv.key == 'token' }).value
|
85
85
|
return false if token.nil?
|
86
86
|
|
87
87
|
# The payment method should have been created during the setup step (see private api)
|
88
|
-
payment_method = PaypalExpressPaymentMethod.from_kb_account_id_and_token(kb_account_id
|
88
|
+
payment_method = PaypalExpressPaymentMethod.from_kb_account_id_and_token(kb_account_id, token)
|
89
89
|
|
90
90
|
# Go to Paypal to get the Payer id (GetExpressCheckoutDetails call)
|
91
91
|
paypal_express_details_response = @gateway.details_for token
|
@@ -99,39 +99,39 @@ module Killbill::PaypalExpress
|
|
99
99
|
response = save_response_and_transaction paypal_express_baid_response, :create_billing_agreement
|
100
100
|
return false unless response.success?
|
101
101
|
|
102
|
-
payment_method.kb_payment_method_id = kb_payment_method_id
|
102
|
+
payment_method.kb_payment_method_id = kb_payment_method_id
|
103
103
|
payment_method.paypal_express_payer_id = payer_id
|
104
104
|
payment_method.paypal_express_baid = response.billing_agreement_id
|
105
105
|
payment_method.save!
|
106
106
|
|
107
|
-
logger.info "Created BAID #{payment_method.paypal_express_baid} for payment method #{kb_payment_method_id
|
107
|
+
logger.info "Created BAID #{payment_method.paypal_express_baid} for payment method #{kb_payment_method_id} (account #{kb_account_id})"
|
108
108
|
true
|
109
109
|
else
|
110
|
-
logger.warn "Unable to retrieve Payer id details for token #{token} (account #{kb_account_id
|
110
|
+
logger.warn "Unable to retrieve Payer id details for token #{token} (account #{kb_account_id})"
|
111
111
|
false
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
def delete_payment_method(kb_account_id, kb_payment_method_id, call_context, options = {})
|
116
|
-
PaypalExpressPaymentMethod.mark_as_deleted! kb_payment_method_id
|
115
|
+
def delete_payment_method(kb_account_id, kb_payment_method_id, call_context = nil, options = {})
|
116
|
+
PaypalExpressPaymentMethod.mark_as_deleted! kb_payment_method_id
|
117
117
|
end
|
118
118
|
|
119
|
-
def get_payment_method_detail(kb_account_id, kb_payment_method_id, tenant_context, options = {})
|
120
|
-
PaypalExpressPaymentMethod.from_kb_payment_method_id(kb_payment_method_id
|
119
|
+
def get_payment_method_detail(kb_account_id, kb_payment_method_id, tenant_context = nil, options = {})
|
120
|
+
PaypalExpressPaymentMethod.from_kb_payment_method_id(kb_payment_method_id).to_payment_method_response
|
121
121
|
end
|
122
122
|
|
123
|
-
def set_default_payment_method(kb_account_id, kb_payment_method_id, call_context, options = {})
|
123
|
+
def set_default_payment_method(kb_account_id, kb_payment_method_id, call_context = nil, options = {})
|
124
124
|
# No-op
|
125
125
|
end
|
126
126
|
|
127
|
-
def get_payment_methods(kb_account_id, refresh_from_gateway, call_context, options = {})
|
128
|
-
PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id
|
127
|
+
def get_payment_methods(kb_account_id, refresh_from_gateway, call_context = nil, options = {})
|
128
|
+
PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id).collect { |pm| pm.to_payment_method_info_response }
|
129
129
|
end
|
130
130
|
|
131
131
|
def reset_payment_methods(kb_account_id, payment_methods)
|
132
132
|
return if payment_methods.nil?
|
133
133
|
|
134
|
-
paypal_pms = PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id
|
134
|
+
paypal_pms = PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id)
|
135
135
|
|
136
136
|
payment_methods.delete_if do |payment_method_info_plugin|
|
137
137
|
should_be_deleted = false
|
@@ -139,12 +139,12 @@ module Killbill::PaypalExpress
|
|
139
139
|
# Do paypal_pm and payment_method_info_plugin represent the same PayPal payment method?
|
140
140
|
if paypal_pm.external_payment_method_id == payment_method_info_plugin.external_payment_method_id
|
141
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
|
142
|
+
if paypal_pm.kb_payment_method_id == payment_method_info_plugin.payment_method_id
|
143
143
|
should_be_deleted = true
|
144
144
|
break
|
145
145
|
elsif paypal_pm.kb_payment_method_id.nil?
|
146
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
|
147
|
+
paypal_pm.kb_payment_method_id = payment_method_info_plugin.payment_method_id
|
148
148
|
should_be_deleted = paypal_pm.save
|
149
149
|
break
|
150
150
|
# Otherwise the same BAID points to 2 different kb_payment_method_id. This should never happen,
|
@@ -158,8 +158,8 @@ module Killbill::PaypalExpress
|
|
158
158
|
|
159
159
|
# The remaining elements in payment_methods are not in our table (this should never happen?!)
|
160
160
|
payment_methods.each do |payment_method_info_plugin|
|
161
|
-
PaypalExpressPaymentMethod.create :kb_account_id => payment_method_info_plugin.account_id
|
162
|
-
:kb_payment_method_id => payment_method_info_plugin.payment_method_id
|
161
|
+
PaypalExpressPaymentMethod.create :kb_account_id => payment_method_info_plugin.account_id,
|
162
|
+
:kb_payment_method_id => payment_method_info_plugin.payment_method_id,
|
163
163
|
:paypal_express_baid => payment_method_info_plugin.external_payment_method_id,
|
164
164
|
:paypal_express_token => 'unknown (created by reset)'
|
165
165
|
end
|
@@ -171,12 +171,12 @@ module Killbill::PaypalExpress
|
|
171
171
|
@logger.warn "Unsuccessful #{api_call}: #{paypal_express_response.message}" unless paypal_express_response.success?
|
172
172
|
|
173
173
|
# Save the response to our logs
|
174
|
-
response = PaypalExpressResponse.from_response(api_call, kb_payment_id
|
174
|
+
response = PaypalExpressResponse.from_response(api_call, kb_payment_id, paypal_express_response)
|
175
175
|
response.save!
|
176
176
|
|
177
177
|
if response.success and !kb_payment_id.blank? and !response.authorization.blank?
|
178
178
|
# Record the transaction
|
179
|
-
transaction = response.create_paypal_express_transaction!(:amount_in_cents => amount_in_cents, :api_call => api_call, :kb_payment_id => kb_payment_id
|
179
|
+
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)
|
180
180
|
@logger.debug "Recorded transaction: #{transaction.inspect}"
|
181
181
|
end
|
182
182
|
response
|
@@ -35,52 +35,57 @@ module Killbill::PaypalExpress
|
|
35
35
|
|
36
36
|
def to_payment_method_response
|
37
37
|
properties = []
|
38
|
-
properties <<
|
39
|
-
properties <<
|
40
|
-
properties <<
|
38
|
+
properties << create_pm_kv_info('payerId', paypal_express_payer_id)
|
39
|
+
properties << create_pm_kv_info('baid', paypal_express_baid)
|
40
|
+
properties << create_pm_kv_info('token', paypal_express_token)
|
41
41
|
|
42
42
|
# We're pretty much guaranteed to have a (single) entry for details_for, since it was called during add_payment_method
|
43
43
|
details_for = PaypalExpressResponse.find_all_by_api_call_and_token('details_for', paypal_express_token).last
|
44
44
|
unless details_for.nil?
|
45
|
-
properties <<
|
46
|
-
properties <<
|
47
|
-
properties <<
|
48
|
-
properties <<
|
49
|
-
properties <<
|
50
|
-
properties <<
|
51
|
-
properties <<
|
52
|
-
properties <<
|
53
|
-
properties <<
|
54
|
-
properties <<
|
55
|
-
properties <<
|
56
|
-
properties <<
|
45
|
+
properties << create_pm_kv_info('payerName', details_for.payer_name)
|
46
|
+
properties << create_pm_kv_info('payerEmail', details_for.payer_email)
|
47
|
+
properties << create_pm_kv_info('payerCountry', details_for.payer_country)
|
48
|
+
properties << create_pm_kv_info('contactPhone', details_for.contact_phone)
|
49
|
+
properties << create_pm_kv_info('shipToAddressName', details_for.ship_to_address_name)
|
50
|
+
properties << create_pm_kv_info('shipToAddressCompany', details_for.ship_to_address_company)
|
51
|
+
properties << create_pm_kv_info('shipToAddressAddress1', details_for.ship_to_address_address1)
|
52
|
+
properties << create_pm_kv_info('shipToAddressAddress2', details_for.ship_to_address_address2)
|
53
|
+
properties << create_pm_kv_info('shipToAddressCity', details_for.ship_to_address_city)
|
54
|
+
properties << create_pm_kv_info('shipToAddressState', details_for.ship_to_address_state)
|
55
|
+
properties << create_pm_kv_info('shipToAddressCountry', details_for.ship_to_address_country)
|
56
|
+
properties << create_pm_kv_info('shipToAddressZip', details_for.ship_to_address_zip)
|
57
57
|
end
|
58
58
|
|
59
|
-
Killbill::Plugin::Model::PaymentMethodPlugin.new
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
nil,
|
67
|
-
nil,
|
68
|
-
nil,
|
69
|
-
nil,
|
70
|
-
nil,
|
71
|
-
nil,
|
72
|
-
nil,
|
73
|
-
nil,
|
74
|
-
nil)
|
59
|
+
pm_plugin = Killbill::Plugin::Model::PaymentMethodPlugin.new
|
60
|
+
pm_plugin.external_payment_method_id = external_payment_method_id
|
61
|
+
pm_plugin.is_default_payment_method = is_default
|
62
|
+
pm_plugin.properties = properties
|
63
|
+
pm_plugin.type = 'PayPal'
|
64
|
+
|
65
|
+
pm_plugin
|
75
66
|
end
|
76
67
|
|
77
68
|
def to_payment_method_info_response
|
78
|
-
Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
|
69
|
+
pm_info_plugin = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
|
70
|
+
pm_info_plugin.account_id = kb_account_id
|
71
|
+
pm_info_plugin.payment_method_id = kb_payment_method_id
|
72
|
+
pm_info_plugin.is_default = is_default
|
73
|
+
pm_info_plugin.external_payment_method_id = external_payment_method_id
|
74
|
+
pm_info_plugin
|
79
75
|
end
|
80
76
|
|
81
77
|
def is_default
|
82
78
|
# No concept of default payment method in Paypal Express
|
83
79
|
false
|
84
80
|
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def create_pm_kv_info(key, value)
|
85
|
+
prop = Killbill::Plugin::Model::PaymentMethodKVInfo.new
|
86
|
+
prop.key = key
|
87
|
+
prop.value = value
|
88
|
+
prop
|
89
|
+
end
|
85
90
|
end
|
86
91
|
end
|
@@ -57,58 +57,58 @@ module Killbill::PaypalExpress
|
|
57
57
|
|
58
58
|
def self.from_response(api_call, kb_payment_id, response)
|
59
59
|
PaypalExpressResponse.new({
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
60
|
+
:api_call => api_call,
|
61
|
+
:kb_payment_id => kb_payment_id,
|
62
|
+
:message => response.message,
|
63
|
+
:authorization => response.authorization,
|
64
|
+
:fraud_review => response.fraud_review?,
|
65
|
+
:test => response.test?,
|
66
|
+
:token => response.token,
|
67
|
+
:payer_id => response.payer_id,
|
68
|
+
:billing_agreement_id => response.params['billing_agreement_id'],
|
69
|
+
:payer_name => response.name,
|
70
|
+
:payer_email => response.email,
|
71
|
+
:payer_country => response.payer_country,
|
72
|
+
:contact_phone => response.contact_phone,
|
73
|
+
:ship_to_address_name => response.address['name'],
|
74
|
+
:ship_to_address_company => response.address['company'],
|
75
|
+
:ship_to_address_address1 => response.address['address1'],
|
76
|
+
:ship_to_address_address2 => response.address['address2'],
|
77
|
+
:ship_to_address_city => response.address['city'],
|
78
|
+
:ship_to_address_state => response.address['state'],
|
79
|
+
:ship_to_address_country => response.address['country'],
|
80
|
+
:ship_to_address_zip => response.address['zip'],
|
81
|
+
:ship_to_address_phone => response.address['phone'],
|
82
|
+
:receiver_info_business => receiver_info(response)['Business'],
|
83
|
+
:receiver_info_receiver => receiver_info(response)['Receiver'],
|
84
|
+
:receiver_info_receiverid => receiver_info(response)['ReceiverID'],
|
85
|
+
:payment_info_transactionid => payment_info(response)['TransactionID'],
|
86
|
+
:payment_info_parenttransactionid => payment_info(response)['ParentTransactionID'],
|
87
|
+
:payment_info_receiptid => payment_info(response)['ReceiptID'],
|
88
|
+
:payment_info_transactiontype => payment_info(response)['TransactionType'],
|
89
|
+
:payment_info_paymenttype => payment_info(response)['PaymentType'],
|
90
|
+
:payment_info_paymentdate => payment_info(response)['PaymentDate'],
|
91
|
+
:payment_info_grossamount => payment_info(response)['GrossAmount'],
|
92
|
+
:payment_info_feeamount => payment_info(response)['FeeAmount'],
|
93
|
+
:payment_info_taxamount => payment_info(response)['TaxAmount'],
|
94
|
+
:payment_info_exchangerate => payment_info(response)['ExchangeRate'],
|
95
|
+
:payment_info_paymentstatus => payment_info(response)['PaymentStatus'],
|
96
|
+
:payment_info_pendingreason => payment_info(response)['PendingReason'],
|
97
|
+
:payment_info_reasoncode => payment_info(response)['ReasonCode'],
|
98
|
+
:payment_info_protectioneligibility => payment_info(response)['ProtectionEligibility'],
|
99
|
+
:payment_info_protectioneligibilitytype => payment_info(response)['ProtectionEligibilityType'],
|
100
|
+
:payment_info_shipamount => payment_info(response)['ShipAmount'],
|
101
|
+
:payment_info_shiphandleamount => payment_info(response)['ShipHandleAmount'],
|
102
|
+
:payment_info_shipdiscount => payment_info(response)['ShipDiscount'],
|
103
|
+
:payment_info_insuranceamount => payment_info(response)['InsuranceAmount'],
|
104
|
+
:payment_info_subject => payment_info(response)['Subject'],
|
105
|
+
:avs_result_code => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.code : response.avs_result['code'],
|
106
|
+
:avs_result_message => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.message : response.avs_result['message'],
|
107
|
+
:avs_result_street_match => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.street_match : response.avs_result['street_match'],
|
108
|
+
:avs_result_postal_match => response.avs_result.kind_of?(ActiveMerchant::Billing::AVSResult) ? response.avs_result.postal_match : response.avs_result['postal_match'],
|
109
|
+
:cvv_result_code => response.cvv_result.kind_of?(ActiveMerchant::Billing::CVVResult) ? response.cvv_result.code : response.cvv_result['code'],
|
110
|
+
:cvv_result_message => response.cvv_result.kind_of?(ActiveMerchant::Billing::CVVResult) ? response.cvv_result.message : response.cvv_result['message'],
|
111
|
+
:success => response.success?
|
112
112
|
})
|
113
113
|
end
|
114
114
|
|
@@ -146,11 +146,26 @@ module Killbill::PaypalExpress
|
|
146
146
|
gateway_error_code = nil
|
147
147
|
|
148
148
|
if type == :payment
|
149
|
-
|
150
|
-
|
149
|
+
p_info_plugin = Killbill::Plugin::Model::PaymentInfoPlugin.new
|
150
|
+
p_info_plugin.amount = amount_in_cents
|
151
|
+
p_info_plugin.created_date = created_date
|
152
|
+
p_info_plugin.effective_date = effective_date
|
153
|
+
p_info_plugin.status = (success ? :PROCESSED : :ERROR)
|
154
|
+
p_info_plugin.gateway_error = gateway_error
|
155
|
+
p_info_plugin.gateway_error_code = gateway_error_code
|
156
|
+
p_info_plugin.first_payment_reference_id = first_payment_reference_id
|
157
|
+
p_info_plugin.second_payment_reference_id = second_payment_reference_id
|
158
|
+
p_info_plugin
|
151
159
|
else
|
152
|
-
|
153
|
-
|
160
|
+
r_info_plugin = Killbill::Plugin::Model::RefundInfoPlugin.new
|
161
|
+
r_info_plugin.amount = amount_in_cents
|
162
|
+
r_info_plugin.created_date = created_date
|
163
|
+
r_info_plugin.effective_date = effective_date
|
164
|
+
r_info_plugin.status = (success ? :PROCESSED : :ERROR)
|
165
|
+
r_info_plugin.gateway_error = gateway_error
|
166
|
+
r_info_plugin.gateway_error_code = gateway_error_code
|
167
|
+
r_info_plugin.reference_id = first_payment_reference_id
|
168
|
+
r_info_plugin
|
154
169
|
end
|
155
170
|
end
|
156
171
|
|
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.1.0</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>
|
@@ -45,9 +45,9 @@ describe Killbill::PaypalExpress::PaymentPlugin do
|
|
45
45
|
# Add some in KillBill and reset
|
46
46
|
payment_methods = []
|
47
47
|
# Random order... Shouldn't matter...
|
48
|
-
payment_methods <<
|
49
|
-
payment_methods <<
|
50
|
-
payment_methods <<
|
48
|
+
payment_methods << create_pm_info_plugin(kb_account_id, 'kb-3', false, 'paypal-3')
|
49
|
+
payment_methods << create_pm_info_plugin(kb_account_id, 'kb-2', false, 'paypal-2')
|
50
|
+
payment_methods << create_pm_info_plugin(kb_account_id, 'kb-4', false, 'paypal-4')
|
51
51
|
@plugin.reset_payment_methods kb_account_id, payment_methods
|
52
52
|
verify_pms kb_account_id, 4
|
53
53
|
|
@@ -58,7 +58,7 @@ describe Killbill::PaypalExpress::PaymentPlugin do
|
|
58
58
|
@plugin.get_payment_methods(kb_account_id, false, nil).size.should == 5
|
59
59
|
|
60
60
|
# Verify we can match it
|
61
|
-
payment_methods <<
|
61
|
+
payment_methods << create_pm_info_plugin(kb_account_id, 'kb-5', false, 'paypal-5')
|
62
62
|
@plugin.reset_payment_methods kb_account_id, payment_methods
|
63
63
|
verify_pms kb_account_id, 5
|
64
64
|
|
@@ -76,4 +76,13 @@ describe Killbill::PaypalExpress::PaymentPlugin do
|
|
76
76
|
pm.external_payment_method_id.should == 'paypal-' + pm.payment_method_id.split('-')[1]
|
77
77
|
end
|
78
78
|
end
|
79
|
+
|
80
|
+
def create_pm_info_plugin(kb_account_id, kb_payment_method_id, is_default, external_payment_method_id)
|
81
|
+
pm_info_plugin = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
|
82
|
+
pm_info_plugin.account_id = kb_account_id
|
83
|
+
pm_info_plugin.payment_method_id = kb_payment_method_id
|
84
|
+
pm_info_plugin.is_default = is_default
|
85
|
+
pm_info_plugin.external_payment_method_id = external_payment_method_id
|
86
|
+
pm_info_plugin
|
87
|
+
end
|
79
88
|
end
|
@@ -15,47 +15,38 @@ 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)
|
27
18
|
end
|
28
19
|
|
29
20
|
after(:each) do
|
30
21
|
@plugin.stop_plugin
|
31
22
|
end
|
32
23
|
|
33
|
-
it
|
24
|
+
it 'should be able to charge and refund' do
|
34
25
|
amount_in_cents = 10000
|
35
26
|
currency = 'USD'
|
36
27
|
kb_payment_id = SecureRandom.uuid
|
37
28
|
|
38
|
-
payment_response = @plugin.process_payment @pm.kb_account_id, kb_payment_id, @pm.kb_payment_method_id, amount_in_cents, currency
|
29
|
+
payment_response = @plugin.process_payment @pm.kb_account_id, kb_payment_id, @pm.kb_payment_method_id, amount_in_cents, currency
|
39
30
|
payment_response.amount.should == amount_in_cents
|
40
|
-
payment_response.status.should ==
|
31
|
+
payment_response.status.should == :PROCESSED
|
41
32
|
|
42
33
|
# Verify our table directly
|
43
34
|
response = Killbill::PaypalExpress::PaypalExpressResponse.find_by_api_call_and_kb_payment_id :charge, kb_payment_id
|
44
35
|
response.test.should be_true
|
45
36
|
response.success.should be_true
|
46
|
-
response.message.should ==
|
37
|
+
response.message.should == 'Success'
|
47
38
|
|
48
39
|
# Check we can retrieve the payment
|
49
|
-
payment_response = @plugin.get_payment_info @pm.kb_account_id, kb_payment_id
|
40
|
+
payment_response = @plugin.get_payment_info @pm.kb_account_id, kb_payment_id
|
50
41
|
payment_response.amount.should == amount_in_cents
|
51
|
-
payment_response.status.should ==
|
42
|
+
payment_response.status.should == :PROCESSED
|
52
43
|
|
53
44
|
# Check we cannot refund an amount greater than the original charge
|
54
|
-
lambda { @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents + 1, currency
|
45
|
+
lambda { @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents + 1, currency }.should raise_error RuntimeError
|
55
46
|
|
56
|
-
refund_response = @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents, currency
|
47
|
+
refund_response = @plugin.process_refund @pm.kb_account_id, kb_payment_id, amount_in_cents, currency
|
57
48
|
refund_response.amount.should == amount_in_cents
|
58
|
-
refund_response.status.should ==
|
49
|
+
refund_response.status.should == :PROCESSED
|
59
50
|
|
60
51
|
# Verify our table directly
|
61
52
|
response = Killbill::PaypalExpress::PaypalExpressResponse.find_by_api_call_and_kb_payment_id :refund, kb_payment_id
|
@@ -63,36 +54,36 @@ describe Killbill::PaypalExpress::PaymentPlugin do
|
|
63
54
|
response.success.should be_true
|
64
55
|
|
65
56
|
# Check we can retrieve the refund
|
66
|
-
refund_response = @plugin.get_refund_info @pm.kb_account_id, kb_payment_id
|
57
|
+
refund_response = @plugin.get_refund_info @pm.kb_account_id, kb_payment_id
|
67
58
|
refund_response.amount.should == (-1 * amount_in_cents)
|
68
|
-
refund_response.status.should ==
|
59
|
+
refund_response.status.should == :PROCESSED
|
69
60
|
|
70
61
|
# Try another payment to verify the BAID
|
71
62
|
second_amount_in_cents = 9423
|
72
63
|
second_kb_payment_id = SecureRandom.uuid
|
73
|
-
payment_response = @plugin.process_payment @pm.kb_account_id, second_kb_payment_id, @pm.kb_payment_method_id, second_amount_in_cents, currency
|
64
|
+
payment_response = @plugin.process_payment @pm.kb_account_id, second_kb_payment_id, @pm.kb_payment_method_id, second_amount_in_cents, currency
|
74
65
|
payment_response.amount.should == second_amount_in_cents
|
75
|
-
payment_response.status.should ==
|
66
|
+
payment_response.status.should == :PROCESSED
|
76
67
|
|
77
68
|
# Check we can refund it as well
|
78
|
-
refund_response = @plugin.process_refund @pm.kb_account_id, second_kb_payment_id, second_amount_in_cents, currency
|
69
|
+
refund_response = @plugin.process_refund @pm.kb_account_id, second_kb_payment_id, second_amount_in_cents, currency
|
79
70
|
refund_response.amount.should == second_amount_in_cents
|
80
|
-
refund_response.status.should ==
|
71
|
+
refund_response.status.should == :PROCESSED
|
81
72
|
|
82
73
|
# it "should be able to create and retrieve payment methods"
|
83
74
|
# This should be in a separate scenario but since it's so hard to create a payment method (need manual intervention),
|
84
75
|
# we can't easily delete it
|
85
|
-
pms = @plugin.get_payment_methods @pm.kb_account_id, false
|
76
|
+
pms = @plugin.get_payment_methods @pm.kb_account_id, false
|
86
77
|
pms.size.should == 1
|
87
78
|
pms[0].external_payment_method_id.should == @pm.paypal_express_baid
|
88
79
|
|
89
|
-
pm_details = @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id
|
80
|
+
pm_details = @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id)
|
90
81
|
pm_details.external_payment_method_id.should == @pm.paypal_express_baid
|
91
82
|
|
92
|
-
@plugin.delete_payment_method @pm.kb_account_id, @pm.kb_payment_method_id
|
83
|
+
@plugin.delete_payment_method @pm.kb_account_id, @pm.kb_payment_method_id
|
93
84
|
|
94
|
-
@plugin.get_payment_methods(@pm.kb_account_id, false
|
95
|
-
lambda { @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id
|
85
|
+
@plugin.get_payment_methods(@pm.kb_account_id, false).size.should == 0
|
86
|
+
lambda { @plugin.get_payment_method_detail(@pm.kb_account_id, @pm.kb_payment_method_id) }.should raise_error RuntimeError
|
96
87
|
end
|
97
88
|
|
98
89
|
private
|
@@ -112,8 +103,12 @@ Note: you need to log-in with a paypal sandbox account (create one here: https:/
|
|
112
103
|
|
113
104
|
# Complete the setup process
|
114
105
|
kb_payment_method_id = SecureRandom.uuid
|
115
|
-
|
116
|
-
|
106
|
+
pm_kv_info = Killbill::Plugin::Model::PaymentMethodKVInfo.new
|
107
|
+
pm_kv_info.key = 'token'
|
108
|
+
pm_kv_info.value = token
|
109
|
+
info = Killbill::Plugin::Model::PaymentMethodPlugin.new
|
110
|
+
info.properties = [pm_kv_info]
|
111
|
+
response = @plugin.add_payment_method kb_account_id, kb_payment_method_id, info, true
|
117
112
|
response.should be_true
|
118
113
|
|
119
114
|
# Verify our table directly
|
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.1.0
|
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-21 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.
|
20
|
+
version: 1.1.2
|
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.
|
26
|
+
version: 1.1.2
|
27
27
|
none: false
|
28
28
|
prerelease: false
|
29
29
|
type: :runtime
|
@@ -165,6 +165,7 @@ files:
|
|
165
165
|
- ".travis.yml"
|
166
166
|
- Gemfile
|
167
167
|
- Jarfile
|
168
|
+
- NEWS
|
168
169
|
- README.md
|
169
170
|
- Rakefile
|
170
171
|
- VERSION
|