killbill-litle 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -93,7 +93,9 @@ The plugin expects a `litle.yml` configuration file containing the following:
93
93
 
94
94
  ```
95
95
  :litle:
96
- :merchant_id: 'your-merchant-id'
96
+ :merchant_id:
97
+ :USD: 'your-merchant-id-USD'
98
+ :EUR: 'your-merchant-id-EURO'
97
99
  :password: 'your-password'
98
100
  :username: 'your-username'
99
101
  # Optional, if you are using PayPage
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.2.0
data/lib/litle/api.rb CHANGED
@@ -2,11 +2,10 @@ module Killbill::Litle
2
2
  class PaymentPlugin < Killbill::Plugin::Payment
3
3
  def start_plugin
4
4
  Killbill::Litle.initialize! @logger, @conf_dir, @kb_apis
5
- @gateway = Killbill::Litle.gateway
6
5
 
7
6
  super
8
7
 
9
- @logger.info "Killbill::Litle::PaymentPlugin started"
8
+ @logger.info 'Killbill::Litle::PaymentPlugin started'
10
9
  end
11
10
 
12
11
  # return DB connections to the Pool if required
@@ -30,7 +29,8 @@ module Killbill::Litle
30
29
  token = get_token(kb_payment_method_id)
31
30
 
32
31
  # Go to Litle
33
- litle_response = @gateway.purchase amount_in_cents, ActiveMerchant::Billing::LitleGateway::LitleCardToken.new(:token => token), options
32
+ gateway = Killbill::Litle.gateway_for_currency(currency)
33
+ litle_response = gateway.purchase amount_in_cents, ActiveMerchant::Billing::LitleGateway::LitleCardToken.new(:token => token), options
34
34
  response = save_response_and_transaction litle_response, :charge, kb_payment_id, amount_in_cents
35
35
 
36
36
  response.to_payment_response
@@ -52,7 +52,8 @@ module Killbill::Litle
52
52
  options[:merchant] ||= report_group_for_currency(currency)
53
53
 
54
54
  # Go to Litle
55
- litle_response = @gateway.credit amount_in_cents, litle_transaction.litle_txn_id, options
55
+ gateway = Killbill::Litle.gateway_for_currency(currency)
56
+ litle_response = gateway.credit amount_in_cents, litle_transaction.litle_txn_id, options
56
57
  response = save_response_and_transaction litle_response, :refund, kb_payment_id, amount_in_cents
57
58
 
58
59
  response.to_refund_response
@@ -72,7 +73,10 @@ module Killbill::Litle
72
73
 
73
74
  # TODO Add support for real credit cards
74
75
  token = find_value_from_payment_method_props payment_method_props, 'paypageRegistrationId'
75
- litle_response = @gateway.store token, options
76
+
77
+ currency = account_currency(kb_account_id)
78
+ gateway = Killbill::Litle.gateway_for_currency(currency)
79
+ litle_response = gateway.store token, options
76
80
  response = save_response_and_transaction litle_response, :add_payment_method
77
81
 
78
82
  if response.success
@@ -156,13 +160,17 @@ module Killbill::Litle
156
160
  end
157
161
 
158
162
  def report_group_for_account(kb_account_id)
159
- account = @kb_apis.get_account_by_id(kb_account_id)
160
- currency = account.currency
163
+ currency = account_currency(kb_account_id)
161
164
  report_group_for_currency(currency)
162
165
  rescue Killbill::Plugin::JKillbillApi::APINotAvailableError
163
166
  "Default Report Group"
164
167
  end
165
168
 
169
+ def account_currency(kb_account_id)
170
+ account = @kb_apis.get_account_by_id(kb_account_id)
171
+ account.currency
172
+ end
173
+
166
174
  def report_group_for_currency(currency)
167
175
  "Report Group for #{currency.respond_to?(:enum) ? currency.enum : currency.to_s}"
168
176
  end
@@ -45,13 +45,16 @@ end
45
45
  post '/plugins/killbill-litle/checkout' do
46
46
  kb_account_id = request.POST['kb_account_id']
47
47
  response_paypage_registration_id = request.POST['response_paypage_registration_id']
48
+ # Allow currency override if needed
49
+ currency = request.POST['currency'] || plugin.get_currency(kb_account_id)
48
50
 
49
51
  {
50
52
  :kb_account_id => kb_account_id,
53
+ :currency => currency,
51
54
  :response_paypage_registration_id => response_paypage_registration_id
52
55
  }.each { |k, v| required_parameter! k, v }
53
56
 
54
- pm = plugin.register_token! kb_account_id, response_paypage_registration_id
57
+ pm = plugin.register_token! kb_account_id, currency, response_paypage_registration_id
55
58
  redirect "/plugins/killbill-litle/1.0/pms/#{pm.id}"
56
59
  end
57
60
 
@@ -3,7 +3,7 @@ require 'logger'
3
3
  module Killbill::Litle
4
4
  mattr_reader :logger
5
5
  mattr_reader :config
6
- mattr_reader :gateway
6
+ mattr_reader :gateways
7
7
  mattr_reader :kb_apis
8
8
  mattr_reader :initialized
9
9
  mattr_reader :test
@@ -17,8 +17,7 @@ module Killbill::Litle
17
17
  @@config.parse!
18
18
  @@test = @@config[:litle][:test]
19
19
 
20
- @@gateway = Killbill::Litle::Gateway.instance
21
- @@gateway.configure(@@config[:litle])
20
+ @@gateways = Killbill::Litle::Gateway.from_config(@@config[:litle])
22
21
 
23
22
  if defined?(JRUBY_VERSION)
24
23
  # See https://github.com/jruby/activerecord-jdbc-adapter/issues/302
@@ -30,4 +29,11 @@ module Killbill::Litle
30
29
 
31
30
  @@initialized = true
32
31
  end
32
+
33
+ def self.gateway_for_currency(currency)
34
+ currency_sym = currency.respond_to?(:enum) ? currency.enum.upcase.to_sym : currency.to_s.upcase.to_sym
35
+ gateway = @@gateways[currency_sym]
36
+ raise "Gateway for #{currency} not configured!" if gateway.nil?
37
+ gateway
38
+ end
33
39
  end
@@ -1,8 +1,6 @@
1
1
  module Killbill::Litle
2
2
  class Gateway
3
- include Singleton
4
-
5
- def configure(config)
3
+ def self.from_config(config)
6
4
  if config[:test]
7
5
  ActiveMerchant::Billing::Base.mode = :test
8
6
  end
@@ -12,9 +10,18 @@ module Killbill::Litle
12
10
  ActiveMerchant::Billing::LitleGateway.wiredump_device.sync = true
13
11
  end
14
12
 
15
- @gateway = ActiveMerchant::Billing::LitleGateway.new({ :user => config[:username],
16
- :merchant_id => config[:merchant_id],
17
- :password => config[:password]
13
+ gateways = {}
14
+ config[:merchant_id].each do |currency, mid|
15
+ gateways[currency.upcase.to_sym] = Gateway.new(currency, config[:username], config[:password], mid)
16
+ end
17
+ gateways
18
+ end
19
+
20
+ def initialize(currency, user, password, merchant_id)
21
+ @currency = currency
22
+ @gateway = ActiveMerchant::Billing::LitleGateway.new({:user => user,
23
+ :password => password,
24
+ :merchant_id => merchant_id
18
25
  })
19
26
  end
20
27
 
@@ -2,8 +2,8 @@ module Killbill::Litle
2
2
  class PrivatePaymentPlugin
3
3
  include Singleton
4
4
 
5
- def register_token!(kb_account_id, paypage_registration_id, options = {})
6
- litle_response = gateway.store paypage_registration_id, options
5
+ def register_token!(kb_account_id, currency, paypage_registration_id, options = {})
6
+ litle_response = gateway(currency).store paypage_registration_id, options
7
7
  response = save_response litle_response, :register_token
8
8
 
9
9
  if response.success
@@ -33,9 +33,9 @@ module Killbill::Litle
33
33
  response
34
34
  end
35
35
 
36
- def gateway
36
+ def gateway(currency)
37
37
  # The gateway should have been configured when the plugin started
38
- Killbill::Litle::Gateway.instance
38
+ Killbill::Litle.gateway_for_currency(currency)
39
39
  end
40
40
 
41
41
  def logger
data/pom.xml CHANGED
@@ -25,7 +25,7 @@
25
25
  <groupId>com.ning.killbill.ruby</groupId>
26
26
  <artifactId>litle-plugin</artifactId>
27
27
  <packaging>pom</packaging>
28
- <version>1.1.1</version>
28
+ <version>1.2.0</version>
29
29
  <name>litle-plugin</name>
30
30
  <url>http://github.com/killbill/killbill-litle-plugin</url>
31
31
  <description>Plugin for accessing Litle as a payment gateway</description>
@@ -6,7 +6,8 @@ describe Killbill::Litle::PaymentPlugin do
6
6
  file = File.new(File.join(dir, 'litle.yml'), "w+")
7
7
  file.write(<<-eos)
8
8
  :litle:
9
- :merchant_id: 'merchant_id'
9
+ :merchant_id:
10
+ :USD: 'merchant_id'
10
11
  :password: 'password'
11
12
  # As defined by spec_helper.rb
12
13
  :database:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-litle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.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-04 00:00:00.000000000 Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: killbill