basecomm_sdk 0.0.1
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 +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.rubocop.yml +94 -0
- data/CHANGELOG +3 -0
- data/Gemfile +4 -0
- data/Guardfile +26 -0
- data/LICENSE.txt +22 -0
- data/README.md +102 -0
- data/Rakefile +14 -0
- data/basecomm_sdk.gemspec +40 -0
- data/lib/basecomm_sdk/address.rb +25 -0
- data/lib/basecomm_sdk/bank_account.rb +29 -0
- data/lib/basecomm_sdk/bank_account_transaction.rb +48 -0
- data/lib/basecomm_sdk/bank_card.rb +26 -0
- data/lib/basecomm_sdk/bank_card_transaction.rb +52 -0
- data/lib/basecomm_sdk/base.rb +91 -0
- data/lib/basecomm_sdk/client.rb +151 -0
- data/lib/basecomm_sdk/push_notification.rb +22 -0
- data/lib/basecomm_sdk/settlement_batch.rb +18 -0
- data/lib/basecomm_sdk/triple_des_service.rb +36 -0
- data/lib/basecomm_sdk/version.rb +3 -0
- data/lib/basecomm_sdk.rb +31 -0
- data/spec/cassettes/BasecommSdk_Client/_add_bank_account/fails_when_passing_an_invalid_bank_account.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_add_bank_account/returns_the_new_bank_account_instance.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_add_bank_card/fails_when_passing_an_invalid_bank_card.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_add_bank_card/returns_a_valid_new_bank_card_instance.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_get_bank_account_transaction/fails_when_passing_invalid_bat_transaction.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_get_bank_account_transaction/fails_when_passing_invalid_transaction.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_get_bank_account_transaction/returns_the_specified_bank_account_transaction.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_get_bank_card_transaction/collects_proper_responses_for_missing_transactions.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_get_bank_card_transaction/returns_the_specified_bank_card_transaction.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_process_bank_account_transaction/fails_when_passing_invalid_transaction.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_process_bank_account_transaction/populates_messages_with_failure_reasons.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_process_bank_account_transaction/returns_the_processed_bank_account_transaction.yml +34 -0
- data/spec/cassettes/BasecommSdk_Client/_process_bank_card_transaction/returns_the_processed_bank_account_transaction_for_auth.yml +34 -0
- data/spec/factories.rb +95 -0
- data/spec/lib/basecomm_sdk/address_spec.rb +53 -0
- data/spec/lib/basecomm_sdk/bank_account_spec.rb +53 -0
- data/spec/lib/basecomm_sdk/bank_account_transaction_spec.rb +60 -0
- data/spec/lib/basecomm_sdk/bank_card_spec.rb +55 -0
- data/spec/lib/basecomm_sdk/bank_card_transaction_spec.rb +55 -0
- data/spec/lib/basecomm_sdk/base_spec.rb +7 -0
- data/spec/lib/basecomm_sdk/client_spec.rb +204 -0
- data/spec/lib/basecomm_sdk/push_notification_spec.rb +14 -0
- data/spec/lib/basecomm_sdk/settlement_batch_spec.rb +14 -0
- data/spec/lib/basecomm_sdk/triple_des_service_spec.rb +39 -0
- data/spec/lib/basecomm_sdk_spec.rb +17 -0
- data/spec/spec_helper.rb +56 -0
- data/spec/support/shared_class_with_messages.rb +7 -0
- metadata +374 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 57612b710ed2938369cf6b2def054be9b99bbf6b
|
4
|
+
data.tar.gz: 4b2662337f31a3d61f5d705ef8539c2fc6d206b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7acdd36efda79ca4cacf833efce4c508efd4e5026e7c67bccf5db556fcebe2bd402ebe5e7e0e6814bd19d795baba37b02b2c114545235334b77e1f4452a166f2
|
7
|
+
data.tar.gz: a2152e94cbaa08a116d714dd099b31f7e0172a053e3e3b0d64501519258d0cf9593f550f528c2e33a85c00278a66401d1dcf26b26158dd87b6301a3af34dbeab
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
Style/Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/AlignParameters:
|
5
|
+
EnforcedStyle: with_fixed_indentation
|
6
|
+
|
7
|
+
Metrics/MethodLength:
|
8
|
+
CountComments: false # count full line comments?
|
9
|
+
Max: 16
|
10
|
+
|
11
|
+
Style/RegexpLiteral:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Encoding:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
# MethodLength:
|
18
|
+
# CountComments: false
|
19
|
+
# Max: 30
|
20
|
+
|
21
|
+
#AlignHash:
|
22
|
+
# EnforcedColonStyle: table
|
23
|
+
# EnforcedHashRocketStyle: table
|
24
|
+
|
25
|
+
HashSyntax:
|
26
|
+
Enabled: true
|
27
|
+
|
28
|
+
Lambda:
|
29
|
+
Description: 'Use the new lambda literal syntax for single-line blocks.'
|
30
|
+
Enabled: true
|
31
|
+
|
32
|
+
LambdaCall:
|
33
|
+
Description: 'Use lambda.call(...) instead of lambda.(...).'
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
LineLength:
|
37
|
+
Max: 90
|
38
|
+
|
39
|
+
AlignParameters:
|
40
|
+
Description: >
|
41
|
+
Align the parameters of a method call if they span more
|
42
|
+
than one line.
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
# Checks formatting of special comments
|
46
|
+
CommentAnnotation:
|
47
|
+
Keywords:
|
48
|
+
- TODO
|
49
|
+
- FIXME
|
50
|
+
- OPTIMIZE
|
51
|
+
- HACK
|
52
|
+
- REVIEW
|
53
|
+
|
54
|
+
AllCops:
|
55
|
+
# Include gemspec and Rakefile
|
56
|
+
Include:
|
57
|
+
- '**/*.gemspec'
|
58
|
+
- '**/*.podspec'
|
59
|
+
- '**/*.jbuilder'
|
60
|
+
- '**/*.rake'
|
61
|
+
- '**/Gemfile'
|
62
|
+
- '**/Rakefile'
|
63
|
+
- '**/Capfile'
|
64
|
+
- '**/Guardfile'
|
65
|
+
- '**/Podfile'
|
66
|
+
- '**/Thorfile'
|
67
|
+
- '**/Vagrantfile'
|
68
|
+
Exclude:
|
69
|
+
- 'vendor/**/*'
|
70
|
+
- 'stubs/**/*'
|
71
|
+
|
72
|
+
Lint/Eval:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
Metrics/LineLength:
|
76
|
+
Max: 110
|
77
|
+
|
78
|
+
Metrics/MethodLength:
|
79
|
+
Max: 20
|
80
|
+
|
81
|
+
Metrics/ClassLength:
|
82
|
+
Max: 120
|
83
|
+
|
84
|
+
Style/RaiseArgs:
|
85
|
+
Enabled: false
|
86
|
+
|
87
|
+
Style/PredicateName:
|
88
|
+
Enabled: false
|
89
|
+
|
90
|
+
Style/TrivialAccessors:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
Style/EachWithObject:
|
94
|
+
Enabled: false
|
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
guard :bundler do
|
2
|
+
watch('Gemfile')
|
3
|
+
watch(/^.+\.gemspec/)
|
4
|
+
end
|
5
|
+
|
6
|
+
CLI = 'bundle exec rspec --format doc --color'
|
7
|
+
|
8
|
+
def rspec_watchers
|
9
|
+
watch(%r{^spec/.+_spec\.rb$})
|
10
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^lib/.+/base\.rb$}) { 'spec' }
|
12
|
+
watch(%r{^providers/(.+)\.rb$}) { |m| "spec/providers/#{m[1]}_spec.rb" }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
|
14
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
15
|
+
end
|
16
|
+
|
17
|
+
group :default do
|
18
|
+
# guard :rubocop, cli: ['-D'] do
|
19
|
+
# watch(%r{.+\.rb$})
|
20
|
+
# watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
21
|
+
# end
|
22
|
+
|
23
|
+
guard :rspec, cmd: CLI do
|
24
|
+
rspec_watchers
|
25
|
+
end
|
26
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Chris Blackburn
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Base Commerce SDK
|
2
|
+
|
3
|
+
**Version: 0.0.1**
|
4
|
+
|
5
|
+
A gem for interfacing with the [Base Commerce](http://www.basecommerce.com/) API. This gem was developed with their help and serves to provide a Gem wrapper around their own Ruby SDK. Please contact them for more information about the Ruby SDK.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'basecomm_sdk'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install basecomm_sdk
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
First, you will need to setup an account with [Base Commerce](http://www.basecommerce.com/). Use their sandbox for testing, and please read their documentation before you begin.
|
26
|
+
|
27
|
+
Read the RSpec examples in the './spec' directory for detailed usage of this gem.
|
28
|
+
|
29
|
+
### Basics
|
30
|
+
|
31
|
+
Include the module.
|
32
|
+
|
33
|
+
require 'basecomm_sdk'
|
34
|
+
|
35
|
+
### Insantiate the Client
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
# Get your sandbox credentials from Base Commerce
|
39
|
+
config = {
|
40
|
+
gateway_username: ENV['BASECOMM_UID'],
|
41
|
+
gateway_password: ENV['BASECOMM_PWD'],
|
42
|
+
key: ENV['BASECOMM_KEY'],
|
43
|
+
sandbox: true # For production set this to false or not at all
|
44
|
+
}
|
45
|
+
client = Client.new(config)
|
46
|
+
```
|
47
|
+
|
48
|
+
### Add Bank Account
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
bank_account = BankAccount.new(...)
|
52
|
+
returned_bank_account = client.add_bank_account(bank_account)
|
53
|
+
```
|
54
|
+
|
55
|
+
### Add Bank Card
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
bank_card = BankCard.new(...)
|
59
|
+
returned_bank_card = client.add_bank_card(bank_card)
|
60
|
+
```
|
61
|
+
|
62
|
+
### Get Bank Account Transaction
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
bat = client.get_bank_account_transaction(id) # id of the transaction you want
|
66
|
+
```
|
67
|
+
|
68
|
+
### Get Bank Card Transaction
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
bct = client.get_bank_card_transaction(id)
|
72
|
+
```
|
73
|
+
|
74
|
+
### Process Bank Account Transaction (ACH)
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
bat = BankAccountTransaction.new(...)
|
78
|
+
returned_bat = client.process_bank_account_transaction(bat)
|
79
|
+
```
|
80
|
+
|
81
|
+
### Process Bank Card Transaction
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
bct = BankCardTransaction.new(...)
|
85
|
+
returned_bct = client.process_bank_card_transaction(bct)
|
86
|
+
```
|
87
|
+
|
88
|
+
## Errata
|
89
|
+
|
90
|
+
* We have not used or tested Push Notifications or Settlement Batch APIs.
|
91
|
+
|
92
|
+
## Updates
|
93
|
+
|
94
|
+
We plan to keep this code updated and in sync with any changes in the Base Commerce API. However, for the latest code see the Base Commerce Ruby SDK.
|
95
|
+
|
96
|
+
## Contributing
|
97
|
+
|
98
|
+
1. Fork it ( https://github.com/[my-github-username]/basecomm_sdk/fork )
|
99
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
100
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
101
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
102
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'midwire_common/rake_tasks'
|
5
|
+
rescue StandardError => e
|
6
|
+
puts ">>> Could not load 'midwire_common/rake_tasks': #{e}"
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rspec/core/rake_task'
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new(:spec)
|
13
|
+
|
14
|
+
task default: :spec
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'basecomm_sdk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'basecomm_sdk'
|
8
|
+
spec.version = BasecommSdk::VERSION
|
9
|
+
spec.authors = ['Chris Blackburn', 'Jason Cartwright']
|
10
|
+
spec.email = ['chris@gosimplefin.com', 'jasonc@gosimplefin.com']
|
11
|
+
spec.summary = 'Ruby client gem for Base Commerce ACH provider'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'dotenv', '~> 1.0'
|
22
|
+
spec.add_runtime_dependency 'json', '~> 1.8'
|
23
|
+
spec.add_runtime_dependency 'faraday', '~> 0.9'
|
24
|
+
spec.add_runtime_dependency 'excon', '~> 0.42'
|
25
|
+
spec.add_runtime_dependency 'midwire_common', '>= 0.1.12'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
30
|
+
spec.add_development_dependency 'factory_girl', '~> 4.5'
|
31
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
32
|
+
spec.add_development_dependency 'vcr'
|
33
|
+
spec.add_development_dependency 'webmock'
|
34
|
+
spec.add_development_dependency 'pry'
|
35
|
+
spec.add_development_dependency 'pry-nav'
|
36
|
+
spec.add_development_dependency 'guard'
|
37
|
+
spec.add_development_dependency 'guard-rspec'
|
38
|
+
spec.add_development_dependency 'guard-bundler'
|
39
|
+
spec.add_development_dependency 'guard-rubocop'
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module BasecommSdk
|
2
|
+
class Address < Base
|
3
|
+
NAME = {
|
4
|
+
xs_address_name_home: 'HOME',
|
5
|
+
xs_address_name_work: 'WORK',
|
6
|
+
xs_address_name_mailing: 'MAILING',
|
7
|
+
xs_address_name_shipping: 'SHIPPING',
|
8
|
+
xs_address_name_billing: 'BILLING',
|
9
|
+
xs_address_name_dba: 'DBA',
|
10
|
+
xs_address_name_legal: 'LEGAL'
|
11
|
+
}
|
12
|
+
|
13
|
+
attr_accessor :name, :line1, :line2, :line3, :city, :state, :zipcode,
|
14
|
+
:country
|
15
|
+
|
16
|
+
def self.build_from_json(json)
|
17
|
+
Address.new(JSON.parse(json).recursively_symbolize_keys!)
|
18
|
+
end
|
19
|
+
singleton_class.send(:alias_method, :from_json, :build_from_json)
|
20
|
+
|
21
|
+
def json_prefix
|
22
|
+
:address
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module BasecommSdk
|
2
|
+
class BankAccount < Base
|
3
|
+
TYPE = {
|
4
|
+
xs_ba_type_checking: 'CHECKING',
|
5
|
+
xs_ba_type_savings: 'SAVINGS'
|
6
|
+
}
|
7
|
+
ENTITY = {
|
8
|
+
xs_ba_entity_individual: 'INDIVIDUAL',
|
9
|
+
xs_ba_entity_organization: 'ORGANIZATION'
|
10
|
+
}
|
11
|
+
STATUS = {
|
12
|
+
xs_ba_status_active: 'ACTIVE',
|
13
|
+
xs_ba_status_deleted: 'DELETED',
|
14
|
+
xs_ba_status_failed: 'FAILED'
|
15
|
+
}
|
16
|
+
|
17
|
+
attr_accessor :name, :alias, :account_number, :routing_number, :token,
|
18
|
+
:status, :type
|
19
|
+
|
20
|
+
def self.build_from_json(json)
|
21
|
+
BankAccount.new(JSON.parse(json).recursively_symbolize_keys!)
|
22
|
+
end
|
23
|
+
singleton_class.send(:alias_method, :from_json, :build_from_json)
|
24
|
+
|
25
|
+
def json_prefix
|
26
|
+
:bank_account
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module BasecommSdk
|
2
|
+
class BankAccountTransaction < Base
|
3
|
+
ACCOUNT_TYPE = {
|
4
|
+
xs_bat_account_type_checking: 'CHECKING',
|
5
|
+
xs_bat_account_type_savings: 'SAVINGS'
|
6
|
+
}
|
7
|
+
TYPE = {
|
8
|
+
xs_bat_type_credit: 'CREDIT',
|
9
|
+
xs_bat_type_debit: 'DEBIT',
|
10
|
+
xs_bat_type_reversal: 'REVERSAL',
|
11
|
+
xs_bat_type_cancel: 'CANCEL'
|
12
|
+
}
|
13
|
+
STATUS = {
|
14
|
+
xs_bat_status_created: 'CREATED',
|
15
|
+
xs_bat_status_initiated: 'INITIATED',
|
16
|
+
xs_bat_status_settled: 'SETTLED',
|
17
|
+
xs_bat_status_returned: 'RETURNED',
|
18
|
+
xs_bat_status_canceled: 'CANCELED',
|
19
|
+
xs_bat_status_failed: 'FAILED',
|
20
|
+
xs_bat_status_rejected: 'REJECTED'
|
21
|
+
}
|
22
|
+
METHOD = {
|
23
|
+
xs_bat_method_ccd: 'CCD',
|
24
|
+
xs_bat_method_ppd: 'PPD',
|
25
|
+
xs_bat_method_tel: 'TEL',
|
26
|
+
xs_bat_method_web: 'WEB'
|
27
|
+
}
|
28
|
+
|
29
|
+
attr_accessor :id, :type, :status, :method,
|
30
|
+
:account_type, :routing_number, :account_number, :account_name,
|
31
|
+
:return_code, :trace, :merchant_transaction_id, :bank_account_token,
|
32
|
+
:micr_data, :amount, :effective_date, :settlement_date, :return_date,
|
33
|
+
:recurring_indicator
|
34
|
+
|
35
|
+
attr_accessor :custom_field1, :custom_field2, :custom_field3,
|
36
|
+
:custom_field4, :custom_field5, :custom_field6, :custom_field7,
|
37
|
+
:custom_field8, :custom_field9, :custom_field10
|
38
|
+
|
39
|
+
def self.build_from_json(json)
|
40
|
+
BankAccountTransaction.new(JSON.parse(json).recursively_symbolize_keys!)
|
41
|
+
end
|
42
|
+
singleton_class.send(:alias_method, :from_json, :build_from_json)
|
43
|
+
|
44
|
+
def json_prefix
|
45
|
+
:bank_account_transaction
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module BasecommSdk
|
2
|
+
class BankCard < Base
|
3
|
+
STATUS = {
|
4
|
+
xs_bc_status_active: 'ACTIVE',
|
5
|
+
xs_bc_status_deleted: 'DELETED',
|
6
|
+
xs_bc_status_failed: 'FAILED'
|
7
|
+
}
|
8
|
+
|
9
|
+
attr_accessor :name, :number, :alias, :expiration_month, :expiration_year,
|
10
|
+
:status, :billing_address, :token, :creation_date, :last_used_date
|
11
|
+
|
12
|
+
def self.build_from_json(json)
|
13
|
+
BankCard.new(JSON.parse(json).recursively_symbolize_keys!)
|
14
|
+
end
|
15
|
+
singleton_class.send(:alias_method, :from_json, :build_from_json)
|
16
|
+
|
17
|
+
def initialize(options = {})
|
18
|
+
super
|
19
|
+
@billing_address = Address.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def json_prefix
|
23
|
+
:bank_card
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module BasecommSdk
|
2
|
+
class BankCardTransaction < Base
|
3
|
+
TYPE = {
|
4
|
+
xs_bct_type_auth: 'AUTH',
|
5
|
+
xs_bct_type_sale: 'SALE',
|
6
|
+
xs_bct_type_void: 'VOID',
|
7
|
+
xs_bct_type_capture: 'CAPTURE',
|
8
|
+
xs_bct_type_refund: 'REFUND',
|
9
|
+
xs_bct_type_credit: 'CREDIT'
|
10
|
+
}
|
11
|
+
|
12
|
+
STATUS = {
|
13
|
+
xs_bct_status_created: 'CREATED',
|
14
|
+
xs_bct_status_authorized: 'AUTHORIZED',
|
15
|
+
xs_bct_status_captured: 'CAPTURED',
|
16
|
+
xs_bct_status_settled: 'SETTLED',
|
17
|
+
xs_bct_status_voided: 'VOIDED',
|
18
|
+
xs_bct_status_declined: 'DECLINED',
|
19
|
+
xs_bct_status_failed: 'FAILED',
|
20
|
+
xs_bct_status_3dsecure: '3DSECURE',
|
21
|
+
xs_bct_status_verified: 'VERIFIED'
|
22
|
+
}
|
23
|
+
|
24
|
+
attr_accessor :billing_address, :type, :card_number, :card_name,
|
25
|
+
:expiration_month, :expiration_year, :card_cvv2,
|
26
|
+
:card_track1_data, :card_track2_data, :ip_address, :po_number,
|
27
|
+
:authorization_code,
|
28
|
+
:response_code, :status, :response_message, :cvv_response_code,
|
29
|
+
:avs_response_code, :encrypted_track_data, :merchant_transaction_id,
|
30
|
+
:verify_complete_url, :verify_url, :amount, :tax_amount, :tip_amount,
|
31
|
+
:id, :settlement_batch_id, :check_secure_code, :recurring_indicator,
|
32
|
+
:token, :settlement_date, :creation_date
|
33
|
+
|
34
|
+
attr_accessor :custom_field1, :custom_field2, :custom_field3,
|
35
|
+
:custom_field4, :custom_field5, :custom_field6, :custom_field7,
|
36
|
+
:custom_field8, :custom_field9, :custom_field10
|
37
|
+
|
38
|
+
def self.build_from_json(json)
|
39
|
+
BankCardTransaction.new(JSON.parse(json).recursively_symbolize_keys!)
|
40
|
+
end
|
41
|
+
singleton_class.send(:alias_method, :from_json, :build_from_json)
|
42
|
+
|
43
|
+
def initialize(options = {})
|
44
|
+
super
|
45
|
+
@billing_address = Address.new
|
46
|
+
end
|
47
|
+
|
48
|
+
def json_prefix
|
49
|
+
:bank_card_transaction
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# rubocop:disable Style/TrivialAccessors
|
2
|
+
module BasecommSdk
|
3
|
+
class Base
|
4
|
+
def self.attr_accessor(*vars)
|
5
|
+
@attributes ||= []
|
6
|
+
@attributes.concat(vars)
|
7
|
+
super(*vars)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.attributes
|
11
|
+
@attributes
|
12
|
+
end
|
13
|
+
|
14
|
+
# Accepts prefixed attribute keys as well as non-prefixed
|
15
|
+
def initialize(options = {})
|
16
|
+
@messages = []
|
17
|
+
instance_hash = options.fetch(json_prefix, options)
|
18
|
+
attributes.each do |atr|
|
19
|
+
instance_variable_set(
|
20
|
+
"@#{atr}",
|
21
|
+
instance_hash.fetch(
|
22
|
+
"#{json_prefix}_#{atr}".to_sym,
|
23
|
+
instance_hash.fetch(
|
24
|
+
"#{atr}".to_sym,
|
25
|
+
nil
|
26
|
+
)
|
27
|
+
)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
# Populate messages with exceptions
|
31
|
+
if options[:exception]
|
32
|
+
options[:exception].each_pair do |k, v|
|
33
|
+
messages << {k => v}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def messages
|
39
|
+
@messages
|
40
|
+
end
|
41
|
+
|
42
|
+
def attributes
|
43
|
+
self.class.attributes
|
44
|
+
end
|
45
|
+
|
46
|
+
def qualified_attributes
|
47
|
+
array = []
|
48
|
+
attributes.each do |atr|
|
49
|
+
array << qualified_key(atr)
|
50
|
+
end
|
51
|
+
array
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_json(_options = {})
|
55
|
+
hash = {}
|
56
|
+
instance_variables.each do |iv|
|
57
|
+
var_name = iv.to_s[1..-1]
|
58
|
+
next if var_name.match(/messages$/)
|
59
|
+
var = instance_variable_get(iv)
|
60
|
+
hash[qualified_key(var_name)] = format(var) unless var.nil?
|
61
|
+
end
|
62
|
+
hash.to_json
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.json_prefix
|
66
|
+
new.json_prefix
|
67
|
+
end
|
68
|
+
|
69
|
+
def qualified_key(key)
|
70
|
+
"#{json_prefix}_#{key}".to_sym
|
71
|
+
end
|
72
|
+
|
73
|
+
def format(instance_var)
|
74
|
+
case instance_var.class.name
|
75
|
+
when 'Date', 'Time', 'DateTime'
|
76
|
+
instance_var.strftime('%m/%d/%Y %H:%M:%S')
|
77
|
+
else
|
78
|
+
instance_var
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def status_name
|
83
|
+
status["#{qualified_key('status')}_name".to_sym]
|
84
|
+
end
|
85
|
+
|
86
|
+
def status_description
|
87
|
+
status["#{qualified_key('status')}_description".to_sym]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
# rubocop:enable Style/TrivialAccessors
|