rock_rms 4.2.3 → 4.3.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: dfd2e5a738f2c8d538e07197bb5594a0776d5633
4
- data.tar.gz: b79e6f614094b84eec16722719be9db159e16231
3
+ metadata.gz: 0c3c3cbc6390883ed496a1e832688b8536ee19fd
4
+ data.tar.gz: 9164e643821a03ea8fbc00ef48f7e791f930d649
5
5
  SHA512:
6
- metadata.gz: 99237295b01bfc1a1f94f7b1ea86d73fa5384e003585b68b5285f1c3d440e5d1a59c6e9da3aff7377bd700f6f14c2b308167f4eab7015d1b6164af2b3865435d
7
- data.tar.gz: b06b878b04735ae4f73fb55cb610d5aa148263197ff0933f00b903adc055ae781cd566b1f4814e833f64bbae787b90466722f76c8f6eb2b035963c9f710b3b94
6
+ metadata.gz: 68044d1978168c99b2fb9a25595d99be949b250d560b5a0293c7072843be923139bb3bf7af1de166c6f2030d03f119d84552b078ce3e1912cda8465bf1d957a8
7
+ data.tar.gz: e9188f8e41ba589a9e4748a462ef914e0d8196845675ee8be750052f64a908a51d452983c6a952b26a811f5fd2ba8fcfad0f7c0726d52241101049a116914795
@@ -8,13 +8,19 @@ module RockRMS
8
8
  date:,
9
9
  reason_id:,
10
10
  transaction_id:,
11
- transaction_code: nil
11
+ transaction_code: nil,
12
+ amount: nil
12
13
  )
14
+
13
15
  old_transaction = list_transactions(
14
16
  '$expand' => 'TransactionDetails',
15
17
  '$filter' => "Id eq #{transaction_id}"
16
18
  ).first
17
19
 
20
+ transaction_amount = old_transaction[:details].map{|d| d[:amount]}.reduce(0.0){|sum,x| sum + x }
21
+
22
+ refund_amount = amount || transaction_amount
23
+
18
24
  params = {
19
25
  'OriginalTransactionId' => transaction_id,
20
26
  'RefundReasonValueId' => reason_id,
@@ -24,7 +30,7 @@ module RockRMS
24
30
  'FinancialPaymentDetailId' => old_transaction[:payment_detail_id],
25
31
  'TransactionCode' => transaction_code,
26
32
  'TransactionDateTime' => date,
27
- 'TransactionDetails' => translate_negative(old_transaction[:details]),
33
+ 'TransactionDetails' => refunded_details(old_transaction[:details], transaction_amount, refund_amount),
28
34
  'TransactionTypeValueId' => old_transaction[:transaction_type_id]
29
35
  }
30
36
  }
@@ -33,8 +39,8 @@ module RockRMS
33
39
 
34
40
  private
35
41
 
36
- def translate_negative(details)
37
- details.map do |dt|
42
+ def refunded_details(details, transaction_amount, refund_amount)
43
+ apportion_refund_amount_over_accounts(details, transaction_amount, refund_amount).map do |dt|
38
44
  {
39
45
  'Amount' => -dt[:amount],
40
46
  'AccountId' => dt[:fund_id]
@@ -42,6 +48,27 @@ module RockRMS
42
48
  end
43
49
  end
44
50
 
51
+ def apportion_refund_amount_over_accounts(details, transaction_amount, refund_amount)
52
+ if refund_amount >= transaction_amount
53
+ details
54
+ else
55
+ ratio = refund_amount / transaction_amount
56
+ initial_acc = {total_amount: transaction_amount, details: []}
57
+ result = details.reduce(initial_acc) do |acc, detail|
58
+ amount_for_this_detail = (detail[:amount] * ratio).round(2)
59
+ new_total_amount = acc[:total_amount] - amount_for_this_detail
60
+ detail[:amount] = amount_for_this_detail
61
+ new_details = acc[:details] << detail
62
+ {
63
+ total_amount: new_total_amount,
64
+ details: new_details,
65
+ }
66
+ end
67
+
68
+ result[:details]
69
+ end
70
+ end
71
+
45
72
  def refund_path(id = nil)
46
73
  id ? "#{PATH}/#{id}" : PATH
47
74
  end
@@ -1,3 +1,3 @@
1
1
  module RockRMS
2
- VERSION = '4.2.3'.freeze
2
+ VERSION = '4.3.0'.freeze
3
3
  end
@@ -27,42 +27,81 @@ RSpec.describe RockRMS::Client::Refund, type: :model do
27
27
 
28
28
  end
29
29
 
30
- subject(:resource) do
31
- client.create_refund(
32
- transaction_id: 1422,
33
- batch_id: 1,
34
- date: '2018-02-01',
35
- reason_id: 1
36
- )
37
- end
30
+ context "without amount param" do
31
+
32
+ subject(:resource) do
33
+ client.create_refund(
34
+ transaction_id: 3000,
35
+ batch_id: 1,
36
+ date: '2018-02-01',
37
+ reason_id: 1
38
+ )
39
+ end
40
+
41
+ it 'returns integer' do
42
+ expect(resource).to be_a(Integer)
43
+ end
44
+
45
+ it 'passes options' do
46
+ expect(client).to receive(:post)
47
+ .with(
48
+ 'FinancialTransactionRefunds',
49
+ 'OriginalTransactionId' => 3000,
50
+ 'RefundReasonValueId' => 1,
51
+ 'FinancialTransaction' => {
52
+ 'AuthorizedPersonAliasId' => 120,
53
+ 'BatchId' => 1,
54
+ 'FinancialPaymentDetailId' => 156,
55
+ 'TransactionDateTime' => '2018-02-01',
56
+ 'TransactionDetails' => [{"Amount"=>-10.0, "AccountId"=>23}, {"Amount"=>-90.0, "AccountId"=>24}],
57
+ 'TransactionTypeValueId' => 53,
58
+ 'TransactionCode' => nil
59
+ }
60
+ )
61
+ .and_call_original
62
+ resource
63
+ end
38
64
 
39
- it 'returns integer' do
40
- expect(resource).to be_a(Integer)
41
65
  end
42
66
 
43
- it 'passes options' do
44
- expect(client).to receive(:post)
45
- .with(
46
- 'FinancialTransactionRefunds',
47
- 'OriginalTransactionId' => 1422,
48
- 'RefundReasonValueId' => 1,
49
- 'FinancialTransaction' => {
50
- 'AuthorizedPersonAliasId' => 120,
51
- 'BatchId' => 1,
52
- 'FinancialPaymentDetailId' => 156,
53
- 'TransactionDateTime' => '2018-02-01',
54
- 'TransactionDetails' => [
55
- {
56
- 'Amount' => -100.0,
57
- 'AccountId' => 23
58
- }
59
- ],
60
- 'TransactionTypeValueId' => 53,
61
- 'TransactionCode' => nil
62
- }
67
+ context "with amount param" do
68
+
69
+ subject(:resource) do
70
+ client.create_refund(
71
+ transaction_id: 3000,
72
+ batch_id: 1,
73
+ date: '2018-02-01',
74
+ reason_id: 1,
75
+ amount: 75.55,
63
76
  )
64
- .and_call_original
65
- resource
77
+ end
78
+
79
+ it 'returns integer' do
80
+ expect(resource).to be_a(Integer)
81
+ end
82
+
83
+ it 'passes options' do
84
+ expect(client).to receive(:post)
85
+ .with(
86
+ 'FinancialTransactionRefunds',
87
+ 'OriginalTransactionId' => 3000,
88
+ 'RefundReasonValueId' => 1,
89
+ 'FinancialTransaction' => {
90
+ 'AuthorizedPersonAliasId' => 120,
91
+ 'BatchId' => 1,
92
+ 'FinancialPaymentDetailId' => 156,
93
+ 'TransactionDateTime' => '2018-02-01',
94
+ 'TransactionDetails' => [{"Amount"=>-7.56, "AccountId"=>23}, {"Amount"=>-67.99, "AccountId"=>24}],
95
+ 'TransactionTypeValueId' => 53,
96
+ 'TransactionCode' => nil
97
+ }
98
+ )
99
+ .and_call_original
100
+ resource
101
+ end
102
+
66
103
  end
104
+
67
105
  end
106
+
68
107
  end
@@ -13,7 +13,7 @@ RSpec.describe RockRMS::Response::Transaction, type: :model do
13
13
  end
14
14
 
15
15
  it 'translates keys' do
16
- result.zip(parsed) do |r, p|
16
+ result.take(1).zip(parsed) do |r, p|
17
17
  expect(r[:id]).to eq(p['Id'])
18
18
  expect(r[:date]).to eq(p['TransactionDateTime'])
19
19
  expect(r[:batch_id]).to eq(p['BatchId'])
@@ -3,7 +3,7 @@
3
3
  "TransactionId": 1422,
4
4
  "AccountId": 23,
5
5
  "IsNonCash": false,
6
- "Amount": 100.00,
6
+ "Amount": 10.00,
7
7
  "Summary": null,
8
8
  "EntityTypeId": null,
9
9
  "EntityId": null,
@@ -21,5 +21,28 @@
21
21
  "ForeignId": null,
22
22
  "ForeignGuid": null,
23
23
  "ForeignKey": null
24
+ },
25
+ {
26
+ "TransactionId": 1422,
27
+ "AccountId": 24,
28
+ "IsNonCash": false,
29
+ "Amount": 90.00,
30
+ "Summary": null,
31
+ "EntityTypeId": null,
32
+ "EntityId": null,
33
+ "Account": null,
34
+ "EntityType": null,
35
+ "CreatedDateTime": "2018-01-25T02:00:14.973",
36
+ "ModifiedDateTime": "2018-01-25T02:00:14.973",
37
+ "CreatedByPersonAliasId": null,
38
+ "ModifiedByPersonAliasId": null,
39
+ "ModifiedAuditValuesAlreadyUpdated": false,
40
+ "Attributes": null,
41
+ "AttributeValues": null,
42
+ "Id": 346,
43
+ "Guid": "a3bdcc01-5476-4e08-8245-dec2630c9471",
44
+ "ForeignId": null,
45
+ "ForeignGuid": null,
46
+ "ForeignKey": null
24
47
  }
25
48
  ]
@@ -36,7 +36,12 @@
36
36
  "TransactionDetails": [{
37
37
  "Id": 345,
38
38
  "AccountId": 23,
39
- "Amount": 100.00
39
+ "Amount": 10.00
40
+ },
41
+ {
42
+ "Id": 346,
43
+ "AccountId": 24,
44
+ "Amount": 90.00
40
45
  }],
41
46
  "TransactionTypeValueId": 53
42
47
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rock_rms
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.3
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Brooks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-24 00:00:00.000000000 Z
11
+ date: 2018-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday