killbill 3.1.3 → 3.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Jarfile +7 -5
- data/NEWS +3 -0
- data/README.md +41 -17
- data/VERSION +1 -1
- data/generators/active_merchant/templates/Jarfile.rb +7 -5
- data/generators/active_merchant/templates/config.yml.rb +3 -3
- data/generators/active_merchant/templates/db/ddl.sql.rb +4 -0
- data/generators/active_merchant/templates/db/schema.rb +4 -0
- data/generators/active_merchant/templates/lib/api.rb +42 -22
- data/generators/active_merchant/templates/lib/models/response.rb +3 -1
- data/generators/active_merchant/templates/plugin.gemspec.rb +1 -1
- data/lib/killbill.rb +7 -4
- data/lib/killbill/gen/api/account.rb +4 -3
- data/lib/killbill/gen/api/account_api_exception.rb +4 -3
- data/lib/killbill/gen/api/account_audit_logs.rb +12 -68
- data/lib/killbill/gen/api/account_audit_logs_for_object_type.rb +4 -3
- data/lib/killbill/gen/api/account_data.rb +4 -3
- data/lib/killbill/gen/api/account_email.rb +4 -3
- data/lib/killbill/gen/api/account_user_api.rb +4 -3
- data/lib/killbill/gen/api/audit_log.rb +4 -3
- data/lib/killbill/gen/api/audit_user_api.rb +4 -3
- data/lib/killbill/gen/api/billing_exception_base.rb +4 -3
- data/lib/killbill/gen/api/block.rb +4 -3
- data/lib/killbill/gen/api/blockable.rb +4 -3
- data/lib/killbill/gen/api/blocking_api_exception.rb +4 -3
- data/lib/killbill/gen/api/blocking_state.rb +4 -3
- data/lib/killbill/gen/api/call_context.rb +4 -3
- data/lib/killbill/gen/api/catalog.rb +4 -3
- data/lib/killbill/gen/api/catalog_api_exception.rb +4 -3
- data/lib/killbill/gen/api/catalog_user_api.rb +4 -3
- data/lib/killbill/gen/api/column_info.rb +4 -3
- data/lib/killbill/gen/api/control_tag.rb +4 -3
- data/lib/killbill/gen/api/currency_conversion.rb +4 -3
- data/lib/killbill/gen/api/currency_conversion_api.rb +4 -3
- data/lib/killbill/gen/api/currency_conversion_exception.rb +4 -3
- data/lib/killbill/gen/api/currency_value_null.rb +4 -3
- data/lib/killbill/gen/api/custom_field.rb +4 -3
- data/lib/killbill/gen/api/custom_field_api_exception.rb +4 -3
- data/lib/killbill/gen/api/custom_field_user_api.rb +4 -3
- data/lib/killbill/gen/api/database_export_output_stream.rb +4 -3
- data/lib/killbill/gen/api/direct_payment.rb +39 -11
- data/lib/killbill/gen/api/direct_payment_api.rb +643 -31
- data/lib/killbill/gen/api/direct_payment_transaction.rb +37 -12
- data/lib/killbill/gen/api/duration.rb +4 -3
- data/lib/killbill/gen/api/entitlement.rb +4 -3
- data/lib/killbill/gen/api/entitlement_ao_status_dry_run.rb +4 -3
- data/lib/killbill/gen/api/entitlement_api.rb +4 -3
- data/lib/killbill/gen/api/entitlement_api_exception.rb +4 -3
- data/lib/killbill/gen/api/entity.rb +4 -3
- data/lib/killbill/gen/api/fixed.rb +4 -3
- data/lib/killbill/gen/api/illegal_plan_change.rb +4 -3
- data/lib/killbill/gen/api/international_price.rb +4 -3
- data/lib/killbill/gen/api/invalid_config_exception.rb +4 -3
- data/lib/killbill/gen/api/invoice.rb +4 -3
- data/lib/killbill/gen/api/invoice_api_exception.rb +4 -3
- data/lib/killbill/gen/api/invoice_creation_event.rb +4 -3
- data/lib/killbill/gen/api/invoice_formatter.rb +4 -3
- data/lib/killbill/gen/api/invoice_item.rb +4 -3
- data/lib/killbill/gen/api/invoice_item_formatter.rb +4 -3
- data/lib/killbill/gen/api/invoice_payment.rb +7 -7
- data/lib/killbill/gen/api/invoice_payment_api.rb +7 -153
- data/lib/killbill/gen/api/invoice_user_api.rb +22 -3
- data/lib/killbill/gen/api/limit.rb +4 -3
- data/lib/killbill/gen/api/listing.rb +4 -3
- data/lib/killbill/gen/api/migration_plan.rb +4 -3
- data/lib/killbill/gen/api/mutable_account_data.rb +4 -3
- data/lib/killbill/gen/api/osgi_killbill.rb +15 -7
- data/lib/killbill/gen/api/osgi_plugin_properties.rb +4 -3
- data/lib/killbill/gen/api/pagination.rb +4 -3
- data/lib/killbill/gen/api/payment_api_exception.rb +4 -3
- data/lib/killbill/gen/api/payment_gateway_api.rb +4 -3
- data/lib/killbill/gen/api/payment_method.rb +11 -4
- data/lib/killbill/gen/api/payment_method_plugin.rb +5 -76
- data/lib/killbill/gen/api/payment_options.rb +68 -0
- data/lib/killbill/gen/api/plan.rb +4 -3
- data/lib/killbill/gen/api/plan_change_result.rb +4 -3
- data/lib/killbill/gen/api/plan_phase.rb +4 -3
- data/lib/killbill/gen/api/plan_phase_specifier.rb +4 -3
- data/lib/killbill/gen/api/plan_specifier.rb +4 -3
- data/lib/killbill/gen/api/plugin_config_service_api.rb +4 -3
- data/lib/killbill/gen/api/plugin_property.rb +4 -3
- data/lib/killbill/gen/api/price.rb +4 -3
- data/lib/killbill/gen/api/price_list.rb +4 -3
- data/lib/killbill/gen/api/price_list_set.rb +4 -3
- data/lib/killbill/gen/api/product.rb +4 -3
- data/lib/killbill/gen/api/rate.rb +4 -3
- data/lib/killbill/gen/api/record_id_api.rb +4 -3
- data/lib/killbill/gen/api/recurring.rb +4 -3
- data/lib/killbill/gen/api/refund.rb +7 -6
- data/lib/killbill/gen/api/require_gen.rb +5 -6
- data/lib/killbill/gen/api/rolled_up_usage.rb +4 -3
- data/lib/killbill/gen/api/security_api_exception.rb +4 -3
- data/lib/killbill/gen/api/static_catalog.rb +4 -3
- data/lib/killbill/gen/api/subscription.rb +4 -3
- data/lib/killbill/gen/api/subscription_api.rb +4 -3
- data/lib/killbill/gen/api/subscription_api_exception.rb +4 -3
- data/lib/killbill/gen/api/subscription_bundle.rb +4 -3
- data/lib/killbill/gen/api/subscription_bundle_timeline.rb +4 -3
- data/lib/killbill/gen/api/subscription_event.rb +4 -3
- data/lib/killbill/gen/api/tag.rb +4 -3
- data/lib/killbill/gen/api/tag_api_exception.rb +4 -3
- data/lib/killbill/gen/api/tag_definition.rb +4 -3
- data/lib/killbill/gen/api/tag_definition_api_exception.rb +4 -3
- data/lib/killbill/gen/api/tag_user_api.rb +4 -3
- data/lib/killbill/gen/api/tenant.rb +4 -3
- data/lib/killbill/gen/api/tenant_api_exception.rb +4 -3
- data/lib/killbill/gen/api/tenant_context.rb +4 -3
- data/lib/killbill/gen/api/tenant_data.rb +4 -3
- data/lib/killbill/gen/api/tenant_kv.rb +4 -3
- data/lib/killbill/gen/api/tenant_user_api.rb +4 -3
- data/lib/killbill/gen/api/tier.rb +4 -3
- data/lib/killbill/gen/api/tiered_block.rb +4 -3
- data/lib/killbill/gen/api/unit.rb +4 -3
- data/lib/killbill/gen/api/usage.rb +4 -3
- data/lib/killbill/gen/api/usage_user_api.rb +4 -3
- data/lib/killbill/gen/plugin-api/currency_plugin_api.rb +4 -3
- data/lib/killbill/gen/plugin-api/ext_bus_event.rb +4 -3
- data/lib/killbill/gen/plugin-api/gateway_notification.rb +4 -3
- data/lib/killbill/gen/plugin-api/hosted_payment_page_form_descriptor.rb +4 -3
- data/lib/killbill/gen/plugin-api/notification_plugin_api.rb +4 -3
- data/lib/killbill/gen/plugin-api/payment_method_info_plugin.rb +4 -3
- data/lib/killbill/gen/plugin-api/payment_plugin_api.rb +75 -81
- data/lib/killbill/gen/plugin-api/payment_plugin_api_exception.rb +4 -3
- data/lib/killbill/gen/plugin-api/{payment_info_plugin.rb → payment_transaction_info_plugin.rb} +21 -6
- data/lib/killbill/gen/plugin-api/require_gen.rb +5 -5
- data/lib/killbill/helpers/active_merchant/active_record/models/payment_method.rb +20 -36
- data/lib/killbill/helpers/active_merchant/active_record/models/response.rb +72 -81
- data/lib/killbill/helpers/active_merchant/active_record/models/transaction.rb +62 -43
- data/lib/killbill/helpers/active_merchant/killbill_spec_helper.rb +0 -13
- data/lib/killbill/helpers/active_merchant/payment_plugin.rb +127 -125
- data/lib/killbill/http_servlet.rb +16 -1
- data/lib/killbill/killbill_api.rb +0 -3
- data/lib/killbill/payment.rb +22 -6
- data/lib/killbill/rake_task.rb +93 -31
- data/spec/killbill/helpers/payment_method_spec.rb +153 -0
- data/spec/killbill/helpers/response_spec.rb +58 -15
- data/spec/killbill/helpers/test_schema.rb +12 -8
- data/spec/killbill/helpers/transaction_spec.rb +134 -0
- data/spec/killbill/payment_plugin_api_spec.rb +18 -18
- data/spec/killbill/payment_plugin_spec.rb +26 -15
- data/spec/killbill/payment_test.rb +6 -7
- data/spec/spec_helper.rb +3 -0
- metadata +6 -5
- data/lib/killbill/gen/api/payment.rb +0 -187
- data/lib/killbill/gen/plugin-api/refund_info_plugin.rb +0 -152
@@ -1,10 +1,11 @@
|
|
1
1
|
###################################################################################
|
2
2
|
# #
|
3
3
|
# Copyright 2010-2013 Ning, Inc. #
|
4
|
+
# Copyright 2014 The Billing Project, LLC #
|
4
5
|
# #
|
5
|
-
#
|
6
|
-
# (the "License"); you may not use this file except in
|
7
|
-
# License. You may obtain a copy of the License at:
|
6
|
+
# The Billing Project licenses this file to you under the Apache License, #
|
7
|
+
# version 2.0 (the "License"); you may not use this file except in #
|
8
|
+
# compliance with the License. You may obtain a copy of the License at: #
|
8
9
|
# #
|
9
10
|
# http://www.apache.org/licenses/LICENSE-2.0 #
|
10
11
|
# #
|
data/lib/killbill/gen/plugin-api/{payment_info_plugin.rb → payment_transaction_info_plugin.rb}
RENAMED
@@ -1,10 +1,11 @@
|
|
1
1
|
###################################################################################
|
2
2
|
# #
|
3
3
|
# Copyright 2010-2013 Ning, Inc. #
|
4
|
+
# Copyright 2014 The Billing Project, LLC #
|
4
5
|
# #
|
5
|
-
#
|
6
|
-
# (the "License"); you may not use this file except in
|
7
|
-
# License. You may obtain a copy of the License at:
|
6
|
+
# The Billing Project licenses this file to you under the Apache License, #
|
7
|
+
# version 2.0 (the "License"); you may not use this file except in #
|
8
|
+
# compliance with the License. You may obtain a copy of the License at: #
|
8
9
|
# #
|
9
10
|
# http://www.apache.org/licenses/LICENSE-2.0 #
|
10
11
|
# #
|
@@ -28,11 +29,11 @@ module Killbill
|
|
28
29
|
module Model
|
29
30
|
|
30
31
|
java_package 'org.killbill.billing.payment.plugin.api'
|
31
|
-
class
|
32
|
+
class PaymentTransactionInfoPlugin
|
32
33
|
|
33
|
-
include org.killbill.billing.payment.plugin.api.
|
34
|
+
include org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin
|
34
35
|
|
35
|
-
attr_accessor :kb_payment_id, :amount, :currency, :created_date, :effective_date, :status, :gateway_error, :gateway_error_code, :first_payment_reference_id, :second_payment_reference_id, :properties
|
36
|
+
attr_accessor :kb_payment_id, :kb_transaction_payment_id, :transaction_type, :amount, :currency, :created_date, :effective_date, :status, :gateway_error, :gateway_error_code, :first_payment_reference_id, :second_payment_reference_id, :properties
|
36
37
|
|
37
38
|
def initialize()
|
38
39
|
end
|
@@ -41,6 +42,12 @@ module Killbill
|
|
41
42
|
# conversion for kb_payment_id [type = java.util.UUID]
|
42
43
|
@kb_payment_id = java.util.UUID.fromString(@kb_payment_id.to_s) unless @kb_payment_id.nil?
|
43
44
|
|
45
|
+
# conversion for kb_transaction_payment_id [type = java.util.UUID]
|
46
|
+
@kb_transaction_payment_id = java.util.UUID.fromString(@kb_transaction_payment_id.to_s) unless @kb_transaction_payment_id.nil?
|
47
|
+
|
48
|
+
# conversion for transaction_type [type = org.killbill.billing.payment.api.TransactionType]
|
49
|
+
@transaction_type = Java::org.killbill.billing.payment.api.TransactionType.value_of("#{@transaction_type.to_s}") unless @transaction_type.nil?
|
50
|
+
|
44
51
|
# conversion for amount [type = java.math.BigDecimal]
|
45
52
|
if @amount.nil?
|
46
53
|
@amount = java.math.BigDecimal::ZERO
|
@@ -94,6 +101,14 @@ module Killbill
|
|
94
101
|
@kb_payment_id = j_obj.kb_payment_id
|
95
102
|
@kb_payment_id = @kb_payment_id.nil? ? nil : @kb_payment_id.to_s
|
96
103
|
|
104
|
+
# conversion for kb_transaction_payment_id [type = java.util.UUID]
|
105
|
+
@kb_transaction_payment_id = j_obj.kb_transaction_payment_id
|
106
|
+
@kb_transaction_payment_id = @kb_transaction_payment_id.nil? ? nil : @kb_transaction_payment_id.to_s
|
107
|
+
|
108
|
+
# conversion for transaction_type [type = org.killbill.billing.payment.api.TransactionType]
|
109
|
+
@transaction_type = j_obj.transaction_type
|
110
|
+
@transaction_type = @transaction_type.to_s.to_sym unless @transaction_type.nil?
|
111
|
+
|
97
112
|
# conversion for amount [type = java.math.BigDecimal]
|
98
113
|
@amount = j_obj.amount
|
99
114
|
@amount = @amount.nil? ? 0 : BigDecimal.new(@amount.to_s)
|
@@ -1,10 +1,11 @@
|
|
1
1
|
###################################################################################
|
2
2
|
# #
|
3
3
|
# Copyright 2010-2013 Ning, Inc. #
|
4
|
+
# Copyright 2014 The Billing Project, LLC #
|
4
5
|
# #
|
5
|
-
#
|
6
|
-
# (the "License"); you may not use this file except in
|
7
|
-
# License. You may obtain a copy of the License at:
|
6
|
+
# The Billing Project licenses this file to you under the Apache License, #
|
7
|
+
# version 2.0 (the "License"); you may not use this file except in #
|
8
|
+
# compliance with the License. You may obtain a copy of the License at: #
|
8
9
|
# #
|
9
10
|
# http://www.apache.org/licenses/LICENSE-2.0 #
|
10
11
|
# #
|
@@ -31,5 +32,4 @@ require 'killbill/gen/plugin-api/notification_plugin_api'
|
|
31
32
|
require 'killbill/gen/plugin-api/currency_plugin_api'
|
32
33
|
require 'killbill/gen/plugin-api/gateway_notification'
|
33
34
|
require 'killbill/gen/plugin-api/hosted_payment_page_form_descriptor'
|
34
|
-
require 'killbill/gen/plugin-api/
|
35
|
-
require 'killbill/gen/plugin-api/refund_info_plugin'
|
35
|
+
require 'killbill/gen/plugin-api/payment_transaction_info_plugin'
|
@@ -3,6 +3,7 @@ module Killbill
|
|
3
3
|
module ActiveMerchant
|
4
4
|
module ActiveRecord
|
5
5
|
require 'active_record'
|
6
|
+
require 'active_merchant'
|
6
7
|
require 'killbill/helpers/active_merchant/active_record/models/helpers'
|
7
8
|
|
8
9
|
class PaymentMethod < ::ActiveRecord::Base
|
@@ -14,9 +15,9 @@ module Killbill
|
|
14
15
|
def self.from_response(kb_account_id, kb_payment_method_id, kb_tenant_id, cc_or_token, response, options, extra_params = {}, model = PaymentMethod)
|
15
16
|
model.new({
|
16
17
|
:kb_account_id => kb_account_id,
|
17
|
-
:kb_tenant_id => kb_tenant_id,
|
18
18
|
:kb_payment_method_id => kb_payment_method_id,
|
19
|
-
:
|
19
|
+
:kb_tenant_id => kb_tenant_id,
|
20
|
+
:token => cc_or_token.kind_of?(::ActiveMerchant::Billing::CreditCard) ? response.authorization : (cc_or_token || response.authorization),
|
20
21
|
:cc_first_name => cc_or_token.kind_of?(::ActiveMerchant::Billing::CreditCard) ? cc_or_token.first_name : nil,
|
21
22
|
:cc_last_name => cc_or_token.kind_of?(::ActiveMerchant::Billing::CreditCard) ? cc_or_token.last_name : nil,
|
22
23
|
:cc_type => cc_or_token.kind_of?(::ActiveMerchant::Billing::CreditCard) ? cc_or_token.brand : nil,
|
@@ -34,7 +35,7 @@ module Killbill
|
|
34
35
|
|
35
36
|
def self.from_kb_account_id(kb_account_id, kb_tenant_id)
|
36
37
|
if kb_tenant_id.nil?
|
37
|
-
where('kb_account_id = ? AND is_deleted = ?', kb_account_id, false)
|
38
|
+
where('kb_account_id = ? AND kb_tenant_id is NULL AND is_deleted = ?', kb_account_id, false)
|
38
39
|
else
|
39
40
|
where('kb_account_id = ? AND kb_tenant_id = ? AND is_deleted = ?', kb_account_id, kb_tenant_id, false)
|
40
41
|
end
|
@@ -42,7 +43,7 @@ module Killbill
|
|
42
43
|
|
43
44
|
def self.from_kb_payment_method_id(kb_payment_method_id, kb_tenant_id)
|
44
45
|
if kb_tenant_id.nil?
|
45
|
-
payment_methods = where('kb_payment_method_id = ? AND is_deleted = ?', kb_payment_method_id, false)
|
46
|
+
payment_methods = where('kb_payment_method_id = ? AND kb_tenant_id is NULL AND is_deleted = ?', kb_payment_method_id, false)
|
46
47
|
else
|
47
48
|
payment_methods = where('kb_payment_method_id = ? AND kb_tenant_id = ? AND is_deleted = ?', kb_payment_method_id, kb_tenant_id, false)
|
48
49
|
end
|
@@ -117,7 +118,7 @@ module Killbill
|
|
117
118
|
actual_limit = [pagination.max_nb_records, limit].min
|
118
119
|
pagination.iterator = StreamyResultSet.new(actual_limit) do |offset,limit|
|
119
120
|
self.find_by_sql(self.search_query(search_key, kb_tenant_id, offset, limit))
|
120
|
-
.map(&:
|
121
|
+
.map(&:to_payment_method_plugin)
|
121
122
|
end
|
122
123
|
pagination
|
123
124
|
end
|
@@ -132,43 +133,31 @@ module Killbill
|
|
132
133
|
false
|
133
134
|
end
|
134
135
|
|
135
|
-
def
|
136
|
+
def to_payment_method_plugin
|
136
137
|
properties = []
|
137
|
-
properties <<
|
138
|
-
properties <<
|
139
|
-
properties <<
|
140
|
-
properties <<
|
141
|
-
properties <<
|
142
|
-
properties <<
|
143
|
-
properties <<
|
144
|
-
properties <<
|
145
|
-
properties <<
|
146
|
-
properties <<
|
147
|
-
properties <<
|
148
|
-
properties <<
|
138
|
+
properties << create_plugin_property('token', external_payment_method_id)
|
139
|
+
properties << create_plugin_property('ccName', cc_name)
|
140
|
+
properties << create_plugin_property('ccType', cc_type)
|
141
|
+
properties << create_plugin_property('ccExpirationMonth', cc_exp_month)
|
142
|
+
properties << create_plugin_property('ccExpirationYear', cc_exp_year)
|
143
|
+
properties << create_plugin_property('ccLast4', cc_last_4)
|
144
|
+
properties << create_plugin_property('address1', address1)
|
145
|
+
properties << create_plugin_property('address2', address2)
|
146
|
+
properties << create_plugin_property('city', city)
|
147
|
+
properties << create_plugin_property('state', state)
|
148
|
+
properties << create_plugin_property('zip', zip)
|
149
|
+
properties << create_plugin_property('country', country)
|
149
150
|
|
150
151
|
pm_plugin = Killbill::Plugin::Model::PaymentMethodPlugin.new
|
151
152
|
pm_plugin.kb_payment_method_id = kb_payment_method_id
|
152
153
|
pm_plugin.external_payment_method_id = external_payment_method_id
|
153
154
|
pm_plugin.is_default_payment_method = is_default
|
154
155
|
pm_plugin.properties = properties
|
155
|
-
pm_plugin.type = 'CreditCard'
|
156
|
-
pm_plugin.cc_name = cc_name
|
157
|
-
pm_plugin.cc_type = cc_type
|
158
|
-
pm_plugin.cc_expiration_month = cc_exp_month
|
159
|
-
pm_plugin.cc_expiration_year = cc_exp_year
|
160
|
-
pm_plugin.cc_last4 = cc_last_4
|
161
|
-
pm_plugin.address1 = address1
|
162
|
-
pm_plugin.address2 = address2
|
163
|
-
pm_plugin.city = city
|
164
|
-
pm_plugin.state = state
|
165
|
-
pm_plugin.zip = zip
|
166
|
-
pm_plugin.country = country
|
167
156
|
|
168
157
|
pm_plugin
|
169
158
|
end
|
170
159
|
|
171
|
-
def
|
160
|
+
def to_payment_method_info_plugin
|
172
161
|
pm_info_plugin = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
|
173
162
|
pm_info_plugin.account_id = kb_account_id
|
174
163
|
pm_info_plugin.payment_method_id = kb_payment_method_id
|
@@ -191,11 +180,6 @@ module Killbill
|
|
191
180
|
|
192
181
|
private
|
193
182
|
|
194
|
-
# Deprecated
|
195
|
-
def create_pm_kv_info(key, value)
|
196
|
-
create_plugin_property(key, value)
|
197
|
-
end
|
198
|
-
|
199
183
|
def create_plugin_property(key, value)
|
200
184
|
prop = Killbill::Plugin::Model::PluginProperty.new
|
201
185
|
prop.key = key
|
@@ -13,58 +13,94 @@ module Killbill
|
|
13
13
|
|
14
14
|
self.abstract_class = true
|
15
15
|
|
16
|
-
def self.from_response(api_call, kb_account_id, kb_payment_id, kb_tenant_id, response, extra_params = {}, model = Response)
|
16
|
+
def self.from_response(api_call, kb_account_id, kb_payment_id, kb_payment_transaction_id, transaction_type, kb_tenant_id, response, extra_params = {}, model = Response)
|
17
17
|
model.new({
|
18
|
-
:api_call
|
19
|
-
:kb_account_id
|
20
|
-
:kb_payment_id
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
18
|
+
:api_call => api_call,
|
19
|
+
:kb_account_id => kb_account_id,
|
20
|
+
:kb_payment_id => kb_payment_id,
|
21
|
+
:kb_payment_transaction_id => kb_payment_transaction_id,
|
22
|
+
:transaction_type => transaction_type,
|
23
|
+
:kb_tenant_id => kb_tenant_id,
|
24
|
+
:message => response.message,
|
25
|
+
:authorization => response.authorization,
|
26
|
+
:fraud_review => response.fraud_review?,
|
27
|
+
:test => response.test?,
|
28
|
+
:avs_result_code => response.avs_result.kind_of?(::ActiveMerchant::Billing::AVSResult) ? response.avs_result.code : response.avs_result['code'],
|
29
|
+
:avs_result_message => response.avs_result.kind_of?(::ActiveMerchant::Billing::AVSResult) ? response.avs_result.message : response.avs_result['message'],
|
30
|
+
:avs_result_street_match => response.avs_result.kind_of?(::ActiveMerchant::Billing::AVSResult) ? response.avs_result.street_match : response.avs_result['street_match'],
|
31
|
+
:avs_result_postal_match => response.avs_result.kind_of?(::ActiveMerchant::Billing::AVSResult) ? response.avs_result.postal_match : response.avs_result['postal_match'],
|
32
|
+
:cvv_result_code => response.cvv_result.kind_of?(::ActiveMerchant::Billing::CVVResult) ? response.cvv_result.code : response.cvv_result['code'],
|
33
|
+
:cvv_result_message => response.cvv_result.kind_of?(::ActiveMerchant::Billing::CVVResult) ? response.cvv_result.message : response.cvv_result['message'],
|
34
|
+
:success => response.success?
|
33
35
|
}.merge!(extra_params))
|
34
36
|
end
|
35
37
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
38
|
+
def to_transaction_info_plugin(transaction=nil)
|
39
|
+
if transaction.nil?
|
40
|
+
amount_in_cents = nil
|
41
|
+
currency = nil
|
42
|
+
created_date = created_at
|
43
|
+
else
|
44
|
+
amount_in_cents = transaction.amount_in_cents
|
45
|
+
currency = transaction.currency
|
46
|
+
created_date = transaction.created_at
|
47
|
+
end
|
39
48
|
|
40
|
-
|
41
|
-
|
49
|
+
t_info_plugin = Killbill::Plugin::Model::PaymentTransactionInfoPlugin.new
|
50
|
+
t_info_plugin.kb_payment_id = kb_payment_id
|
51
|
+
t_info_plugin.kb_transaction_payment_id = kb_payment_transaction_id
|
52
|
+
t_info_plugin.transaction_type = transaction_type.nil? ? nil : transaction_type.to_sym
|
53
|
+
t_info_plugin.amount = Money.new(amount_in_cents, currency).to_d if currency
|
54
|
+
t_info_plugin.currency = currency
|
55
|
+
t_info_plugin.created_date = created_date
|
56
|
+
t_info_plugin.effective_date = effective_date
|
57
|
+
t_info_plugin.status = (success ? :PROCESSED : :ERROR)
|
58
|
+
t_info_plugin.gateway_error = gateway_error
|
59
|
+
t_info_plugin.gateway_error_code = gateway_error_code
|
60
|
+
t_info_plugin.first_payment_reference_id = first_reference_id
|
61
|
+
t_info_plugin.second_payment_reference_id = second_reference_id
|
62
|
+
|
63
|
+
properties = []
|
64
|
+
properties << create_plugin_property('message', message)
|
65
|
+
properties << create_plugin_property('authorization', authorization)
|
66
|
+
properties << create_plugin_property('fraudReview', fraud_review)
|
67
|
+
properties << create_plugin_property('test', self.read_attribute(:test))
|
68
|
+
properties << create_plugin_property('avsResultCode', avs_result_code)
|
69
|
+
properties << create_plugin_property('avsResultMessage', avs_result_message)
|
70
|
+
properties << create_plugin_property('avsResultStreetMatch', avs_result_street_match)
|
71
|
+
properties << create_plugin_property('avsResultPostalMatch', avs_result_postal_match)
|
72
|
+
properties << create_plugin_property('cvvResultCode', cvv_result_code)
|
73
|
+
properties << create_plugin_property('cvvResultMessage', cvv_result_message)
|
74
|
+
properties << create_plugin_property('success', success)
|
75
|
+
t_info_plugin.properties = properties
|
76
|
+
|
77
|
+
t_info_plugin
|
42
78
|
end
|
43
79
|
|
44
80
|
# Override in your plugin if needed
|
45
|
-
def self.search_where_clause(t, search_key
|
81
|
+
def self.search_where_clause(t, search_key)
|
46
82
|
# Exact matches only
|
47
83
|
where_clause = t[:kb_payment_id].eq(search_key)
|
84
|
+
.or(t[:kb_payment_transaction_id].eq(search_key))
|
48
85
|
.or(t[:message].eq(search_key))
|
49
86
|
.or(t[:authorization].eq(search_key))
|
50
87
|
.or(t[:fraud_review].eq(search_key))
|
51
88
|
|
52
89
|
# Only search successful payments and refunds
|
53
|
-
where_clause = where_clause.and(t[:
|
54
|
-
.and(t[:success].eq(true))
|
90
|
+
where_clause = where_clause.and(t[:success].eq(true))
|
55
91
|
|
56
92
|
where_clause
|
57
93
|
end
|
58
94
|
|
59
95
|
# VisibleForTesting
|
60
|
-
def self.search_query(
|
96
|
+
def self.search_query(search_key, kb_tenant_id, offset = nil, limit = nil)
|
61
97
|
t = self.arel_table
|
62
98
|
|
63
99
|
if kb_tenant_id.nil?
|
64
|
-
query = t.where(search_where_clause(t, search_key
|
100
|
+
query = t.where(search_where_clause(t, search_key))
|
65
101
|
.order(t[:id])
|
66
102
|
else
|
67
|
-
query = t.where(search_where_clause(t, search_key
|
103
|
+
query = t.where(search_where_clause(t, search_key).and(t[:kb_tenant_id].eq(kb_tenant_id)))
|
68
104
|
.order(t[:id])
|
69
105
|
end
|
70
106
|
|
@@ -81,18 +117,16 @@ module Killbill
|
|
81
117
|
query
|
82
118
|
end
|
83
119
|
|
84
|
-
def self.search(search_key, kb_tenant_id, offset = 0, limit = 100
|
85
|
-
api_call = type == :payment ? 'charge' : 'refund'
|
120
|
+
def self.search(search_key, kb_tenant_id, offset = 0, limit = 100)
|
86
121
|
pagination = ::Killbill::Plugin::Model::Pagination.new
|
87
122
|
pagination.current_offset = offset
|
88
|
-
pagination.total_nb_records = self.count_by_sql(self.search_query(
|
89
|
-
pagination.max_nb_records = self.where(:
|
123
|
+
pagination.total_nb_records = self.count_by_sql(self.search_query(search_key, kb_tenant_id))
|
124
|
+
pagination.max_nb_records = self.where(:success => true).count
|
90
125
|
pagination.next_offset = (!pagination.total_nb_records.nil? && offset + limit >= pagination.total_nb_records) ? nil : offset + limit
|
91
126
|
# Reduce the limit if the specified value is larger than the number of records
|
92
127
|
actual_limit = [pagination.max_nb_records, limit].min
|
93
128
|
pagination.iterator = ::Killbill::Plugin::ActiveMerchant::ActiveRecord::StreamyResultSet.new(actual_limit) do |offset, limit|
|
94
|
-
self.find_by_sql(self.search_query(
|
95
|
-
.map { |x| type == :payment ? x.to_payment_response : x.to_refund_response }
|
129
|
+
self.find_by_sql(self.search_query(search_key, kb_tenant_id, offset, limit)).map { |x| x.to_transaction_info_plugin }
|
96
130
|
end
|
97
131
|
pagination
|
98
132
|
end
|
@@ -102,16 +136,6 @@ module Killbill
|
|
102
136
|
authorization
|
103
137
|
end
|
104
138
|
|
105
|
-
# Override in your plugin if needed
|
106
|
-
def first_payment_reference_id
|
107
|
-
nil
|
108
|
-
end
|
109
|
-
|
110
|
-
# Override in your plugin if needed
|
111
|
-
def second_payment_reference_id
|
112
|
-
nil
|
113
|
-
end
|
114
|
-
|
115
139
|
# Override in your plugin if needed
|
116
140
|
def first_reference_id
|
117
141
|
nil
|
@@ -139,44 +163,11 @@ module Killbill
|
|
139
163
|
|
140
164
|
private
|
141
165
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
else
|
148
|
-
amount_in_cents = transaction.amount_in_cents
|
149
|
-
currency = transaction.currency
|
150
|
-
created_date = transaction.created_at
|
151
|
-
end
|
152
|
-
|
153
|
-
if type == :payment
|
154
|
-
p_info_plugin = Killbill::Plugin::Model::PaymentInfoPlugin.new
|
155
|
-
p_info_plugin.kb_payment_id = kb_payment_id
|
156
|
-
p_info_plugin.amount = Money.new(amount_in_cents, currency).to_d if currency
|
157
|
-
p_info_plugin.currency = currency
|
158
|
-
p_info_plugin.created_date = created_date
|
159
|
-
p_info_plugin.effective_date = effective_date
|
160
|
-
p_info_plugin.status = (success ? :PROCESSED : :ERROR)
|
161
|
-
p_info_plugin.gateway_error = gateway_error
|
162
|
-
p_info_plugin.gateway_error_code = gateway_error_code
|
163
|
-
p_info_plugin.first_payment_reference_id = first_reference_id
|
164
|
-
p_info_plugin.second_payment_reference_id = second_reference_id
|
165
|
-
p_info_plugin
|
166
|
-
else
|
167
|
-
r_info_plugin = Killbill::Plugin::Model::RefundInfoPlugin.new
|
168
|
-
r_info_plugin.kb_payment_id = kb_payment_id
|
169
|
-
r_info_plugin.amount = Money.new(amount_in_cents, currency).to_d if currency
|
170
|
-
r_info_plugin.currency = currency
|
171
|
-
r_info_plugin.created_date = created_date
|
172
|
-
r_info_plugin.effective_date = effective_date
|
173
|
-
r_info_plugin.status = (success ? :PROCESSED : :ERROR)
|
174
|
-
r_info_plugin.gateway_error = gateway_error
|
175
|
-
r_info_plugin.gateway_error_code = gateway_error_code
|
176
|
-
r_info_plugin.first_refund_reference_id = first_reference_id
|
177
|
-
r_info_plugin.second_refund_reference_id = second_reference_id
|
178
|
-
r_info_plugin
|
179
|
-
end
|
166
|
+
def create_plugin_property(key, value)
|
167
|
+
prop = Killbill::Plugin::Model::PluginProperty.new
|
168
|
+
prop.key = key
|
169
|
+
prop.value = value
|
170
|
+
prop
|
180
171
|
end
|
181
172
|
end
|
182
173
|
end
|
@@ -8,62 +8,81 @@ module Killbill
|
|
8
8
|
|
9
9
|
self.abstract_class = true
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
class << self
|
12
|
+
def transactions_from_kb_payment_id(kb_payment_id, kb_tenant_id)
|
13
|
+
where(:kb_payment_id => kb_payment_id, :kb_tenant_id => kb_tenant_id).order(:created_at)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
[:authorize, :capture, :purchase, :credit, :refund].each do |transaction_type|
|
17
|
+
define_method("#{transaction_type.to_s}s_from_kb_payment_id") do |kb_payment_id, kb_tenant_id|
|
18
|
+
transaction_from_kb_payment_id(transaction_type.to_s.upcase, kb_payment_id, kb_tenant_id, :multiple)
|
19
|
+
end
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
22
|
+
# For convenience
|
23
|
+
alias_method :authorizations_from_kb_payment_id, :authorizes_from_kb_payment_id
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
rescue
|
27
|
-
do_find_candidate_transaction_for_refund :charge, kb_payment_id, kb_tenant_id, amount_in_cents
|
25
|
+
# void is special: unique void per payment_id
|
26
|
+
def void_from_kb_payment_id(kb_payment_id, kb_tenant_id)
|
27
|
+
transaction_from_kb_payment_id(:VOID, kb_payment_id, kb_tenant_id, :single)
|
28
28
|
end
|
29
|
-
end
|
30
29
|
|
31
|
-
|
30
|
+
def from_kb_payment_transaction_id(kb_payment_transaction_id, kb_tenant_id)
|
31
|
+
transaction_from_kb_payment_transaction_id(nil, kb_payment_transaction_id, kb_tenant_id, :single)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def find_candidate_transaction_for_refund(kb_payment_id, kb_tenant_id, amount_in_cents)
|
35
|
+
begin
|
36
|
+
do_find_candidate_transaction_for_refund(:authorize, kb_payment_id, kb_tenant_id, amount_in_cents)
|
37
|
+
rescue
|
38
|
+
do_find_candidate_transaction_for_refund(:purchase, kb_payment_id, kb_tenant_id, amount_in_cents)
|
39
|
+
end
|
37
40
|
end
|
38
|
-
# Find one successful charge which amount is at least the amount we are trying to refund
|
39
|
-
transactions = where('amount_in_cents >= ? AND api_call = ? AND kb_tenant_id = ? AND kb_payment_id = ?', amount_in_cents, api_call, kb_tenant_id, kb_payment_id)
|
40
|
-
raise "Unable to find transaction for payment #{kb_payment_id} and api_call #{api_call}" if transactions.size == 0
|
41
41
|
|
42
|
-
|
43
|
-
amount_refunded_in_cents = where('api_call = ? and kb_payment_id = ?', :refund, kb_payment_id)
|
44
|
-
.sum('amount_in_cents')
|
42
|
+
private
|
45
43
|
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
def do_find_candidate_transaction_for_refund(api_call, kb_payment_id, kb_tenant_id, amount_in_cents)
|
45
|
+
# Find one successful charge which amount is at least the amount we are trying to refund
|
46
|
+
if kb_tenant_id.nil?
|
47
|
+
transactions = where('amount_in_cents >= ? AND api_call = ? AND kb_tenant_id is NULL AND kb_payment_id = ?', amount_in_cents, api_call, kb_payment_id).order(:created_at)
|
48
|
+
else
|
49
|
+
transactions = where('amount_in_cents >= ? AND api_call = ? AND kb_tenant_id = ? AND kb_payment_id = ?', amount_in_cents, api_call, kb_tenant_id, kb_payment_id).order(:created_at)
|
50
|
+
end
|
51
|
+
raise "Unable to find transaction for payment #{kb_payment_id} and api_call #{api_call}" if transactions.size == 0
|
49
52
|
|
50
|
-
|
51
|
-
|
53
|
+
# We have candidates, but we now need to make sure we didn't refund more than for the specified amount
|
54
|
+
amount_refunded_in_cents = where('api_call = ? and kb_payment_id = ?', :refund, kb_payment_id)
|
55
|
+
.sum('amount_in_cents')
|
52
56
|
|
53
|
-
|
57
|
+
amount_left_to_refund_in_cents = -amount_refunded_in_cents
|
58
|
+
transactions.map { |transaction| amount_left_to_refund_in_cents += transaction.amount_in_cents }
|
59
|
+
raise "Amount #{amount_in_cents} too large to refund for payment #{kb_payment_id}" if amount_left_to_refund_in_cents < amount_in_cents
|
54
60
|
|
55
|
-
|
56
|
-
if kb_tenant_id.nil?
|
57
|
-
transactions = where('api_call = ? AND kb_payment_id = ?', api_call, kb_payment_id)
|
58
|
-
else
|
59
|
-
transactions = where('api_call = ? AND kb_tenant_id = ? AND kb_payment_id = ?', api_call, kb_tenant_id, kb_payment_id)
|
61
|
+
transactions.first
|
60
62
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
|
64
|
+
[:kb_payment_id, :kb_payment_transaction_id].each do |attribute|
|
65
|
+
define_method("transaction_from_#{attribute.to_s}") do |transaction_type, attribute_value, kb_tenant_id, how_many|
|
66
|
+
if kb_tenant_id.nil?
|
67
|
+
if transaction_type.nil?
|
68
|
+
transactions = where("kb_tenant_id is NULL AND #{attribute.to_s} = ?", attribute_value).order(:created_at)
|
69
|
+
else
|
70
|
+
transactions = where("transaction_type = ? AND kb_tenant_id is NULL AND #{attribute.to_s} = ?", transaction_type, attribute_value).order(:created_at)
|
71
|
+
end
|
72
|
+
else
|
73
|
+
if transaction_type.nil?
|
74
|
+
transactions = where("kb_tenant_id = ? AND #{attribute.to_s} = ?", kb_tenant_id, attribute_value).order(:created_at)
|
75
|
+
else
|
76
|
+
transactions = where("transaction_type = ? AND kb_tenant_id = ? AND #{attribute.to_s} = ?", transaction_type, kb_tenant_id, attribute_value).order(:created_at)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
if how_many == :single
|
80
|
+
raise "Kill Bill #{attribute} = #{attribute_value} mapping to multiple plugin transactions" if transactions.size > 1
|
81
|
+
transactions[0]
|
82
|
+
else
|
83
|
+
transactions
|
84
|
+
end
|
85
|
+
end
|
67
86
|
end
|
68
87
|
end
|
69
88
|
end
|