killbill 7.0.3 → 7.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0af413a5183714f9c7cda0b9c2ec1c4240397593
4
- data.tar.gz: 128972b51281d32b3bb1cc9bc4b88887ba7efe36
3
+ metadata.gz: 4d15f7f9e9da5390cf9abe1cb4734e51622842b0
4
+ data.tar.gz: d40ccd578500e93b61b25e3851b3fc46e4872b2a
5
5
  SHA512:
6
- metadata.gz: fc0116cb6ac588e04ae7c4c365ab51d8e24cb04660a505c178c32fab49b82636ae5d22ce9a3e075818df6c312540bc82409c3c410765e68d907ac13071248f3b
7
- data.tar.gz: 507a28b987997ae0c05296400997678606d3a73193b7a510a5fe9f2cf0ef7df2fb820b0d9d17b24a07e6ce1b0fc639bdd2cf002f15ecbb29dc40d8f3171ef95b
6
+ metadata.gz: bd1d6ad6cf260b363d634bdb440098d73d4d55ec143a0f613dccd85e15d5e8546f985647fb79df2f8786c28a3d20df2cdec64fa6bad3e2dd8425e5fc2bbae1da
7
+ data.tar.gz: ae70cbd211f1036e53345e4f4fbd7024eef6eed016311caf4561c832d03674d1075b8093bf6d717265f35e6f320a49434a9e02a6fa05c38383cc9e9e3849660f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- killbill (7.0.3)
4
+ killbill (7.0.4)
5
5
  rack (>= 1.5.2)
6
6
  sinatra (~> 1.3.4)
7
7
  typhoeus (~> 0.6.9)
@@ -56,7 +56,7 @@ GEM
56
56
  diff-lcs (1.1.3)
57
57
  equalizer (0.0.11)
58
58
  erubis (2.7.0)
59
- ethon (0.8.1)
59
+ ethon (0.9.0)
60
60
  ffi (>= 1.3.0)
61
61
  ffi (1.9.10-java)
62
62
  i18n (0.7.0)
data/NEWS CHANGED
@@ -1,3 +1,8 @@
1
+ 7.0.4
2
+ Add support for migrations
3
+ ActiveMerchant: change message column to TEXT
4
+ ActiveMerchant: pass in extra_params to dispatch_to_gateways
5
+
1
6
  7.0.3
2
7
  Java API: set default dates in context to now()
3
8
  Expose the underlying object from LazyEvaluator
data/README.md CHANGED
@@ -138,10 +138,16 @@ Use the plugin generator:
138
138
 
139
139
  ```bash
140
140
  ./script/generate active_merchant gateway_name /path/to/dir
141
+ cd /path/to/dir
142
+ git init .
143
+ git add .
144
+ git commit -m 'Initial'
141
145
  ```
142
146
 
143
147
  Replace `gateway_name` with the snake case of your ActiveMerchant gateway (e.g. `yandex`, `stripe`, `paypal`, etc.).
144
148
 
149
+ The newly generated plugin is in a git repository due to the way that the gemspec file resolves the files to include in the `killbill:package` rake task. The above will add the generated files to a git repository, the handling of which is left to the reader.
150
+
145
151
  This will generate a tree of files ready to be plugged into Kill Bill. To package the plugin, run:
146
152
 
147
153
  ```bash
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.expand_path('../../lib', __FILE__)
3
+ require 'killbill/migration_cli'
4
+
5
+ begin
6
+ Killbill::Cli.start
7
+ rescue => e
8
+ Thor::Shell::Color.new.say e.message, :red
9
+ exit 1
10
+ end
@@ -57,7 +57,7 @@ CREATE TABLE <%= identifier %>_responses (
57
57
  kb_payment_transaction_id varchar(255) DEFAULT NULL,
58
58
  transaction_type varchar(255) DEFAULT NULL,
59
59
  payment_processor_account_id varchar(255) DEFAULT NULL,
60
- message varchar(255) DEFAULT NULL,
60
+ message text DEFAULT NULL,
61
61
  authorisation varchar(255) DEFAULT NULL,
62
62
  fraud_review boolean DEFAULT NULL,
63
63
  test boolean DEFAULT NULL,
@@ -58,7 +58,7 @@ ActiveRecord::Schema.define(:version => 20140410153635) do
58
58
  t.string "kb_payment_transaction_id"
59
59
  t.string "transaction_type"
60
60
  t.string "payment_processor_account_id"
61
- t.string "message"
61
+ t.text "message"
62
62
  t.string "authorization"
63
63
  t.boolean "fraud_review"
64
64
  t.boolean "test"
@@ -361,7 +361,7 @@ module Killbill
361
361
  # TODO Split settlements is partially implemented. Left to be done:
362
362
  # * payment_source should probably be retrieved per gateway
363
363
  # * amount per gateway should be retrieved from the options
364
- def dispatch_to_gateways(operation, kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context, gateway_call_proc, linked_transaction_proc=nil)
364
+ def dispatch_to_gateways(operation, kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context, gateway_call_proc, linked_transaction_proc=nil, extra_params={})
365
365
  kb_transaction = Utils::LazyEvaluator.new { get_kb_transaction(kb_payment_id, kb_payment_transaction_id, context.tenant_id) }
366
366
  amount_in_cents = amount.nil? ? nil : to_cents(amount, currency)
367
367
 
@@ -412,7 +412,7 @@ module Killbill
412
412
 
413
413
  # Perform the operation in the gateway
414
414
  gw_response = gateway_call_proc.call(gateway, linked_transaction, payment_source, amount_in_cents, options)
415
- response, transaction = save_response_and_transaction(gw_response, operation, kb_account_id, context.tenant_id, payment_processor_account_id, kb_payment_id, kb_payment_transaction_id, operation.upcase, amount_in_cents, currency)
415
+ response, transaction = save_response_and_transaction(gw_response, operation, kb_account_id, context.tenant_id, payment_processor_account_id, kb_payment_id, kb_payment_transaction_id, operation.upcase, amount_in_cents, currency, extra_params)
416
416
 
417
417
  # Filter after each gateway call
418
418
  after_gateway(response, transaction, gw_response, context)
@@ -564,10 +564,10 @@ module Killbill
564
564
  account.currency
565
565
  end
566
566
 
567
- def save_response_and_transaction(gw_response, api_call, kb_account_id, kb_tenant_id, payment_processor_account_id, kb_payment_id=nil, kb_payment_transaction_id=nil, transaction_type=nil, amount_in_cents=0, currency=nil)
567
+ def save_response_and_transaction(gw_response, api_call, kb_account_id, kb_tenant_id, payment_processor_account_id, kb_payment_id=nil, kb_payment_transaction_id=nil, transaction_type=nil, amount_in_cents=0, currency=nil, extra_params={})
568
568
  @logger.warn "Unsuccessful #{api_call}: #{gw_response.message}" unless gw_response.success?
569
569
 
570
- response, transaction = @response_model.create_response_and_transaction(@identifier, @transaction_model, api_call, kb_account_id, kb_payment_id, kb_payment_transaction_id, transaction_type, payment_processor_account_id, kb_tenant_id, gw_response, amount_in_cents, currency, {}, @response_model)
570
+ response, transaction = @response_model.create_response_and_transaction(@identifier, @transaction_model, api_call, kb_account_id, kb_payment_id, kb_payment_transaction_id, transaction_type, payment_processor_account_id, kb_tenant_id, gw_response, amount_in_cents, currency, extra_params, @response_model)
571
571
 
572
572
  @logger.debug { "Recorded transaction: #{transaction.inspect}" } unless transaction.nil?
573
573
 
@@ -0,0 +1,109 @@
1
+ require 'logger'
2
+
3
+ require 'active_record'
4
+ require 'arjdbc'
5
+
6
+ require 'jdbc/mariadb'
7
+ Jdbc::MariaDB.load_driver
8
+
9
+ module Killbill
10
+ class Migration
11
+
12
+ class << self
13
+ attr_accessor :ar_patched
14
+ end
15
+
16
+ def initialize(plugin_name, config = nil, logger = Logger.new(STDOUT))
17
+ configure_logging(logger)
18
+ configure_migration(plugin_name)
19
+ configure_connection(config)
20
+
21
+ monkey_patch_ar
22
+ end
23
+
24
+ def sql_for_migration(migrations_paths = ActiveRecord::Migrator.migrations_paths)
25
+ ActiveRecord::Base.connection.readonly = true
26
+
27
+ ActiveRecord::Migrator.migrate(migrations_paths)
28
+
29
+ ActiveRecord::Base.connection.migration_statements
30
+ end
31
+
32
+ def migrate(migrations_paths = ActiveRecord::Migrator.migrations_paths)
33
+ ActiveRecord::Base.connection.readonly = false
34
+
35
+ ActiveRecord::Migrator.migrate(migrations_paths)
36
+ end
37
+
38
+ def current_version
39
+ ActiveRecord::Migrator.current_version
40
+ end
41
+
42
+ def sql_dump(stream = StringIO.new)
43
+ Dir.mktmpdir do |dir|
44
+ filename = File.join(dir, 'structure.sql')
45
+ ActiveRecord::Tasks::DatabaseTasks.structure_dump(@config, filename)
46
+ stream.write(File.read(filename))
47
+ end
48
+ stream
49
+ end
50
+
51
+ def ruby_dump(stream = StringIO.new)
52
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
53
+ end
54
+
55
+ private
56
+
57
+ def configure_logging(logger)
58
+ verbose = ENV['VERBOSE'] ? ENV['VERBOSE'] == 'true' : false
59
+
60
+ ActiveRecord::Base.logger = logger
61
+ ActiveRecord::Base.logger.level = verbose ? Logger::DEBUG : Logger::INFO
62
+
63
+ ActiveRecord::Migration.verbose = verbose
64
+ end
65
+
66
+ def configure_migration(plugin_name)
67
+ ActiveRecord::SchemaMigration.table_name_prefix = "#{plugin_name}_"
68
+ end
69
+
70
+ def configure_connection(config)
71
+ config ||= {}
72
+ db_config = {
73
+ :adapter => ENV['ADAPTER'] || :mysql,
74
+ :driver => ENV['DRIVER'] || 'org.mariadb.jdbc.Driver',
75
+ :username => ENV['USERNAME'] || 'killbill',
76
+ :password => ENV['PASSWORD'] || 'killbill',
77
+ :database => ENV['DB'] || 'killbill',
78
+ :host => ENV['HOST'] || '127.0.0.1'
79
+ }
80
+ config_with_defaults = db_config.merge(config)
81
+ ActiveRecord::Base.establish_connection(config_with_defaults)
82
+
83
+ @config = config_with_defaults.stringify_keys
84
+ end
85
+
86
+ def monkey_patch_ar
87
+ return if self.class.ar_patched
88
+
89
+ ActiveRecord::Base.connection.class.class_eval do
90
+ attr_accessor :migration_statements
91
+ attr_accessor :readonly
92
+
93
+ [:exec_query, :exec_insert, :exec_delete, :exec_update, :exec_query_raw, :execute].each do |method|
94
+ send(:alias_method, "old_#{method}".to_sym, method)
95
+
96
+ define_method(method) do |sql, *args|
97
+ migration_sql = /^(create|alter|drop|insert|delete|update)/i.match(sql)
98
+
99
+ @migration_statements ||= []
100
+ @migration_statements << "#{sql};" if migration_sql
101
+
102
+ send("old_#{method}", sql, *args) if !migration_sql || (migration_sql && !@readonly)
103
+ end
104
+ end
105
+ end
106
+ self.class.ar_patched = true
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,80 @@
1
+ require 'highline'
2
+ require 'thor'
3
+
4
+ require 'killbill/migration'
5
+
6
+ module Killbill
7
+ class Cli < Thor
8
+
9
+ include ::Thor::Actions
10
+
11
+ class_option :adapter,
12
+ :type => :string,
13
+ :default => 'mysql',
14
+ :desc => 'Database adapter'
15
+
16
+ class_option :driver,
17
+ :type => :string,
18
+ :default => 'org.mariadb.jdbc.Driver',
19
+ :desc => 'Database driver'
20
+
21
+ class_option :username,
22
+ :type => :string,
23
+ :default => 'killbill',
24
+ :desc => 'Database username'
25
+
26
+ class_option :password,
27
+ :type => :string,
28
+ :default => 'killbill',
29
+ :desc => 'Database password'
30
+
31
+ class_option :database,
32
+ :type => :string,
33
+ :default => 'killbill',
34
+ :desc => 'Database name'
35
+
36
+ class_option :host,
37
+ :type => :string,
38
+ :default => '127.0.0.1',
39
+ :desc => 'Database hostname'
40
+
41
+ desc 'current_version plugin_name', 'Display the current migration version'
42
+ def current_version(plugin_name)
43
+ say migration(plugin_name, options).current_version, :green
44
+ end
45
+
46
+ method_option :path,
47
+ :type => :string,
48
+ :default => ActiveRecord::Migrator.migrations_paths,
49
+ :desc => 'Folder where to find migration files.'
50
+ desc 'sql_for_migration plugin_name', 'Display the migration SQL'
51
+ def sql_for_migration(plugin_name)
52
+ say migration(plugin_name, options).sql_for_migration(options[:path]).join("\n"), :green
53
+ end
54
+
55
+ method_option :path,
56
+ :type => :string,
57
+ :default => ActiveRecord::Migrator.migrations_paths,
58
+ :desc => 'Folder where to find migration files.'
59
+ desc 'migrate plugin_name', 'Run all migrations'
60
+ def migrate(plugin_name)
61
+ migration(plugin_name, options).migrate(options[:path])
62
+ end
63
+
64
+ desc 'ruby_dump plugin_name', 'Dump the current schema structure (Ruby)'
65
+ def ruby_dump(plugin_name)
66
+ say migration(plugin_name, options).ruby_dump.string, :green
67
+ end
68
+
69
+ desc 'sql_dump plugin_name', 'Dump the current schema structure (SQL)'
70
+ def sql_dump(plugin_name)
71
+ say migration(plugin_name, options).sql_dump.string, :green
72
+ end
73
+
74
+ private
75
+
76
+ def migration(plugin_name, options)
77
+ Killbill::Migration.new(plugin_name, options)
78
+ end
79
+ end
80
+ end
@@ -5,6 +5,8 @@ require 'tmpdir'
5
5
  require 'rake'
6
6
  require 'rubygems/installer'
7
7
 
8
+ require 'killbill/migration'
9
+
8
10
  module Killbill
9
11
  class PluginHelper
10
12
  include Rake::DSL
@@ -64,6 +66,8 @@ module Killbill
64
66
  # Staging area to install gem dependencies
65
67
  # Note the Killbill friendly structure (which we will keep in the tarball)
66
68
  @plugin_gem_target_dir = @plugin_target_dir.join(@gems_dir_path)
69
+
70
+ @migration = Killbill::Migration.new(plugin_name || ENV['PLUGIN_NAME'])
67
71
  end
68
72
 
69
73
  attr_reader :base
@@ -246,6 +250,33 @@ module Killbill
246
250
  task :clean => :clobber do
247
251
  rm_r @package_dir if File.exist?(@package_dir)
248
252
  end
253
+
254
+ namespace :db do
255
+ desc 'Display the current migration version'
256
+ task :current_version do
257
+ puts @migration.current_version
258
+ end
259
+
260
+ desc 'Display the migration SQL'
261
+ task :sql_for_migration do
262
+ puts @migration.sql_for_migration.join("\n")
263
+ end
264
+
265
+ desc 'Run all migrations'
266
+ task :migrate do
267
+ @migration.migrate
268
+ end
269
+
270
+ desc 'Dump the current schema structure (Ruby)'
271
+ task :ruby_dump do
272
+ puts @migration.ruby_dump.string
273
+ end
274
+
275
+ desc 'Dump the current schema structure (SQL)'
276
+ task :sql_dump do
277
+ puts @migration.sql_dump.string
278
+ end
279
+ end
249
280
  end
250
281
  end
251
282
 
@@ -1,3 +1,3 @@
1
1
  module Killbill
2
- VERSION = '7.0.3'
2
+ VERSION = '7.0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.3
4
+ version: 7.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kill Bill core team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-22 00:00:00.000000000 Z
11
+ date: 2016-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -298,7 +298,8 @@ dependencies:
298
298
  type: :development
299
299
  description: Base classes to write plugins.
300
300
  email: killbilling-users@googlegroups.com
301
- executables: []
301
+ executables:
302
+ - killbill-migration
302
303
  extensions: []
303
304
  extra_rdoc_files: []
304
305
  files:
@@ -312,6 +313,7 @@ files:
312
313
  - NEWS
313
314
  - README.md
314
315
  - Rakefile
316
+ - bin/killbill-migration
315
317
  - gen_config/api.conf
316
318
  - gen_config/plugin_api.conf
317
319
  - generators/active_merchant/active_merchant_generator.rb
@@ -538,6 +540,8 @@ files:
538
540
  - lib/killbill/jplugin.rb
539
541
  - lib/killbill/killbill_api.rb
540
542
  - lib/killbill/killbill_logger.rb
543
+ - lib/killbill/migration.rb
544
+ - lib/killbill/migration_cli.rb
541
545
  - lib/killbill/notification.rb
542
546
  - lib/killbill/payment.rb
543
547
  - lib/killbill/payment_control.rb
@@ -599,7 +603,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
599
603
  version: '0'
600
604
  requirements: []
601
605
  rubyforge_project:
602
- rubygems_version: 2.1.9
606
+ rubygems_version: 2.4.6
603
607
  signing_key:
604
608
  specification_version: 4
605
609
  summary: Framework to write Kill Bill plugins in Ruby.