killbill-litle 1.0.6 → 1.0.8

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.
data/.gitignore CHANGED
@@ -34,3 +34,6 @@ litle.yml
34
34
  test.db
35
35
 
36
36
  target
37
+ pom.xml.asc
38
+
39
+ .idea/
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.6
1
+ 1.0.8
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.rdoc_options << '--exclude' << '.'
24
24
 
25
- s.add_dependency 'killbill', '~> 1.0.16'
25
+ s.add_dependency 'killbill', '~> 1.0.17'
26
26
  s.add_dependency 'activemerchant', '~> 2.0.0'
27
27
  s.add_dependency 'activerecord', '~> 3.2.1'
28
28
  s.add_dependency 'sinatra', '~> 1.3.4'
data/lib/litle/api.rb CHANGED
@@ -14,15 +14,15 @@ module Killbill::Litle
14
14
  ActiveRecord::Base.connection.close
15
15
  end
16
16
 
17
- def process_payment(kb_account_id, kb_payment_id, kb_payment_method_id, amount_in_cents, currency, options = {})
17
+ def process_payment(kb_account_id, kb_payment_id, kb_payment_method_id, amount_in_cents, currency, call_context, options = {})
18
18
  # If the payment was already made, just return the status
19
19
  # TODO Should we set the Litle Id field to check for dups (https://www.litle.com/mc-secure/DupeChecking_V1.2.pdf)?
20
- litle_transaction = LitleTransaction.from_kb_payment_id(kb_payment_id) rescue nil
20
+ litle_transaction = LitleTransaction.from_kb_payment_id(kb_payment_id.to_s) rescue nil
21
21
  return litle_transaction.litle_response.to_payment_response unless litle_transaction.nil?
22
22
 
23
23
  # Required argument
24
24
  # Note! The field is limited to 25 chars, so we convert the UUID (in hex) to base64
25
- options[:order_id] ||= Utils.compact_uuid kb_payment_id
25
+ options[:order_id] ||= Utils.compact_uuid kb_payment_id.to_s
26
26
 
27
27
  # Set a default report group
28
28
  options[:merchant] ||= report_group_for_currency(currency)
@@ -36,8 +36,8 @@ module Killbill::Litle
36
36
  response.to_payment_response
37
37
  end
38
38
 
39
- def process_refund(kb_account_id, kb_payment_id, amount_in_cents, currency, options = {})
40
- litle_transaction = LitleTransaction.find_candidate_transaction_for_refund(kb_payment_id, amount_in_cents)
39
+ def process_refund(kb_account_id, kb_payment_id, amount_in_cents, currency, call_context, options = {})
40
+ litle_transaction = LitleTransaction.find_candidate_transaction_for_refund(kb_payment_id.to_s, amount_in_cents)
41
41
 
42
42
  # Set a default report group
43
43
  options[:merchant] ||= report_group_for_currency(currency)
@@ -49,16 +49,16 @@ module Killbill::Litle
49
49
  response.to_refund_response
50
50
  end
51
51
 
52
- def get_payment_info(kb_account_id, kb_payment_id, options = {})
52
+ def get_payment_info(kb_account_id, kb_payment_id, tenant_context, options = {})
53
53
  # We assume the payment is immutable in Litle and only look at our tables since there
54
54
  # doesn't seem to be a Litle API to fetch details for a given transaction.
55
55
  # TODO How can we support Authorization/Sale Recycling?
56
- litle_transaction = LitleTransaction.from_kb_payment_id(kb_payment_id)
56
+ litle_transaction = LitleTransaction.from_kb_payment_id(kb_payment_id.to_s)
57
57
 
58
58
  litle_transaction.litle_response.to_payment_response
59
59
  end
60
60
 
61
- def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default=true, options = {})
61
+ def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, call_context, options = {})
62
62
  # Set a default report group
63
63
  options[:merchant] ||= report_group_for_account(kb_account_id)
64
64
 
@@ -67,19 +67,23 @@ module Killbill::Litle
67
67
  litle_response = @gateway.store token, options
68
68
  response = save_response_and_transaction litle_response, :add_payment_method
69
69
 
70
- LitlePaymentMethod.create :kb_account_id => kb_account_id, :kb_payment_method_id => kb_payment_method_id, :litle_token => response.litle_token
70
+ if response.success
71
+ LitlePaymentMethod.create :kb_account_id => kb_account_id.to_s, :kb_payment_method_id => kb_payment_method_id.to_s, :litle_token => response.litle_token
72
+ else
73
+ raise response.message
74
+ end
71
75
  end
72
76
 
73
- def delete_payment_method(kb_account_id, kb_payment_method_id, options = {})
74
- LitlePaymentMethod.mark_as_deleted! kb_payment_method_id
77
+ def delete_payment_method(kb_account_id, kb_payment_method_id, call_context, options = {})
78
+ LitlePaymentMethod.mark_as_deleted! kb_payment_method_id.to_s
75
79
  end
76
80
 
77
- def get_payment_method_detail(kb_account_id, kb_payment_method_id, options = {})
78
- LitlePaymentMethod.from_kb_payment_method_id(kb_payment_method_id).to_payment_method_response
81
+ def get_payment_method_detail(kb_account_id, kb_payment_method_id, tenant_context, options = {})
82
+ LitlePaymentMethod.from_kb_payment_method_id(kb_payment_method_id.to_s).to_payment_method_response
79
83
  end
80
84
 
81
- def get_payment_methods(kb_account_id, refresh_from_gateway = false, options = {})
82
- LitlePaymentMethod.from_kb_account_id(kb_account_id).collect { |pm| pm.to_payment_method_response }
85
+ def get_payment_methods(kb_account_id, refresh_from_gateway, call_context, options = {})
86
+ LitlePaymentMethod.from_kb_account_id(kb_account_id.to_s).collect { |pm| pm.to_payment_method_response }
83
87
  end
84
88
 
85
89
  private
@@ -93,24 +97,23 @@ module Killbill::Litle
93
97
  end
94
98
 
95
99
  def report_group_for_currency(currency)
96
- "Report Group for #{currency}"
100
+ "Report Group for #{currency.respond_to?(:enum) ? currency.enum : currency.to_s}"
97
101
  end
98
102
 
99
-
100
103
  def get_token(kb_payment_method_id)
101
- LitlePaymentMethod.from_kb_payment_method_id(kb_payment_method_id).litle_token
104
+ LitlePaymentMethod.from_kb_payment_method_id(kb_payment_method_id.to_s).litle_token
102
105
  end
103
106
 
104
107
  def save_response_and_transaction(litle_response, api_call, kb_payment_id=nil, amount_in_cents=0)
105
108
  @logger.warn "Unsuccessful #{api_call}: #{litle_response.message}" unless litle_response.success?
106
109
 
107
110
  # Save the response to our logs
108
- response = LitleResponse.from_response(api_call, kb_payment_id, litle_response)
111
+ response = LitleResponse.from_response(api_call, kb_payment_id.to_s, litle_response)
109
112
  response.save!
110
113
 
111
114
  if response.success and !kb_payment_id.blank? and !response.litle_txn_id.blank?
112
115
  # Record the transaction
113
- transaction = response.create_litle_transaction!(:amount_in_cents => amount_in_cents, :api_call => api_call, :kb_payment_id => kb_payment_id, :litle_txn_id => response.litle_txn_id)
116
+ transaction = response.create_litle_transaction!(:amount_in_cents => amount_in_cents, :api_call => api_call, :kb_payment_id => kb_payment_id.to_s, :litle_txn_id => response.litle_txn_id)
114
117
  @logger.debug "Recorded transaction: #{transaction.inspect}"
115
118
  end
116
119
  response
@@ -6,8 +6,12 @@ module Killbill::Litle
6
6
  litle_response = gateway.store paypage_registration_id, options
7
7
  response = save_response litle_response, :register_token
8
8
 
9
- # Create the payment method (not associated to a Killbill payment method yet)
10
- LitlePaymentMethod.create! :kb_account_id => kb_account_id, :kb_payment_method_id => nil, :litle_token => response.litle_token
9
+ if response.success
10
+ # Create the payment method (not associated to a Killbill payment method yet)
11
+ LitlePaymentMethod.create! :kb_account_id => kb_account_id, :kb_payment_method_id => nil, :litle_token => response.litle_token
12
+ else
13
+ raise response.message
14
+ end
11
15
  end
12
16
 
13
17
  private
@@ -31,4 +35,4 @@ module Killbill::Litle
31
35
  Killbill::Litle.logger
32
36
  end
33
37
  end
34
- end
38
+ end
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.0.6</version>
28
+ <version>1.0.8</version>
29
29
  <name>litle-plugin</name>
30
30
  <scm>
31
31
  <connection>scm:git:git://github.com/killbill/killbill-litle-plugin.git</connection>
@@ -3,8 +3,6 @@ require 'logger'
3
3
 
4
4
  ActiveMerchant::Billing::Base.mode = :test
5
5
 
6
-
7
-
8
6
  class KillbillApiWithFakeGetAccountById < Killbill::Plugin::KillbillApi
9
7
 
10
8
  def initialize(japi_proxy)
@@ -19,6 +17,16 @@ end
19
17
 
20
18
  describe Killbill::Litle::PaymentPlugin do
21
19
  before(:each) do
20
+ @call_context = Killbill::Plugin::Model::CallContext.new(SecureRandom.uuid,
21
+ 'token',
22
+ 'rspec tester',
23
+ 'TEST',
24
+ 'user',
25
+ 'testing',
26
+ 'this is from a test',
27
+ Time.now,
28
+ Time.now)
29
+
22
30
  @plugin = Killbill::Litle::PaymentPlugin.new
23
31
  kb_apis = KillbillApiWithFakeGetAccountById.new(nil)
24
32
  @plugin.kb_apis = kb_apis
@@ -34,17 +42,17 @@ describe Killbill::Litle::PaymentPlugin do
34
42
  it "should be able to create and retrieve payment methods" do
35
43
  pm = create_payment_method
36
44
 
37
- pms = @plugin.get_payment_methods(pm.kb_account_id)
45
+ pms = @plugin.get_payment_methods(pm.kb_account_id, false, @call_context)
38
46
  pms.size.should == 1
39
47
  pms[0].external_payment_method_id.should == pm.litle_token
40
48
 
41
- pm_details = @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id)
49
+ pm_details = @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id, @call_context)
42
50
  pm_details.external_payment_method_id.should == pm.litle_token
43
51
 
44
- @plugin.delete_payment_method(pm.kb_account_id, pm.kb_payment_method_id)
52
+ @plugin.delete_payment_method(pm.kb_account_id, pm.kb_payment_method_id, @call_context)
45
53
 
46
- @plugin.get_payment_methods(pm.kb_account_id).size.should == 0
47
- lambda { @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id) }.should raise_error RuntimeError
54
+ @plugin.get_payment_methods(pm.kb_account_id, false, @call_context).size.should == 0
55
+ lambda { @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id, @call_context) }.should raise_error RuntimeError
48
56
  end
49
57
 
50
58
  it "should be able to charge and refund" do
@@ -53,7 +61,7 @@ describe Killbill::Litle::PaymentPlugin do
53
61
  currency = 'USD'
54
62
  kb_payment_id = SecureRandom.uuid
55
63
 
56
- payment_response = @plugin.process_payment pm.kb_account_id, kb_payment_id, pm.kb_payment_method_id, amount_in_cents, currency
64
+ payment_response = @plugin.process_payment pm.kb_account_id, kb_payment_id, pm.kb_payment_method_id, amount_in_cents, currency, @call_context
57
65
  payment_response.amount.should == amount_in_cents
58
66
  payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
59
67
 
@@ -64,14 +72,14 @@ describe Killbill::Litle::PaymentPlugin do
64
72
  response.message.should == "Approved"
65
73
  response.params_litleonelineresponse_saleresponse_order_id.should == Killbill::Litle::Utils.compact_uuid(kb_payment_id)
66
74
 
67
- payment_response = @plugin.get_payment_info pm.kb_account_id, kb_payment_id
75
+ payment_response = @plugin.get_payment_info pm.kb_account_id, kb_payment_id, @call_context
68
76
  payment_response.amount.should == amount_in_cents
69
77
  payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
70
78
 
71
79
  # Check we cannot refund an amount greater than the original charge
72
- lambda { @plugin.process_refund pm.kb_account_id, kb_payment_id, amount_in_cents + 1, currency }.should raise_error RuntimeError
80
+ lambda { @plugin.process_refund pm.kb_account_id, kb_payment_id, amount_in_cents + 1, currency, @call_context }.should raise_error RuntimeError
73
81
 
74
- refund_response = @plugin.process_refund pm.kb_account_id, kb_payment_id, amount_in_cents, currency
82
+ refund_response = @plugin.process_refund pm.kb_account_id, kb_payment_id, amount_in_cents, currency, @call_context
75
83
  refund_response.amount.should == amount_in_cents
76
84
  refund_response.status.should == Killbill::Plugin::Model::RefundPluginStatus.new(:PROCESSED)
77
85
 
@@ -84,7 +92,7 @@ describe Killbill::Litle::PaymentPlugin do
84
92
  second_amount_in_cents = 29471
85
93
  second_kb_payment_id = SecureRandom.uuid
86
94
 
87
- payment_response = @plugin.process_payment pm.kb_account_id, second_kb_payment_id, pm.kb_payment_method_id, second_amount_in_cents, currency
95
+ payment_response = @plugin.process_payment pm.kb_account_id, second_kb_payment_id, pm.kb_payment_method_id, second_amount_in_cents, currency, @call_context
88
96
  payment_response.amount.should == second_amount_in_cents
89
97
  payment_response.status.should == Killbill::Plugin::Model::PaymentPluginStatus.new(:PROCESSED)
90
98
  end
@@ -98,7 +106,7 @@ describe Killbill::Litle::PaymentPlugin do
98
106
  # Generate a token in Litle
99
107
  paypage_registration_id = '123456789012345678901324567890abcdefghi'
100
108
  info = Killbill::Plugin::Model::PaymentMethodPlugin.new nil, nil, [Killbill::Plugin::Model::PaymentMethodKVInfo.new(false, "paypageRegistrationId", paypage_registration_id)], nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
101
- payment_method = @plugin.add_payment_method(kb_account_id, kb_payment_method_id, info)
109
+ payment_method = @plugin.add_payment_method(kb_account_id, kb_payment_method_id, info, true, @call_context)
102
110
 
103
111
  pm = Killbill::Litle::LitlePaymentMethod.from_kb_payment_method_id kb_payment_method_id
104
112
  pm.kb_account_id.should == kb_account_id
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-litle
3
3
  version: !ruby/object:Gem::Version
4
+ version: 1.0.8
4
5
  prerelease:
5
- version: 1.0.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Killbill core team
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-22 00:00:00.000000000 Z
12
+ date: 2013-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: killbill
@@ -17,13 +17,13 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 1.0.16
20
+ version: 1.0.17
21
21
  none: false
22
22
  requirement: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.16
26
+ version: 1.0.17
27
27
  none: false
28
28
  prerelease: false
29
29
  type: :runtime
@@ -260,9 +260,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
260
  - !ruby/object:Gem::Version
261
261
  segments:
262
262
  - 0
263
- hash: 2
264
263
  version: !binary |-
265
264
  MA==
265
+ hash: 2
266
266
  none: false
267
267
  requirements: []
268
268
  rubyforge_project: