killbill-orbital 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ version = File.read(File.expand_path('../VERSION', __FILE__)).strip
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'killbill-orbital'
5
+ s.version = version
6
+ s.summary = 'Plugin to use Orbital as a gateway.'
7
+ s.description = 'Kill Bill payment plugin for Orbital.'
8
+
9
+ s.required_ruby_version = '>= 1.9.3'
10
+
11
+ s.license = 'Apache License (2.0)'
12
+
13
+ s.author = 'Kill Bill core team'
14
+ s.email = 'killbilling-users@googlegroups.com'
15
+ s.homepage = 'http://killbill.io'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.bindir = 'bin'
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
21
+ s.require_paths = ['lib']
22
+
23
+ s.rdoc_options << '--exclude' << '.'
24
+
25
+ s.add_dependency 'killbill', '~> 7.0'
26
+
27
+ s.add_dependency 'sinatra', '~> 1.3.4'
28
+ s.add_dependency 'thread_safe', '~> 0.3.4'
29
+ s.add_dependency 'activerecord', '~> 4.1.0'
30
+ if defined?(JRUBY_VERSION)
31
+ s.add_dependency 'activerecord-bogacs', '~> 0.3'
32
+ s.add_dependency 'activerecord-jdbc-adapter', '~> 1.3', '< 1.5'
33
+ s.add_dependency 'jruby-openssl', '~> 0.9.7'
34
+ end
35
+ s.add_dependency 'actionpack', '~> 4.1.0'
36
+ s.add_dependency 'actionview', '~> 4.1.0'
37
+ s.add_dependency 'activemerchant', '~> 1.55.0'
38
+ s.add_dependency 'offsite_payments', '~> 2.1.0'
39
+ s.add_dependency 'monetize', '~> 1.1.0'
40
+ s.add_dependency 'money', '~> 6.5.1'
41
+
42
+ s.add_development_dependency 'jbundler', '~> 0.9.2'
43
+ s.add_development_dependency 'rake', '>= 10.0.0'
44
+ s.add_development_dependency 'rspec', '~> 2.12.0'
45
+ if defined?(JRUBY_VERSION)
46
+ s.add_development_dependency 'jdbc-sqlite3', '~> 3.7'
47
+ s.add_development_dependency 'jdbc-mariadb', '~> 1.1'
48
+ s.add_development_dependency 'jdbc-postgres', '~> 9.4'
49
+ else
50
+ s.add_development_dependency 'sqlite3', '~> 1.3.7'
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ mainClass=Killbill::Orbital::PaymentPlugin
2
+ require=orbital
3
+ pluginType=PAYMENT
@@ -0,0 +1,141 @@
1
+ module Killbill #:nodoc:
2
+ module Orbital #:nodoc:
3
+ class PaymentPlugin < ::Killbill::Plugin::ActiveMerchant::PaymentPlugin
4
+
5
+ def initialize
6
+ gateway_builder = Proc.new do |config|
7
+ ::ActiveMerchant::Billing::OrbitalGateway.new :login => config[:login],
8
+ :password => config[:password],
9
+ # ActiveMerchant expects it to be a String
10
+ :merchant_id => config[:merchant_id].to_s
11
+ end
12
+
13
+ super(gateway_builder,
14
+ :orbital,
15
+ ::Killbill::Orbital::OrbitalPaymentMethod,
16
+ ::Killbill::Orbital::OrbitalTransaction,
17
+ ::Killbill::Orbital::OrbitalResponse)
18
+ end
19
+
20
+ def on_event(event)
21
+ # Require to deal with per tenant configuration invalidation
22
+ super(event)
23
+ #
24
+ # Custom event logic could be added below...
25
+ #
26
+ end
27
+
28
+ def authorize_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
29
+ # Pass extra parameters for the gateway here
30
+ options = {}
31
+
32
+ properties = merge_properties(properties, options)
33
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
34
+ end
35
+
36
+ def capture_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
37
+ # Pass extra parameters for the gateway here
38
+ options = {}
39
+
40
+ properties = merge_properties(properties, options)
41
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
42
+ end
43
+
44
+ def purchase_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
45
+ # Pass extra parameters for the gateway here
46
+ options = {}
47
+
48
+ properties = merge_properties(properties, options)
49
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
50
+ end
51
+
52
+ def void_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context)
53
+ # Pass extra parameters for the gateway here
54
+ options = {}
55
+
56
+ properties = merge_properties(properties, options)
57
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context)
58
+ end
59
+
60
+ def credit_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
61
+ # Pass extra parameters for the gateway here
62
+ options = {}
63
+
64
+ properties = merge_properties(properties, options)
65
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
66
+ end
67
+
68
+ def refund_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
69
+ # Pass extra parameters for the gateway here
70
+ options = {}
71
+
72
+ properties = merge_properties(properties, options)
73
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
74
+ end
75
+
76
+ def get_payment_info(kb_account_id, kb_payment_id, properties, context)
77
+ # Pass extra parameters for the gateway here
78
+ options = {}
79
+
80
+ properties = merge_properties(properties, options)
81
+ super(kb_account_id, kb_payment_id, properties, context)
82
+ end
83
+
84
+ def search_payments(search_key, offset, limit, properties, context)
85
+ # Pass extra parameters for the gateway here
86
+ options = {}
87
+
88
+ properties = merge_properties(properties, options)
89
+ super(search_key, offset, limit, properties, context)
90
+ end
91
+
92
+ def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context)
93
+ # Pass extra parameters for the gateway here
94
+ options = {}
95
+
96
+ properties = merge_properties(properties, options)
97
+ super(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context)
98
+ end
99
+
100
+ def delete_payment_method(kb_account_id, kb_payment_method_id, properties, context)
101
+ # Pass extra parameters for the gateway here
102
+ options = {}
103
+
104
+ properties = merge_properties(properties, options)
105
+ super(kb_account_id, kb_payment_method_id, properties, context)
106
+ end
107
+
108
+ def get_payment_method_detail(kb_account_id, kb_payment_method_id, properties, context)
109
+ # Pass extra parameters for the gateway here
110
+ options = {}
111
+
112
+ properties = merge_properties(properties, options)
113
+ super(kb_account_id, kb_payment_method_id, properties, context)
114
+ end
115
+
116
+ def set_default_payment_method(kb_account_id, kb_payment_method_id, properties, context)
117
+ # TODO
118
+ end
119
+
120
+ def get_payment_methods(kb_account_id, refresh_from_gateway, properties, context)
121
+ # Pass extra parameters for the gateway here
122
+ options = {}
123
+
124
+ properties = merge_properties(properties, options)
125
+ super(kb_account_id, refresh_from_gateway, properties, context)
126
+ end
127
+
128
+ def search_payment_methods(search_key, offset, limit, properties, context)
129
+ # Pass extra parameters for the gateway here
130
+ options = {}
131
+
132
+ properties = merge_properties(properties, options)
133
+ super(search_key, offset, limit, properties, context)
134
+ end
135
+
136
+ def reset_payment_methods(kb_account_id, payment_methods, properties, context)
137
+ super
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,50 @@
1
+ # -- encoding : utf-8 --
2
+
3
+ set :views, File.expand_path(File.dirname(__FILE__) + '/views')
4
+
5
+ include Killbill::Plugin::ActiveMerchant::Sinatra
6
+
7
+ configure do
8
+ # Usage: rackup -Ilib -E test
9
+ if development? or test?
10
+ # Make sure the plugin is initialized
11
+ plugin = ::Killbill::Orbital::PaymentPlugin.new
12
+ plugin.logger = Logger.new(STDOUT)
13
+ plugin.logger.level = Logger::INFO
14
+ plugin.conf_dir = File.dirname(File.dirname(__FILE__)) + '/..'
15
+ plugin.start_plugin
16
+ end
17
+ end
18
+
19
+ helpers do
20
+ def plugin(session = {})
21
+ ::Killbill::Orbital::PrivatePaymentPlugin.new(session)
22
+ end
23
+ end
24
+
25
+ # curl -v http://127.0.0.1:9292/plugins/killbill-orbital/1.0/pms/1
26
+ get '/plugins/killbill-orbital/1.0/pms/:id', :provides => 'json' do
27
+ if pm = ::Killbill::Orbital::OrbitalPaymentMethod.find_by_id(params[:id].to_i)
28
+ pm.to_json
29
+ else
30
+ status 404
31
+ end
32
+ end
33
+
34
+ # curl -v http://127.0.0.1:9292/plugins/killbill-orbital/1.0/transactions/1
35
+ get '/plugins/killbill-orbital/1.0/transactions/:id', :provides => 'json' do
36
+ if transaction = ::Killbill::Orbital::OrbitalTransaction.find_by_id(params[:id].to_i)
37
+ transaction.to_json
38
+ else
39
+ status 404
40
+ end
41
+ end
42
+
43
+ # curl -v http://127.0.0.1:9292/plugins/killbill-orbital/1.0/responses/1
44
+ get '/plugins/killbill-orbital/1.0/responses/:id', :provides => 'json' do
45
+ if transaction = ::Killbill::Orbital::OrbitalResponse.find_by_id(params[:id].to_i)
46
+ transaction.to_json
47
+ else
48
+ status 404
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ class OrbitalGateway
4
+
5
+ def store(creditcard, options = {})
6
+ add_customer_profile(creditcard, options)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ module Killbill #:nodoc:
2
+ module Orbital #:nodoc:
3
+ class OrbitalPaymentMethod < ::Killbill::Plugin::ActiveMerchant::ActiveRecord::PaymentMethod
4
+
5
+ self.table_name = 'orbital_payment_methods'
6
+
7
+ def self.from_response(kb_account_id, kb_payment_method_id, kb_tenant_id, cc_or_token, response, options, extra_params = {}, model = ::Killbill::Orbital::OrbitalPaymentMethod)
8
+ super(kb_account_id,
9
+ kb_payment_method_id,
10
+ kb_tenant_id,
11
+ cc_or_token,
12
+ response,
13
+ options,
14
+ {
15
+ :cc_number => extract(response, 'cc_account_num'),
16
+ }.merge!(extra_params),
17
+ model)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,84 @@
1
+ module Killbill #:nodoc:
2
+ module Orbital #:nodoc:
3
+ class OrbitalResponse < ::Killbill::Plugin::ActiveMerchant::ActiveRecord::Response
4
+
5
+ self.table_name = 'orbital_responses'
6
+
7
+ has_one :orbital_transaction
8
+
9
+ def self.from_response(api_call, kb_account_id, kb_payment_id, kb_payment_transaction_id, transaction_type, payment_processor_account_id, kb_tenant_id, response, extra_params = {}, model = ::Killbill::Orbital::OrbitalResponse)
10
+ super(api_call,
11
+ kb_account_id,
12
+ kb_payment_id,
13
+ kb_payment_transaction_id,
14
+ transaction_type,
15
+ payment_processor_account_id,
16
+ kb_tenant_id,
17
+ response,
18
+ orbital_response_params(response).merge!(extra_params),
19
+ model)
20
+ end
21
+
22
+ def self.orbital_response_params(response)
23
+ {
24
+ :params_account_num => extract(response, 'account_num'),
25
+ :params_address_1 => extract(response, 'address_1'),
26
+ :params_address_2 => extract(response, 'address_2'),
27
+ :params_approval_status => extract(response, 'approval_status'),
28
+ :params_auth_code => extract(response, 'auth_code'),
29
+ :params_avs_resp_code => extract(response, 'avs_resp_code'),
30
+ :params_card_brand => extract(response, 'card_brand'),
31
+ :params_cavv_resp_code => extract(response, 'cavv_resp_code'),
32
+ :params_cc_account_num => extract(response, 'cc_account_num'),
33
+ :params_cc_expire_date => extract(response, 'cc_expire_date'),
34
+ :params_country_fraud_filter_status => extract(response, 'country_fraud_filter_status'),
35
+ :params_customer_bin => extract(response, 'customer_bin'),
36
+ :params_customer_city => extract(response, 'customer_city'),
37
+ :params_customer_country_code => extract(response, 'customer_country_code'),
38
+ :params_customer_email => extract(response, 'customer_email'),
39
+ :params_customer_merchant_id => extract(response, 'customer_merchant_id'),
40
+ :params_customer_name => extract(response, 'customer_name'),
41
+ :params_customer_phone => extract(response, 'customer_phone'),
42
+ :params_customer_profile_action => extract(response, 'customer_profile_action'),
43
+ :params_customer_profile_message => extract(response, 'customer_profile_message'),
44
+ :params_customer_profile_order_override_ind => extract(response, 'customer_profile_order_override_ind'),
45
+ :params_customer_ref_num => extract(response, 'customer_ref_num'),
46
+ :params_customer_state => extract(response, 'customer_state'),
47
+ :params_customer_zip => extract(response, 'customer_zip'),
48
+ :params_cvv2_resp_code => extract(response, 'cvv2_resp_code'),
49
+ :params_ecp_account_dda => extract(response, 'ecp_account_dda'),
50
+ :params_ecp_account_rt => extract(response, 'ecp_account_rt'),
51
+ :params_ecp_account_type => extract(response, 'ecp_account_type'),
52
+ :params_ecp_bank_pmt_dlv => extract(response, 'ecp_bank_pmt_dlv'),
53
+ :params_host_avs_resp_code => extract(response, 'host_avs_resp_code'),
54
+ :params_host_cvv2_resp_code => extract(response, 'host_cvv2_resp_code'),
55
+ :params_host_resp_code => extract(response, 'host_resp_code'),
56
+ :params_industry_type => extract(response, 'industry_type'),
57
+ :params_iso_country_code => extract(response, 'iso_country_code'),
58
+ :params_merchant_id => extract(response, 'merchant_id'),
59
+ :params_message_type => extract(response, 'message_type'),
60
+ :params_order_default_amount => extract(response, 'order_default_amount'),
61
+ :params_order_default_description => extract(response, 'order_default_description'),
62
+ :params_order_id => extract(response, 'order_id'),
63
+ :params_partial_auth_occurred => extract(response, 'partial_auth_occurred'),
64
+ :params_proc_status => extract(response, 'proc_status'),
65
+ :params_profile_proc_status => extract(response, 'profile_proc_status'),
66
+ :params_recurring_advice_cd => extract(response, 'recurring_advice_cd'),
67
+ :params_redeemed_amount => extract(response, 'redeemed_amount'),
68
+ :params_remaining_balance => extract(response, 'remaining_balance'),
69
+ :params_requested_amount => extract(response, 'requested_amount'),
70
+ :params_resp_code => extract(response, 'resp_code'),
71
+ :params_resp_msg => extract(response, 'resp_msg'),
72
+ :params_resp_time => extract(response, 'resp_time'),
73
+ :params_status => extract(response, 'status'),
74
+ :params_status_msg => extract(response, 'status_msg'),
75
+ :params_switch_solo_issue_num => extract(response, 'switch_solo_issue_num'),
76
+ :params_switch_solo_start_date => extract(response, 'switch_solo_start_date'),
77
+ :params_terminal_id => extract(response, 'terminal_id'),
78
+ :params_tx_ref_idx => extract(response, 'tx_ref_idx'),
79
+ :params_tx_ref_num => extract(response, 'tx_ref_num'),
80
+ }
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,11 @@
1
+ module Killbill #:nodoc:
2
+ module Orbital #:nodoc:
3
+ class OrbitalTransaction < ::Killbill::Plugin::ActiveMerchant::ActiveRecord::Transaction
4
+
5
+ self.table_name = 'orbital_transactions'
6
+
7
+ belongs_to :orbital_response
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module Killbill #:nodoc:
2
+ module Orbital #:nodoc:
3
+ class PrivatePaymentPlugin < ::Killbill::Plugin::ActiveMerchant::PrivatePaymentPlugin
4
+ def initialize(session = {})
5
+ super(:orbital,
6
+ ::Killbill::Orbital::OrbitalPaymentMethod,
7
+ ::Killbill::Orbital::OrbitalTransaction,
8
+ ::Killbill::Orbital::OrbitalResponse,
9
+ session)
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/orbital.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'openssl'
2
+ require 'action_controller'
3
+ require 'active_record'
4
+ require 'action_view'
5
+ require 'active_merchant'
6
+ require 'active_support'
7
+ require 'bigdecimal'
8
+ require 'money'
9
+ require 'monetize'
10
+ require 'offsite_payments'
11
+ require 'pathname'
12
+ require 'sinatra'
13
+ require 'singleton'
14
+ require 'yaml'
15
+
16
+ require 'killbill'
17
+ require 'killbill/helpers/active_merchant'
18
+
19
+ require 'orbital/ext/active_merchant/active_merchant.rb'
20
+
21
+ require 'orbital/api'
22
+ require 'orbital/private_api'
23
+
24
+ require 'orbital/models/payment_method'
25
+ require 'orbital/models/response'
26
+ require 'orbital/models/transaction'
data/orbital.yml ADDED
@@ -0,0 +1,34 @@
1
+ :orbital:
2
+ - :account_id: default
3
+ :test: true
4
+ :login: <%= ENV['LOGIN'] %>
5
+ :password: <%= ENV['PASSWORD'] %>
6
+ :merchant_id: <%= ENV['MERCHANT_ID'] %>
7
+
8
+ :database:
9
+ # SQLite (development)
10
+ :adapter: sqlite3
11
+ :database: test.db
12
+ # For PostgreSQL
13
+ # :adapter: postgresql
14
+ # :database: 'killbill'
15
+ # For MySQL
16
+ # :adapter: mariadb
17
+ # :username: 'killbill'
18
+ # :password: 'killbill'
19
+ # :database: 'killbill' # or set the URL :
20
+ # #:url: jdbc:mysql://127.0.0.1:3306/killbill
21
+ # :driver: org.mariadb.jdbc.Driver # as in KB
22
+ # :pool: 30 # AR's default is max 5 connections
23
+ # In Kill Bill
24
+ # :adapter: mysql
25
+ # :jndi: 'killbill/osgi/jdbc'
26
+ # :pool: false # false-pool (JNDI pool's max)
27
+ # # uncomment if pool does not support JDBC4 :
28
+ # #:connection_alive_sql: 'select 1'
29
+ # # MySQL adapter #configure_connection defaults :
30
+ # # @@SESSION.sql_auto_is_null = 0,
31
+ # # @@SESSION.wait_timeout = 2147483,
32
+ # # @@SESSION.sql_mode = 'STRICT_ALL_TABLES'
33
+ # # ... can be disabled (on AR-JDBC 1.4) using :
34
+ # :configure_connection: false