killbill-client 1.4.0 → 1.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2ef126812dd995a0279bb40b3e5ebcbd8f6e846
4
- data.tar.gz: 86db64653e7e29ae21541b4241dfcf01ee5de169
3
+ metadata.gz: af588a74667e14903ee145dfd23cd3ea1e39455e
4
+ data.tar.gz: ccd3d09f2fc6904e2ab688fbbbf63b924610acbb
5
5
  SHA512:
6
- metadata.gz: 9b738f3f54f9d508126f79c0da7b962c87b2034524d38597dd9c68100b54b870dae165ca3a1584feb6e6dfd143bbb807b8a8e025a6df540b9dca53a55097f48e
7
- data.tar.gz: 22dc8d5c9d4bd13fff971e20913be2e3a5a67fe150623c3cdeb6f44ff3aa8c9b10a870a0ba990c3ed87ae05eddd31e93189f00315e106ec3f352758a8f2a8684
6
+ metadata.gz: c29ea6b799ba99d3a40b31b43efb2b6c6ff1aafe2c64ddb868f10096b90f2113d64bfd5fd3e0441eb7b0e7b5df66eecc2b40aff62320d396ffed45996edab236
7
+ data.tar.gz: 5ef30ac236df22c9f86db03c2000182ced72ff3d3ecd28bb16923b654bfcd39490c88153aad5ef4f7dfb14febfe69bf84f658fe7d901f1bbc1c6fc66f7cdb5c2
@@ -23,6 +23,8 @@ module KillBillClient
23
23
  private
24
24
 
25
25
  def combo_payment(user, reason, comment, options, refresh_options = nil)
26
+ follow_location = true
27
+ follow_location = options.delete(:follow_location) if options.has_key?(:follow_location)
26
28
  begin
27
29
  created_transaction = self.class.post "#{Payment::KILLBILL_API_PAYMENTS_PREFIX}/combo",
28
30
  to_json,
@@ -34,14 +36,21 @@ module KillBillClient
34
36
  }.merge(options)
35
37
  rescue KillBillClient::API::ResponseError => error
36
38
  response = error.response
37
- if response.header['location']
39
+ if follow_location && response.header['location']
38
40
  created_transaction = ComboTransaction.new
39
41
  created_transaction.uri = response.header['location']
40
42
  else
41
43
  raise error
42
44
  end
43
45
  end
44
- created_transaction.refresh(refresh_options || options, Payment)
46
+
47
+ if follow_location
48
+ return created_transaction.refresh(refresh_options || options, Payment)
49
+ end
50
+
51
+ created_payment = Payment.new
52
+ created_payment.uri = created_transaction.uri
53
+ created_payment
45
54
  end
46
55
  end
47
56
  end
@@ -2,12 +2,14 @@ module KillBillClient
2
2
  module Model
3
3
  class Credit < CreditAttributes
4
4
  KILLBILL_API_CREDITS_PREFIX = "#{KILLBILL_API_PREFIX}/credits"
5
- has_many :audit_logs, KillBillClient::Model::AuditLog
5
+ has_many :audit_logs, KillBillClient::Model::AuditLog
6
6
 
7
- def create(user = nil, reason = nil, comment = nil, options = {})
7
+ def create(auto_commit = false, user = nil, reason = nil, comment = nil, options = {})
8
8
  created_credit = self.class.post KILLBILL_API_CREDITS_PREFIX,
9
9
  to_json,
10
- {},
10
+ {
11
+ :autoCommit => auto_commit
12
+ },
11
13
  {
12
14
  :user => user,
13
15
  :reason => reason,
@@ -9,63 +9,64 @@ module KillBillClient
9
9
  has_many :properties, KillBillClient::Model::PluginPropertyAttributes
10
10
  has_many :audit_logs, KillBillClient::Model::AuditLog
11
11
 
12
- def auth(account_id, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {})
12
+ def auth(account_id, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
13
13
  @transaction_type = 'AUTHORIZE'
14
14
  query_map = {}
15
- create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments", query_map, payment_method_id, user, reason, comment, options)
15
+ create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments", query_map, payment_method_id, user, reason, comment, options, refresh_options)
16
16
  end
17
17
 
18
- def purchase(account_id, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {})
18
+ def purchase(account_id, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
19
19
  @transaction_type = 'PURCHASE'
20
20
  query_map = {}
21
- create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments", query_map, payment_method_id, user, reason, comment, options)
21
+ create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments", query_map, payment_method_id, user, reason, comment, options, refresh_options)
22
22
  end
23
23
 
24
- def credit(account_id, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {})
24
+ def credit(account_id, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
25
25
  @transaction_type = 'CREDIT'
26
26
  query_map = {}
27
- create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments", query_map, payment_method_id, user, reason, comment, options)
27
+ create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments", query_map, payment_method_id, user, reason, comment, options, refresh_options)
28
28
  end
29
29
 
30
- def auth_by_external_key(account_external_key, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {})
30
+ def auth_by_external_key(account_external_key, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
31
31
  @transaction_type = 'AUTHORIZE'
32
32
  query_map = {:externalKey => account_external_key}
33
- create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/payments", query_map, payment_method_id, user, reason, comment, options)
33
+ create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/payments", query_map, payment_method_id, user, reason, comment, options, refresh_options)
34
34
  end
35
35
 
36
- def purchase_by_external_key(account_external_key, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {})
36
+ def purchase_by_external_key(account_external_key, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
37
37
  @transaction_type = 'PURCHASE'
38
38
  query_map = {:externalKey => account_external_key}
39
- create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/payments", query_map, payment_method_id, user, reason, comment, options)
39
+ create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/payments", query_map, payment_method_id, user, reason, comment, options, refresh_options)
40
40
  end
41
41
 
42
- def credit_by_external_key(account_external_key, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {})
42
+ def credit_by_external_key(account_external_key, payment_method_id = nil, user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
43
43
  @transaction_type = 'CREDIT'
44
44
  query_map = {:externalKey => account_external_key}
45
- create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/payments", query_map, payment_method_id, user, reason, comment, options)
45
+ create_initial_transaction("#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/payments", query_map, payment_method_id, user, reason, comment, options, refresh_options)
46
46
  end
47
47
 
48
- def complete(user = nil, reason = nil, comment = nil, options = {})
49
- complete_initial_transaction(user, reason, comment, options)
48
+ def complete(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
49
+ complete_initial_transaction(user, reason, comment, options, refresh_options)
50
50
  end
51
51
 
52
- def complete_auth(user = nil, reason = nil, comment = nil, options = {})
52
+ def complete_auth(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
53
53
  @transaction_type = 'AUTHORIZE'
54
- complete_initial_transaction(user, reason, comment, options)
54
+ complete_initial_transaction(user, reason, comment, options, refresh_options)
55
55
  end
56
56
 
57
- def complete_purchase(user = nil, reason = nil, comment = nil, options = {})
57
+ def complete_purchase(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
58
58
  @transaction_type = 'PURCHASE'
59
- complete_initial_transaction(user, reason, comment, options)
59
+ complete_initial_transaction(user, reason, comment, options, refresh_options)
60
60
  end
61
61
 
62
- def complete_credit(user = nil, reason = nil, comment = nil, options = {})
62
+ def complete_credit(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
63
63
  @transaction_type = 'CREDIT'
64
- complete_initial_transaction(user, reason, comment, options)
64
+ complete_initial_transaction(user, reason, comment, options, refresh_options)
65
65
  end
66
66
 
67
- def capture(user = nil, reason = nil, comment = nil, options = {})
68
- created_transaction = with_payment_failure_handling do
67
+ def capture(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
68
+ follow_location = delete_follow_location(options)
69
+ refresh_payment_with_failure_handling(follow_location, refresh_options || options) do
69
70
  self.class.post "#{follow_up_path(payment_id)}",
70
71
  to_json,
71
72
  {},
@@ -75,11 +76,11 @@ module KillBillClient
75
76
  :comment => comment,
76
77
  }.merge(options)
77
78
  end
78
- created_transaction.refresh(options, Payment)
79
79
  end
80
80
 
81
- def refund(user = nil, reason = nil, comment = nil, options = {})
82
- created_transaction = with_payment_failure_handling do
81
+ def refund(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
82
+ follow_location = delete_follow_location(options)
83
+ refresh_payment_with_failure_handling(follow_location, refresh_options || options) do
83
84
  self.class.post "#{follow_up_path(payment_id)}/refunds",
84
85
  to_json,
85
86
  {},
@@ -89,11 +90,11 @@ module KillBillClient
89
90
  :comment => comment,
90
91
  }.merge(options)
91
92
  end
92
- created_transaction.refresh(options, Payment)
93
93
  end
94
94
 
95
- def void(user = nil, reason = nil, comment = nil, options = {})
96
- created_transaction = with_payment_failure_handling do
95
+ def void(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
96
+ follow_location = delete_follow_location(options)
97
+ refresh_payment_with_failure_handling(follow_location, refresh_options || options) do
97
98
  self.class.delete "#{follow_up_path(payment_id)}",
98
99
  to_json,
99
100
  {},
@@ -103,11 +104,11 @@ module KillBillClient
103
104
  :comment => comment,
104
105
  }.merge(options)
105
106
  end
106
- created_transaction.refresh(options, Payment)
107
107
  end
108
108
 
109
- def chargeback(user = nil, reason = nil, comment = nil, options = {})
110
- created_transaction = with_payment_failure_handling do
109
+ def chargeback(user = nil, reason = nil, comment = nil, options = {}, refresh_options = nil)
110
+ follow_location = delete_follow_location(options)
111
+ refresh_payment_with_failure_handling(follow_location, refresh_options || options) do
111
112
  self.class.post "#{follow_up_path(payment_id)}/chargebacks",
112
113
  to_json,
113
114
  {},
@@ -117,7 +118,6 @@ module KillBillClient
117
118
  :comment => comment,
118
119
  }.merge(options)
119
120
  end
120
- created_transaction.refresh(options, Payment)
121
121
  end
122
122
 
123
123
 
@@ -147,10 +147,11 @@ module KillBillClient
147
147
  path
148
148
  end
149
149
 
150
- def create_initial_transaction(path, query_map, payment_method_id, user, reason, comment, options)
150
+ def create_initial_transaction(path, query_map, payment_method_id, user, reason, comment, options, refresh_options)
151
151
  query_map[:paymentMethodId] = payment_method_id unless payment_method_id.nil?
152
152
 
153
- created_transaction = with_payment_failure_handling do
153
+ follow_location = delete_follow_location(options)
154
+ refresh_payment_with_failure_handling(follow_location, refresh_options || options) do
154
155
  self.class.post path,
155
156
  to_json,
156
157
  query_map,
@@ -160,11 +161,11 @@ module KillBillClient
160
161
  :comment => comment
161
162
  }.merge(options)
162
163
  end
163
- created_transaction.refresh(options, Payment)
164
164
  end
165
165
 
166
- def complete_initial_transaction(user, reason, comment, options)
167
- created_transaction = with_payment_failure_handling do
166
+ def complete_initial_transaction(user, reason, comment, options, refresh_options)
167
+ follow_location = delete_follow_location(options)
168
+ refresh_payment_with_failure_handling(follow_location, refresh_options || options) do
168
169
  self.class.put follow_up_path(payment_id),
169
170
  to_json,
170
171
  {},
@@ -174,17 +175,22 @@ module KillBillClient
174
175
  :comment => comment
175
176
  }.merge(options)
176
177
  end
177
- created_transaction.refresh(options, Payment)
178
178
  end
179
179
 
180
- private
180
+ def delete_follow_location(options, key = :follow_location, default_value = true)
181
+ if options.has_key?(key)
182
+ return options.delete(key)
183
+ end
184
+
185
+ default_value
186
+ end
181
187
 
182
- def with_payment_failure_handling
188
+ def refresh_payment_with_failure_handling(follow_location, refresh_options)
183
189
  begin
184
190
  created_transaction = yield
185
191
  rescue KillBillClient::API::ResponseError => error
186
192
  response = error.response
187
- if response['location']
193
+ if follow_location && response['location']
188
194
  created_transaction = Transaction.new
189
195
  created_transaction.uri = response['location']
190
196
  else
@@ -192,7 +198,13 @@ module KillBillClient
192
198
  end
193
199
  end
194
200
 
195
- created_transaction
201
+ if follow_location
202
+ return created_transaction.refresh(refresh_options, Payment)
203
+ end
204
+
205
+ created_payment = Payment.new
206
+ created_payment.uri = created_transaction.uri
207
+ created_payment
196
208
  end
197
209
  end
198
210
  end
@@ -1,7 +1,7 @@
1
1
  module KillBillClient
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 4
4
+ MINOR = 5
5
5
  PATCH = 0
6
6
  PRE = nil
7
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Killbill core team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement