killbill-payu-latam 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,49 @@
1
+ version = File.read(File.expand_path('../VERSION', __FILE__)).strip
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'killbill-payu-latam'
5
+ s.version = version
6
+ s.summary = 'Plugin to use PayU Latam as a gateway.'
7
+ s.description = 'Kill Bill payment plugin for PayU Latam.'
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://kill-bill.org'
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', '~> 3.2.0'
26
+ s.add_dependency 'aktivemerchant', '~> 2.0.0'
27
+ s.add_dependency 'offsite_payments', '~> 2.0.1'
28
+ s.add_dependency 'activerecord', '~> 4.1.0'
29
+ s.add_dependency 'actionpack', '~> 4.1.0'
30
+ s.add_dependency 'actionview', '~> 4.1.0'
31
+ s.add_dependency 'activesupport', '~> 4.1.0'
32
+ s.add_dependency 'money', '~> 6.1.1'
33
+ s.add_dependency 'monetize', '~> 0.3.0'
34
+ s.add_dependency 'sinatra', '~> 1.3.4'
35
+ if defined?(JRUBY_VERSION)
36
+ s.add_dependency 'activerecord-jdbcmysql-adapter', '~> 1.3.7'
37
+ # Required to avoid errors like java.lang.NoClassDefFoundError: org/bouncycastle/asn1/DERBoolean
38
+ s.add_dependency 'jruby-openssl', '~> 0.9.4'
39
+ end
40
+
41
+ s.add_development_dependency 'jbundler', '~> 0.4.1'
42
+ s.add_development_dependency 'rake', '>= 10.0.0'
43
+ s.add_development_dependency 'rspec', '~> 2.12.0'
44
+ if defined?(JRUBY_VERSION)
45
+ s.add_development_dependency 'activerecord-jdbcsqlite3-adapter', '~> 1.3.7'
46
+ else
47
+ s.add_development_dependency 'sqlite3', '~> 1.3.7'
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ mainClass=Killbill::PayuLatam::PaymentPlugin
2
+ require=payu_latam
3
+ pluginType=PAYMENT
@@ -0,0 +1,25 @@
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 'payu_latam/api'
20
+ require 'payu_latam/private_api'
21
+
22
+ require 'payu_latam/models/payment_method'
23
+ require 'payu_latam/models/response'
24
+ require 'payu_latam/models/transaction'
25
+
@@ -0,0 +1,184 @@
1
+ module Killbill #:nodoc:
2
+ module PayuLatam #:nodoc:
3
+ class PaymentPlugin < ::Killbill::Plugin::ActiveMerchant::PaymentPlugin
4
+
5
+ def initialize
6
+ gateway_builder = Proc.new do |config|
7
+ ::ActiveMerchant::Billing::PayULatamGateway.new :api_login => config[:api_login],
8
+ :api_key => config[:api_key],
9
+ :country_account_id => config[:country_account_id],
10
+ :merchant_id => config[:merchant_id]
11
+ end
12
+
13
+ super(gateway_builder,
14
+ :payu_latam,
15
+ ::Killbill::PayuLatam::PayuLatamPaymentMethod,
16
+ ::Killbill::PayuLatam::PayuLatamTransaction,
17
+ ::Killbill::PayuLatam::PayuLatamResponse)
18
+ end
19
+
20
+ def authorize_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
21
+ # Pass extra parameters for the gateway here
22
+ options = {}
23
+
24
+ add_required_options(properties, options)
25
+
26
+ properties = merge_properties(properties, options)
27
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
28
+ end
29
+
30
+ def capture_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
31
+ # Pass extra parameters for the gateway here
32
+ options = {}
33
+
34
+ add_required_options(properties, options)
35
+
36
+ properties = merge_properties(properties, options)
37
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
38
+ end
39
+
40
+ def purchase_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
41
+ # Pass extra parameters for the gateway here
42
+ options = {}
43
+
44
+ add_required_options(properties, options)
45
+
46
+ properties = merge_properties(properties, options)
47
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
48
+ end
49
+
50
+ def void_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, properties, context)
51
+ # Pass extra parameters for the gateway here
52
+ options = {}
53
+
54
+ add_required_options(properties, 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
+ add_required_options(properties, options)
65
+
66
+ properties = merge_properties(properties, options)
67
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
68
+ end
69
+
70
+ def refund_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
71
+ # Pass extra parameters for the gateway here
72
+ options = {}
73
+
74
+ add_required_options(properties, options)
75
+
76
+ properties = merge_properties(properties, options)
77
+ super(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
78
+ end
79
+
80
+ def get_payment_info(kb_account_id, kb_payment_id, properties, context)
81
+ # Pass extra parameters for the gateway here
82
+ options = {}
83
+
84
+ properties = merge_properties(properties, options)
85
+ super(kb_account_id, kb_payment_id, properties, context)
86
+ end
87
+
88
+ def search_payments(search_key, offset, limit, properties, context)
89
+ # Pass extra parameters for the gateway here
90
+ options = {}
91
+
92
+ properties = merge_properties(properties, options)
93
+ super(search_key, offset, limit, properties, context)
94
+ end
95
+
96
+ def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context)
97
+ # Pass extra parameters for the gateway here
98
+ options = {
99
+ :payer_user_id => kb_account_id
100
+ }
101
+
102
+ add_required_options(properties, options)
103
+
104
+ properties = merge_properties(properties, options)
105
+ super(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context)
106
+ end
107
+
108
+ def delete_payment_method(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 get_payment_method_detail(kb_account_id, kb_payment_method_id, properties, context)
117
+ # Pass extra parameters for the gateway here
118
+ options = {}
119
+
120
+ properties = merge_properties(properties, options)
121
+ super(kb_account_id, kb_payment_method_id, properties, context)
122
+ end
123
+
124
+ def set_default_payment_method(kb_account_id, kb_payment_method_id, properties, context)
125
+ # TODO
126
+ end
127
+
128
+ def get_payment_methods(kb_account_id, refresh_from_gateway, properties, context)
129
+ # Pass extra parameters for the gateway here
130
+ options = {}
131
+
132
+ properties = merge_properties(properties, options)
133
+ super(kb_account_id, refresh_from_gateway, properties, context)
134
+ end
135
+
136
+ def search_payment_methods(search_key, offset, limit, properties, context)
137
+ # Pass extra parameters for the gateway here
138
+ options = {}
139
+
140
+ properties = merge_properties(properties, options)
141
+ super(search_key, offset, limit, properties, context)
142
+ end
143
+
144
+ def reset_payment_methods(kb_account_id, payment_methods, properties, context)
145
+ super
146
+ end
147
+
148
+ def build_form_descriptor(kb_account_id, descriptor_fields, properties, context)
149
+ # Pass extra parameters for the gateway here
150
+ options = {}
151
+ properties = merge_properties(properties, options)
152
+
153
+ # Add your custom static hidden tags here
154
+ options = {
155
+ #:token => config[:payu_latam][:token]
156
+ }
157
+ descriptor_fields = merge_properties(descriptor_fields, options)
158
+
159
+ super(kb_account_id, descriptor_fields, properties, context)
160
+ end
161
+
162
+ def process_notification(notification, properties, context)
163
+ # Pass extra parameters for the gateway here
164
+ options = {}
165
+ properties = merge_properties(properties, options)
166
+
167
+ super(notification, properties, context) do |gw_notification, service|
168
+ # Retrieve the payment
169
+ # gw_notification.kb_payment_id =
170
+ #
171
+ # Set the response body
172
+ # gw_notification.entity =
173
+ end
174
+ end
175
+
176
+ private
177
+
178
+ def add_required_options(properties, options)
179
+ language = find_value_from_properties(properties, 'language') || 'en'
180
+ options[:language] ||= language
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,84 @@
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::PayuLatam::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::PayuLatam::PrivatePaymentPlugin.new(:payu_latam,
22
+ ::Killbill::PayuLatam::PayuLatamPaymentMethod,
23
+ ::Killbill::PayuLatam::PayuLatamTransaction,
24
+ ::Killbill::PayuLatam::PayuLatamResponse,
25
+ session)
26
+ end
27
+ end
28
+
29
+ # curl -v http://127.0.0.1:9292/plugins/killbill-payu-latam/form
30
+ get '/plugins/killbill-payu-latam/form', :provides => 'html' do
31
+ order_id = request.GET['order_id']
32
+ account_id = request.GET['account_id']
33
+ options = {
34
+ :amount => request.GET['amount'],
35
+ :currency => request.GET['currency'],
36
+ :test => request.GET['test'],
37
+ :credential2 => request.GET['credential2'],
38
+ :credential3 => request.GET['credential3'],
39
+ :credential4 => request.GET['credential4'],
40
+ :country => request.GET['country'],
41
+ :account_name => request.GET['account_name'],
42
+ :transaction_type => request.GET['transaction_type'],
43
+ :authcode => request.GET['authcode'],
44
+ :notify_url => request.GET['notify_url'],
45
+ :return_url => request.GET['return_url'],
46
+ :redirect_param => request.GET['redirect_param'],
47
+ :forward_url => request.GET['forward_url']
48
+ }
49
+
50
+ @form = plugin(session).payment_form_for(order_id, account_id, :payu_latam, options) do |service|
51
+ # Add your custom hidden tags here, e.g.
52
+ #service.token = config[:payu_latam][:token]
53
+ submit_tag 'Submit'
54
+ end
55
+
56
+ erb :form
57
+ end
58
+
59
+ # curl -v http://127.0.0.1:9292/plugins/killbill-payu-latam/1.0/pms/1
60
+ get '/plugins/killbill-payu-latam/1.0/pms/:id', :provides => 'json' do
61
+ if pm = ::Killbill::PayuLatam::PayuLatamPaymentMethod.find_by_id(params[:id].to_i)
62
+ pm.to_json
63
+ else
64
+ status 404
65
+ end
66
+ end
67
+
68
+ # curl -v http://127.0.0.1:9292/plugins/killbill-payu-latam/1.0/transactions/1
69
+ get '/plugins/killbill-payu-latam/1.0/transactions/:id', :provides => 'json' do
70
+ if transaction = ::Killbill::PayuLatam::PayuLatamTransaction.find_by_id(params[:id].to_i)
71
+ transaction.to_json
72
+ else
73
+ status 404
74
+ end
75
+ end
76
+
77
+ # curl -v http://127.0.0.1:9292/plugins/killbill-payu-latam/1.0/responses/1
78
+ get '/plugins/killbill-payu-latam/1.0/responses/:id', :provides => 'json' do
79
+ if transaction = ::Killbill::PayuLatam::PayuLatamResponse.find_by_id(params[:id].to_i)
80
+ transaction.to_json
81
+ else
82
+ status 404
83
+ end
84
+ end
@@ -0,0 +1,23 @@
1
+ module Killbill #:nodoc:
2
+ module PayuLatam #:nodoc:
3
+ class PayuLatamPaymentMethod < ::Killbill::Plugin::ActiveMerchant::ActiveRecord::PaymentMethod
4
+
5
+ self.table_name = 'payu_latam_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::PayuLatam::PayuLatamPaymentMethod)
8
+ super(kb_account_id,
9
+ kb_payment_method_id,
10
+ kb_tenant_id,
11
+ cc_or_token,
12
+ response,
13
+ options,
14
+ {
15
+ # Pass custom key/values here
16
+ #:params_id => extract(response, 'id'),
17
+ #:params_card_id => extract(response, 'card', 'id')
18
+ }.merge!(extra_params),
19
+ model)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Killbill #:nodoc:
2
+ module PayuLatam #:nodoc:
3
+ class PayuLatamResponse < ::Killbill::Plugin::ActiveMerchant::ActiveRecord::Response
4
+
5
+ self.table_name = 'payu_latam_responses'
6
+
7
+ has_one :payu_latam_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::PayuLatam::PayuLatamResponse)
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
+ {
19
+ # Pass custom key/values here
20
+ #:params_id => extract(response, 'id'),
21
+ #:params_card_id => extract(response, 'card', 'id')
22
+ }.merge!(extra_params),
23
+ model)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Killbill #:nodoc:
2
+ module PayuLatam #:nodoc:
3
+ class PayuLatamTransaction < ::Killbill::Plugin::ActiveMerchant::ActiveRecord::Transaction
4
+
5
+ self.table_name = 'payu_latam_transactions'
6
+
7
+ belongs_to :payu_latam_response
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module Killbill #:nodoc:
2
+ module PayuLatam #:nodoc:
3
+ class PrivatePaymentPlugin < ::Killbill::Plugin::ActiveMerchant::PrivatePaymentPlugin
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <body>
4
+
5
+ <%= @form %>
6
+
7
+ </body>
8
+ </html>
@@ -0,0 +1,54 @@
1
+ # See http://docs.payulatam.com/en/api-integration/proof-of-payment/
2
+ :payu_latam:
3
+ - :account_id: colombia
4
+ :test: true
5
+ :api_login: 11959c415b33d0c
6
+ :api_key: 6u39nqhq8ftd0hlvnjfs66eh8c
7
+ :country_account_id: 500538
8
+ :merchant_id: 500238
9
+ - :account_id: panama
10
+ :test: true
11
+ :api_login: 11959c415b33d0c
12
+ :api_key: 6u39nqhq8ftd0hlvnjfs66eh8c
13
+ :country_account_id: 500537
14
+ :merchant_id: 500238
15
+ - :account_id: peru
16
+ :test: true
17
+ :api_login: 11959c415b33d0c
18
+ :api_key: 6u39nqhq8ftd0hlvnjfs66eh8c
19
+ :country_account_id: 500546
20
+ :merchant_id: 500238
21
+ - :account_id: mexico
22
+ :test: true
23
+ :api_login: 11959c415b33d0c
24
+ :api_key: 6u39nqhq8ftd0hlvnjfs66eh8c
25
+ :country_account_id: 500547
26
+ :merchant_id: 500238
27
+ - :account_id: argentina
28
+ :test: true
29
+ :api_login: 11959c415b33d0c
30
+ :api_key: 6u39nqhq8ftd0hlvnjfs66eh8c
31
+ :country_account_id: 509171
32
+ :merchant_id: 500238
33
+ - :account_id: brazil
34
+ :test: true
35
+ :api_login: 403ba744e9827f3
36
+ :api_key: 676k86ks53la6tni6clgd30jf6
37
+ :country_account_id: 500719
38
+ :merchant_id: 500365
39
+
40
+ :database:
41
+ :adapter: sqlite3
42
+ :database: test.db
43
+ # For MySQL
44
+ # :adapter: 'jdbcmysql'
45
+ # :username: 'killbill'
46
+ # :password: 'killbill'
47
+ # :driver: 'com.mysql.jdbc.Driver'
48
+ # :url: 'jdbc:mysql://127.0.0.1:3306/killbill'
49
+ # In Kill Bill
50
+ # :adapter: 'jdbcmysql'
51
+ # :jndi: 'killbill/osgi/jdbc'
52
+ # :driver: 'com.mysql.jdbc.Driver'
53
+ # :connection_alive_sql: 'select 1'
54
+ # :pool: 250