rock_rms 3.0.2 → 3.1.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: 8cbd1e3135b8af5ee807b31db1540e14d922a24e
4
- data.tar.gz: c39a14cdfb5d434b9ee74ae95a462d82555c4aad
3
+ metadata.gz: 0ce2e3c0428ddbc12f3f61174a80bfe26a118396
4
+ data.tar.gz: 486cfc3c44790ec1e12641653189edef93919e6f
5
5
  SHA512:
6
- metadata.gz: d2793c043b4a20524975f842667453774a943bae5a891ee762857b56077ddd318a4ee21a0738f1d67ce4709770e610ed783233a5d85ef26c704d2c2fa624f3d1
7
- data.tar.gz: fb61bec8b329ef95b6166e6dc162c01ed830b43f37b67465b832673537bc32f779742e3e5c94262a2845a913f143691d5b638544112afb4c872eaab2ce360fed
6
+ metadata.gz: 545647157dcd6a2ac1e0092adbd0b232ed48be5db15b5634a89af339ebbc988db094757cfb46dcf91d1fcb7ce688da76b6533e107c89af81949092dd8d176d24
7
+ data.tar.gz: 734b379adb815d742ed2373497752ff454c961d9a8223d6e90b2a5db28a038f2a3ccb1aabb79f2db0c10ff687c73e9324add58a9f975674203f8389d12e4d7e6
@@ -16,6 +16,7 @@ module RockRMS
16
16
  include RockRMS::Client::Person
17
17
  include RockRMS::Client::PhoneNumber
18
18
  include RockRMS::Client::RecurringDonation
19
+ include RockRMS::Client::Refund
19
20
  include RockRMS::Client::Transaction
20
21
  include RockRMS::Client::TransactionDetail
21
22
 
@@ -0,0 +1,48 @@
1
+ module RockRMS
2
+ class Client
3
+ module Refund
4
+ PATH = 'FinancialTransactionRefunds'.freeze
5
+
6
+ def create_refund(
7
+ batch_id:,
8
+ date:,
9
+ reason_id:,
10
+ transaction_id:
11
+ )
12
+ old_transaction = list_transactions(
13
+ '$expand' => 'TransactionDetails',
14
+ '$filter' => "Id eq #{transaction_id}"
15
+ ).first
16
+
17
+ params = {
18
+ 'OriginalTransactionId' => transaction_id,
19
+ 'RefundReasonValueId' => reason_id,
20
+ 'FinancialTransaction' => {
21
+ 'AuthorizedPersonAliasId' => old_transaction[:person_id],
22
+ 'BatchId' => batch_id,
23
+ 'FinancialPaymentDetailId' => old_transaction[:payment_detail_id],
24
+ 'TransactionDateTime' => date,
25
+ 'TransactionDetails' => translate_negative(old_transaction[:details]),
26
+ 'TransactionTypeValueId' => old_transaction[:transaction_type_id]
27
+ }
28
+ }
29
+ post(refund_path, params)
30
+ end
31
+
32
+ private
33
+
34
+ def translate_negative(details)
35
+ details.map do |dt|
36
+ {
37
+ 'Amount' => -dt[:amount],
38
+ 'AccountId' => dt[:fund_id]
39
+ }
40
+ end
41
+ end
42
+
43
+ def refund_path(id = nil)
44
+ id ? "#{PATH}/#{id}" : PATH
45
+ end
46
+ end
47
+ end
48
+ end
@@ -9,7 +9,9 @@ module RockRMS
9
9
  recurring_donation_id: 'ScheduledTransactionId',
10
10
  summary: 'Summary',
11
11
  transaction_code: 'TransactionCode',
12
- details: 'TransactionDetails'
12
+ details: 'TransactionDetails',
13
+ payment_detail_id: 'FinancialPaymentDetailId',
14
+ transaction_type_id: 'TransactionTypeValueId'
13
15
  }.freeze
14
16
 
15
17
 
@@ -1,3 +1,3 @@
1
1
  module RockRMS
2
- VERSION = '3.0.2'.freeze
2
+ VERSION = '3.1.0'.freeze
3
3
  end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RockRMS::Client::Refund, type: :model do
4
+ include_context 'resource specs'
5
+
6
+ describe '#create_refund' do
7
+ context 'arguments' do
8
+ it 'require `authorized_person_id`' do
9
+ expect { client.create_refund }
10
+ .to raise_error(ArgumentError, /transaction_id/)
11
+ end
12
+
13
+ it 'require `batch_id`' do
14
+ expect { client.create_refund }
15
+ .to raise_error(ArgumentError, /batch_id/)
16
+ end
17
+
18
+ it 'require `date`' do
19
+ expect { client.create_refund }
20
+ .to raise_error(ArgumentError, /date/)
21
+ end
22
+
23
+ it 'require `funds`' do
24
+ expect { client.create_refund }
25
+ .to raise_error(ArgumentError, /reason_id/)
26
+ end
27
+
28
+ end
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
38
+
39
+ it 'returns integer' do
40
+ expect(resource).to be_a(Integer)
41
+ end
42
+
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
+ }
62
+ )
63
+ .and_call_original
64
+ resource
65
+ end
66
+ end
67
+ end
@@ -20,6 +20,8 @@ RSpec.describe RockRMS::Response::Transaction, type: :model do
20
20
  expect(r[:recurring_donation_id]).to eq(p['ScheduledTransactionId'])
21
21
  expect(r[:summary]).to eq(p['Summary'])
22
22
  expect(r[:transaction_code]).to eq(p['TransactionCode'])
23
+ expect(r[:payment_detail_id]).to eq(p['FinancialPaymentDetailId'])
24
+ expect(r[:transaction_type_id]).to eq(p['TransactionTypeValueId'])
23
25
  expect(r[:details]).to eq(
24
26
  RockRMS::Response::TransactionDetail.format(p['TransactionDetails'])
25
27
  )
@@ -0,0 +1 @@
1
+ 12345
@@ -40,7 +40,8 @@ class RockMock < Sinatra::Base
40
40
  {
41
41
  create_group_member: 'GroupMembers',
42
42
  create_transaction: 'FinancialTransactions',
43
- create_batch: 'FinancialBatches'
43
+ create_batch: 'FinancialBatches',
44
+ create_refund: 'FinancialTransactionRefunds'
44
45
  }.each do |json, end_point|
45
46
  post "/api/#{end_point}" do
46
47
  json_response 201, "#{json}.json"
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: 3.0.2
4
+ version: 3.1.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-02-02 00:00:00.000000000 Z
11
+ date: 2018-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -192,6 +192,7 @@ files:
192
192
  - lib/rock_rms/resources/person.rb
193
193
  - lib/rock_rms/resources/phone_number.rb
194
194
  - lib/rock_rms/resources/recurring_donation.rb
195
+ - lib/rock_rms/resources/refund.rb
195
196
  - lib/rock_rms/resources/transaction.rb
196
197
  - lib/rock_rms/resources/transaction_detail.rb
197
198
  - lib/rock_rms/response/base.rb
@@ -218,6 +219,7 @@ files:
218
219
  - spec/rock_rms/resources/person_spec.rb
219
220
  - spec/rock_rms/resources/phone_number_spec.rb
220
221
  - spec/rock_rms/resources/recurring_donation_spec.rb
222
+ - spec/rock_rms/resources/refund_spec.rb
221
223
  - spec/rock_rms/resources/transaction_detail_spec.rb
222
224
  - spec/rock_rms/resources/transaction_spec.rb
223
225
  - spec/rock_rms/response/batch_spec.rb
@@ -238,6 +240,7 @@ files:
238
240
  - spec/support/fixtures/campuses.json
239
241
  - spec/support/fixtures/create_batch.json
240
242
  - spec/support/fixtures/create_group_member.json
243
+ - spec/support/fixtures/create_refund.json
241
244
  - spec/support/fixtures/create_transaction.json
242
245
  - spec/support/fixtures/families.json
243
246
  - spec/support/fixtures/group.json