money_mover 0.0.3
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 +1 -0
- data/.rspec +2 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +80 -0
- data/lib/money_mover/dwolla/account_client.rb +9 -0
- data/lib/money_mover/dwolla/account_token.rb +24 -0
- data/lib/money_mover/dwolla/api_connection.rb +18 -0
- data/lib/money_mover/dwolla/api_server_response.rb +31 -0
- data/lib/money_mover/dwolla/application_client.rb +9 -0
- data/lib/money_mover/dwolla/application_token.rb +25 -0
- data/lib/money_mover/dwolla/client.rb +24 -0
- data/lib/money_mover/dwolla/config.rb +33 -0
- data/lib/money_mover/dwolla/environment_urls.rb +35 -0
- data/lib/money_mover/dwolla/error_handler.rb +30 -0
- data/lib/money_mover/dwolla/models/account_funding_source.rb +28 -0
- data/lib/money_mover/dwolla/models/api_resource.rb +70 -0
- data/lib/money_mover/dwolla/models/customer.rb +53 -0
- data/lib/money_mover/dwolla/models/document.rb +22 -0
- data/lib/money_mover/dwolla/models/funding_source.rb +30 -0
- data/lib/money_mover/dwolla/models/micro_deposit_initiation.rb +19 -0
- data/lib/money_mover/dwolla/models/micro_deposit_verification.rb +31 -0
- data/lib/money_mover/dwolla/models/receive_only_business_customer.rb +27 -0
- data/lib/money_mover/dwolla/models/receive_only_customer.rb +19 -0
- data/lib/money_mover/dwolla/models/root_account.rb +27 -0
- data/lib/money_mover/dwolla/models/transfer.rb +33 -0
- data/lib/money_mover/dwolla/models/unverified_business_customer.rb +43 -0
- data/lib/money_mover/dwolla/models/unverified_customer.rb +27 -0
- data/lib/money_mover/dwolla/models/verified_business_customer.rb +53 -0
- data/lib/money_mover/dwolla/models/webhook_subscription.rb +36 -0
- data/lib/money_mover/dwolla/token.rb +26 -0
- data/lib/money_mover/dwolla.rb +44 -0
- data/lib/money_mover/standalone_errors.rb +12 -0
- data/lib/money_mover/version.rb +3 -0
- data/lib/money_mover.rb +15 -0
- data/money_mover.gemspec +27 -0
- data/spec/integration/money_mover/dwolla/customers/create_spec.rb +75 -0
- data/spec/integration/money_mover/dwolla/customers/find_spec.rb +71 -0
- data/spec/integration/money_mover/dwolla/customers/funding-sources/create_spec.rb +40 -0
- data/spec/integration/money_mover/dwolla/documents/create_spec.rb +62 -0
- data/spec/integration/money_mover/dwolla/funding-sources/micro-deposits/initiation_spec.rb +52 -0
- data/spec/integration/money_mover/dwolla/funding-sources/micro-deposits/verification_spec.rb +77 -0
- data/spec/integration/money_mover/dwolla/transfers/create_spec.rb +80 -0
- data/spec/lib/money_mover/dwolla/client_spec.rb +101 -0
- data/spec/lib/money_mover/dwolla/config_spec.rb +20 -0
- data/spec/lib/money_mover/dwolla/error_handler_spec.rb +78 -0
- data/spec/lib/money_mover/dwolla/funding_source_spec.rb +94 -0
- data/spec/lib/money_mover/dwolla/microdeposits_initiation_spec.rb +36 -0
- data/spec/lib/money_mover/dwolla/root_account_spec.rb +86 -0
- data/spec/lib/money_mover/dwolla/token_spec.rb +101 -0
- data/spec/lib/money_mover/dwolla/transfer_spec.rb +94 -0
- data/spec/lib/money_mover/dwolla/webhook_subscription_spec.rb +199 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/support/dwolla_helper.rb +330 -0
- data/spec/support/fixtures/sample.jpg +0 -0
- metadata +196 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
module MoneyMover
|
2
|
+
module Dwolla
|
3
|
+
class RootAccount < ApiResource
|
4
|
+
def account_resource_id
|
5
|
+
account_resource_location.split('/').last
|
6
|
+
end
|
7
|
+
|
8
|
+
def account_resource_location
|
9
|
+
_links.dig :account, :href
|
10
|
+
end
|
11
|
+
|
12
|
+
def funding_sources
|
13
|
+
@funding_sources ||= AccountFundingSource.all(account_resource_id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def bank_account_funding_source
|
17
|
+
funding_sources.detect{|source| source.bank_account? }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def self.fetch_endpoint
|
23
|
+
"/"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module MoneyMover
|
2
|
+
module Dwolla
|
3
|
+
class Transfer < ApiResource
|
4
|
+
attr_accessor :sender_funding_source_token, :destination_funding_source_token, :transfer_amount, :metadata
|
5
|
+
|
6
|
+
validates_presence_of :sender_funding_source_token, :destination_funding_source_token, :transfer_amount
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def create_endpoint
|
11
|
+
"/transfers"
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_params
|
15
|
+
{
|
16
|
+
_links: {
|
17
|
+
destination: {
|
18
|
+
href: "#{@client.api_url}/funding-sources/#{@destination_funding_source_token}"
|
19
|
+
},
|
20
|
+
source: {
|
21
|
+
href: "#{@client.api_url}/funding-sources/#{@sender_funding_source_token}"
|
22
|
+
}
|
23
|
+
},
|
24
|
+
amount: {
|
25
|
+
value: @transfer_amount.to_s,
|
26
|
+
currency: "USD"
|
27
|
+
},
|
28
|
+
metadata: @metadata
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module MoneyMover
|
2
|
+
module Dwolla
|
3
|
+
class UnverifiedBusinessCustomer < Customer
|
4
|
+
validates_presence_of :businessName
|
5
|
+
|
6
|
+
def initialize(attrs = {})
|
7
|
+
attrs[:type] = 'unverified'
|
8
|
+
super attrs
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def create_params
|
14
|
+
create_attrs = {
|
15
|
+
firstName: firstName,
|
16
|
+
lastName: lastName,
|
17
|
+
email: email,
|
18
|
+
address1: address1,
|
19
|
+
address2: address2,
|
20
|
+
city: city,
|
21
|
+
state: state,
|
22
|
+
postalCode: postalCode,
|
23
|
+
dateOfBirth: dateOfBirth,
|
24
|
+
ssn: ssn,
|
25
|
+
phone: phone,
|
26
|
+
businessClassification: businessClassification,
|
27
|
+
businessType: businessType,
|
28
|
+
businessName: businessName,
|
29
|
+
ein: ein,
|
30
|
+
doingBusinessAs: doingBusinessAs,
|
31
|
+
website: website,
|
32
|
+
type: type,
|
33
|
+
ipAddress: ipAddress
|
34
|
+
}
|
35
|
+
|
36
|
+
# hack to fix bug on dwolla's side with funding sources being removed if no dba is sent
|
37
|
+
create_attrs[:doingBusinessAs] = businessName unless doingBusinessAs.present?
|
38
|
+
|
39
|
+
create_attrs.compact
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module MoneyMover
|
2
|
+
module Dwolla
|
3
|
+
class UnverifiedCustomer < Customer
|
4
|
+
private
|
5
|
+
|
6
|
+
validates_presence_of :firstName, :lastName, :email
|
7
|
+
|
8
|
+
def initialize(attrs={})
|
9
|
+
super attrs.merge(type: 'unverified')
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_params
|
13
|
+
create_attrs = {
|
14
|
+
firstName: firstName,
|
15
|
+
lastName: lastName,
|
16
|
+
email: email
|
17
|
+
}
|
18
|
+
|
19
|
+
create_attrs[:businessName] = businessName if businessName.present?
|
20
|
+
create_attrs[:ipAddress] = ipAddress if ipAddress.present?
|
21
|
+
#create_attrs[:type] = 'unverified'
|
22
|
+
|
23
|
+
create_attrs
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module MoneyMover
|
2
|
+
module Dwolla
|
3
|
+
class VerifiedBusinessCustomer < Customer
|
4
|
+
validates_presence_of :address1,
|
5
|
+
:city,
|
6
|
+
:state,
|
7
|
+
:postalCode,
|
8
|
+
:dateOfBirth,
|
9
|
+
:ssn,
|
10
|
+
:phone,
|
11
|
+
:businessClassification,
|
12
|
+
:businessType,
|
13
|
+
:businessName,
|
14
|
+
:ein
|
15
|
+
|
16
|
+
def initialize(attrs = {})
|
17
|
+
attrs[:type] = 'business'
|
18
|
+
super attrs
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def create_params
|
24
|
+
create_attrs = {
|
25
|
+
firstName: firstName,
|
26
|
+
lastName: lastName,
|
27
|
+
email: email,
|
28
|
+
address1: address1,
|
29
|
+
address2: address2,
|
30
|
+
city: city,
|
31
|
+
state: state,
|
32
|
+
postalCode: postalCode,
|
33
|
+
dateOfBirth: dateOfBirth,
|
34
|
+
ssn: ssn,
|
35
|
+
phone: phone,
|
36
|
+
businessClassification: businessClassification,
|
37
|
+
businessType: businessType,
|
38
|
+
businessName: businessName,
|
39
|
+
ein: ein,
|
40
|
+
doingBusinessAs: doingBusinessAs,
|
41
|
+
website: website,
|
42
|
+
type: type,
|
43
|
+
}
|
44
|
+
|
45
|
+
# hack to fix bug on dwolla's side with funding sources being removed if no dba is sent
|
46
|
+
create_attrs[:doingBusinessAs] = businessName unless doingBusinessAs.present?
|
47
|
+
create_attrs[:ipAddress] = ipAddress if ipAddress.present?
|
48
|
+
|
49
|
+
create_attrs
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module MoneyMover
|
2
|
+
module Dwolla
|
3
|
+
class WebhookSubscription < ApiResource
|
4
|
+
attr_accessor :url, :secret
|
5
|
+
|
6
|
+
validates_presence_of :url, :secret
|
7
|
+
|
8
|
+
def initialize(attrs = {}, client = ApplicationClient.new)
|
9
|
+
super_attrs = { id: attrs[:id], url: attrs[:url], secret: attrs[:secret] }
|
10
|
+
super super_attrs, client
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.all
|
14
|
+
response = ApplicationClient.new.get fetch_endpoint
|
15
|
+
response.body[:_embedded][:'webhook-subscriptions'].map{|sub| self.new(sub) }
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def self.fetch_endpoint
|
21
|
+
'/webhook-subscriptions'
|
22
|
+
end
|
23
|
+
|
24
|
+
def create_endpoint
|
25
|
+
'/webhook-subscriptions'
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_params
|
29
|
+
{
|
30
|
+
url: url,
|
31
|
+
secret: secret
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module MoneyMover
|
2
|
+
module Dwolla
|
3
|
+
class Token
|
4
|
+
attr_reader :account_id, :expires_in, :access_token, :refresh_token, :_links, :token_type, :refresh_expires_in, :scope
|
5
|
+
|
6
|
+
def initialize(attrs={}, ach_config = Config.new, client = Client.new)
|
7
|
+
@_links = attrs[:_links]
|
8
|
+
@account_id = attrs[:account_id]
|
9
|
+
@expires_in = attrs[:expires_in]
|
10
|
+
@refresh_expires_in = attrs[:refresh_expires_in]
|
11
|
+
@access_token = attrs[:access_token]
|
12
|
+
@refresh_token = attrs[:refresh_token]
|
13
|
+
@token_type = attrs[:token_type]
|
14
|
+
@scope = attrs[:scope]
|
15
|
+
|
16
|
+
@ach_config = ach_config
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def request_new_token!
|
21
|
+
response = @client.post @client.token_url, create_params
|
22
|
+
Token.new response.body
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'money_mover/dwolla/config'
|
2
|
+
require 'money_mover/dwolla/api_connection'
|
3
|
+
require 'money_mover/dwolla/api_server_response'
|
4
|
+
|
5
|
+
# token stuff
|
6
|
+
require 'money_mover/dwolla/client'
|
7
|
+
require 'money_mover/dwolla/token'
|
8
|
+
require 'money_mover/dwolla/account_client'
|
9
|
+
require 'money_mover/dwolla/account_token'
|
10
|
+
require 'money_mover/dwolla/application_client'
|
11
|
+
require 'money_mover/dwolla/application_token'
|
12
|
+
|
13
|
+
require 'money_mover/dwolla/environment_urls'
|
14
|
+
require 'money_mover/dwolla/error_handler'
|
15
|
+
|
16
|
+
require 'money_mover/dwolla/models/api_resource'
|
17
|
+
# models
|
18
|
+
require 'money_mover/dwolla/models/account_funding_source'
|
19
|
+
require 'money_mover/dwolla/models/document'
|
20
|
+
require 'money_mover/dwolla/models/funding_source'
|
21
|
+
require 'money_mover/dwolla/models/micro_deposit_initiation'
|
22
|
+
require 'money_mover/dwolla/models/micro_deposit_verification'
|
23
|
+
require 'money_mover/dwolla/models/transfer'
|
24
|
+
require 'money_mover/dwolla/models/root_account'
|
25
|
+
# customer models
|
26
|
+
require 'money_mover/dwolla/models/customer'
|
27
|
+
require 'money_mover/dwolla/models/receive_only_business_customer'
|
28
|
+
require 'money_mover/dwolla/models/receive_only_customer'
|
29
|
+
require 'money_mover/dwolla/models/unverified_customer'
|
30
|
+
require 'money_mover/dwolla/models/unverified_business_customer'
|
31
|
+
require 'money_mover/dwolla/models/verified_business_customer'
|
32
|
+
|
33
|
+
# application stuff
|
34
|
+
require 'money_mover/dwolla/models/webhook_subscription'
|
35
|
+
|
36
|
+
module MoneyMover
|
37
|
+
module Dwolla
|
38
|
+
@config_provider = nil
|
39
|
+
|
40
|
+
class << self
|
41
|
+
attr_accessor :config_provider
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class StandaloneErrors < SimpleDelegator
|
2
|
+
extend ActiveModel::Naming
|
3
|
+
extend ActiveModel::Translation
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
super ActiveModel::Errors.new(self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def copy!(error_source)
|
10
|
+
error_source.errors.each { |key, msg| add key, msg }
|
11
|
+
end
|
12
|
+
end
|
data/lib/money_mover.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_support/core_ext/hash'
|
2
|
+
#require 'active_support/hash_with_indifferent_access'
|
3
|
+
|
4
|
+
require 'faraday'
|
5
|
+
require 'faraday_middleware'
|
6
|
+
require 'active_model'
|
7
|
+
|
8
|
+
require 'money_mover/version'
|
9
|
+
require 'money_mover/standalone_errors'
|
10
|
+
|
11
|
+
# dwolla
|
12
|
+
require 'money_mover/dwolla'
|
13
|
+
|
14
|
+
module MoneyMover; end
|
15
|
+
|
data/money_mover.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
|
3
|
+
require 'money_mover/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.required_ruby_version = '>= 1.9.3'
|
7
|
+
s.name = 'money_mover'
|
8
|
+
s.version = MoneyMover::VERSION
|
9
|
+
s.date = '2016-07-21'
|
10
|
+
s.summary = "Money Mover"
|
11
|
+
s.description = "Moves Money with ACH integrations (dwolla, stripe)"
|
12
|
+
s.authors = ["Daniel Errante"]
|
13
|
+
s.email = 'danoph@gmail.com'
|
14
|
+
s.files = ["lib/money_mover.rb"]
|
15
|
+
s.homepage = 'https://github.com/danoph/money_mover'
|
16
|
+
s.license = 'MIT'
|
17
|
+
|
18
|
+
s.add_dependency('faraday', '~> 0.9', '>= 0.9.0')
|
19
|
+
s.add_dependency('faraday_middleware', '~> 0.9', '>= 0.9.0')
|
20
|
+
s.add_dependency('activemodel', '~> 4.2', '>= 4.2.6')
|
21
|
+
s.add_dependency('activesupport', '~> 4.2', '>= 4.2.6')
|
22
|
+
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
25
|
+
#s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
|
+
s.require_paths = ['lib']
|
27
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MoneyMover::Dwolla::UnverifiedCustomer do
|
4
|
+
let(:firstName) { 'first name' }
|
5
|
+
let(:lastName) { 'last name' }
|
6
|
+
let(:email) { 'some@example.com' }
|
7
|
+
let(:ipAddress) { '127.0.0.1' }
|
8
|
+
|
9
|
+
let(:attrs) {{
|
10
|
+
firstName: firstName,
|
11
|
+
lastName: lastName,
|
12
|
+
email: email,
|
13
|
+
ipAddress: ipAddress
|
14
|
+
}}
|
15
|
+
|
16
|
+
subject { described_class.new(attrs) }
|
17
|
+
|
18
|
+
let(:customer_token) { '9481924a-6795-4e7a-b436-a7a48a4141ca' }
|
19
|
+
|
20
|
+
let(:create_customer_params) {{
|
21
|
+
firstName: firstName,
|
22
|
+
lastName: lastName,
|
23
|
+
email: email,
|
24
|
+
ipAddress: ipAddress
|
25
|
+
}}
|
26
|
+
|
27
|
+
before do
|
28
|
+
dwolla_helper.stub_create_customer_request create_customer_params, create_response
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#save' do
|
32
|
+
context 'success' do
|
33
|
+
let(:create_response) { dwolla_helper.customer_created_response customer_token }
|
34
|
+
|
35
|
+
it 'creates new customer in dwolla' do
|
36
|
+
expect(subject.save).to eq(true)
|
37
|
+
expect(subject.id).to eq(customer_token)
|
38
|
+
expect(subject.resource_location).to eq(dwolla_helper.customer_endpoint(customer_token))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'fail' do
|
43
|
+
let(:create_response) { dwolla_helper.resource_create_error_response error_response }
|
44
|
+
|
45
|
+
#let(:error_response) {{
|
46
|
+
#code: "ValidationError",
|
47
|
+
#message: "Validation error(s) present. See embedded errors list for more details.",
|
48
|
+
#_embedded: {
|
49
|
+
#errors: [
|
50
|
+
#{ code: "Invalid", message: "Invalid parameter.", path: "/firstName"
|
51
|
+
#}
|
52
|
+
#]
|
53
|
+
#}
|
54
|
+
#}}
|
55
|
+
|
56
|
+
let(:error_response) {{
|
57
|
+
code: "ValidationError",
|
58
|
+
message: "Validation error(s) present. See embedded errors list for more details.",
|
59
|
+
_embedded: {
|
60
|
+
errors: [
|
61
|
+
{ code: "Duplicate", message: "A customer with the specified email already exists.", path: "/email"
|
62
|
+
}
|
63
|
+
]
|
64
|
+
}
|
65
|
+
}}
|
66
|
+
|
67
|
+
it 'returns errors' do
|
68
|
+
expect(subject.save).to eq(false)
|
69
|
+
expect(subject.errors[:email]).to eq(['A customer with the specified email already exists.'])
|
70
|
+
expect(subject.id).to be_nil
|
71
|
+
expect(subject.resource_location).to be_nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MoneyMover::Dwolla::Customer do
|
4
|
+
let(:customer_token) { '9481924a-6795-4e7a-b436-a7a48a4141ca' }
|
5
|
+
|
6
|
+
let(:firstName) { 'first name' }
|
7
|
+
let(:lastName) { 'last name' }
|
8
|
+
let(:email) { 'email@example.com' }
|
9
|
+
let(:ipAddress) { '127.0.0.1' }
|
10
|
+
|
11
|
+
before do
|
12
|
+
dwolla_helper.stub_find_customer_request customer_token, customer_response
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.find' do
|
16
|
+
subject { described_class.find(customer_token) }
|
17
|
+
|
18
|
+
context 'success' do
|
19
|
+
let(:timestamp) { DateTime.now.to_s }
|
20
|
+
|
21
|
+
let(:customer_response_object) {{
|
22
|
+
_links: {
|
23
|
+
self: {
|
24
|
+
href: dwolla_helper.customer_endpoint(customer_token)
|
25
|
+
}
|
26
|
+
},
|
27
|
+
id: customer_token,
|
28
|
+
firstName: firstName,
|
29
|
+
lastName: lastName,
|
30
|
+
email: email,
|
31
|
+
ipAddress: ipAddress,
|
32
|
+
type: 'unverified',
|
33
|
+
status: 'unverified',
|
34
|
+
created: timestamp
|
35
|
+
}}
|
36
|
+
|
37
|
+
let(:customer_response) {{
|
38
|
+
status: 200,
|
39
|
+
body: customer_response_object.to_json,
|
40
|
+
headers: {
|
41
|
+
'Content-Type' => 'application/json'
|
42
|
+
}
|
43
|
+
}}
|
44
|
+
|
45
|
+
it 'returns customer' do
|
46
|
+
expect(subject.id).to eq(customer_token)
|
47
|
+
#expect(subject.resource_location).to eq(dwolla_helper.customer_endpoint(customer_token))
|
48
|
+
expect(subject.firstName).to eq(firstName)
|
49
|
+
expect(subject.lastName).to eq(lastName)
|
50
|
+
expect(subject.email).to eq(email)
|
51
|
+
expect(subject.ipAddress).to eq(ipAddress)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'failure' do
|
56
|
+
let(:response_body) {{
|
57
|
+
code: 'Something',
|
58
|
+
message: 'Customer not found.'
|
59
|
+
}}
|
60
|
+
|
61
|
+
let(:customer_response) {{
|
62
|
+
status: 404,
|
63
|
+
body: response_body.to_json
|
64
|
+
}}
|
65
|
+
|
66
|
+
it 'returns errors' do
|
67
|
+
expect { subject }.to raise_error('Customer Not Found')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MoneyMover::Dwolla::FundingSource do
|
4
|
+
let(:name) { 'my checking account' }
|
5
|
+
let(:type) { 'checking' }
|
6
|
+
let(:routingNumber) { '222222226' }
|
7
|
+
let(:accountNumber) { '9393' }
|
8
|
+
|
9
|
+
let(:attrs) {{
|
10
|
+
#customer_id: customer_token,
|
11
|
+
name: name,
|
12
|
+
type: type,
|
13
|
+
routingNumber: routingNumber,
|
14
|
+
accountNumber: accountNumber
|
15
|
+
}}
|
16
|
+
|
17
|
+
subject { described_class.new(customer_token, attrs) }
|
18
|
+
|
19
|
+
let(:customer_token) { '9481924a-6795-4e7a-b436-a7a48a4141ca' }
|
20
|
+
let(:funding_source_token) { 'FC451A7A-AE30-4404-AB95-E3553FCD733F' }
|
21
|
+
|
22
|
+
let(:create_params) {{
|
23
|
+
name: name,
|
24
|
+
type: type,
|
25
|
+
routingNumber: routingNumber,
|
26
|
+
accountNumber: accountNumber
|
27
|
+
}}
|
28
|
+
|
29
|
+
before do
|
30
|
+
dwolla_helper.stub_create_customer_funding_source_request customer_token, create_params, dwolla_helper.customer_funding_source_created_response(customer_token, funding_source_token)
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#save' do
|
34
|
+
it 'creates new customer funding source in dwolla' do
|
35
|
+
expect(subject.save).to eq(true)
|
36
|
+
expect(subject.id).to eq(funding_source_token)
|
37
|
+
expect(subject.resource_location).to eq(dwolla_helper.customer_funding_source_endpoint(customer_token, funding_source_token))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MoneyMover::Dwolla::Document do
|
4
|
+
let(:customer_id) { 'customer-id' }
|
5
|
+
let(:file) { File.expand_path('../../../../../support/fixtures/sample.jpg', __FILE__) }
|
6
|
+
let(:file_fixture) { Rack::Test::UploadedFile.new(file, 'image/jpeg') }
|
7
|
+
let(:documentType) { 'other' }
|
8
|
+
|
9
|
+
let(:attrs) {{
|
10
|
+
customer_id: customer_id,
|
11
|
+
documentType: 'other',
|
12
|
+
file: file_fixture
|
13
|
+
}}
|
14
|
+
|
15
|
+
subject { described_class.new(attrs) }
|
16
|
+
|
17
|
+
let(:create_params) {{
|
18
|
+
documentType: documentType,
|
19
|
+
#file: File.new(file, 'rb')
|
20
|
+
#file: Faraday::UploadIO.new(file)
|
21
|
+
}}
|
22
|
+
|
23
|
+
let(:resource_token) { 'some-token' }
|
24
|
+
|
25
|
+
before do
|
26
|
+
dwolla_helper.stub_request(:post, dwolla_helper.build_dwolla_url(dwolla_helper.customer_documents_endpoint(customer_id))).with(headers: dwolla_helper.request_headers).to_return(create_response)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#save' do
|
30
|
+
context 'success' do
|
31
|
+
let(:create_response) { dwolla_helper.customer_document_created_response resource_token }
|
32
|
+
|
33
|
+
it 'creates new resource in dwolla' do
|
34
|
+
expect(subject.save).to eq(true)
|
35
|
+
expect(subject.id).to eq(resource_token)
|
36
|
+
expect(subject.resource_location).to eq(dwolla_helper.document_endpoint(resource_token))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'fail' do
|
41
|
+
let(:create_response) { dwolla_helper.resource_create_error_response error_response }
|
42
|
+
|
43
|
+
let(:error_response) {{
|
44
|
+
code: "ValidationError",
|
45
|
+
message: "Validation error(s) present. See embedded errors list for more details.",
|
46
|
+
_embedded: {
|
47
|
+
errors: [
|
48
|
+
{ code: "Invalid", message: "Invalid parameter.", path: "/file"
|
49
|
+
}
|
50
|
+
]
|
51
|
+
}
|
52
|
+
}}
|
53
|
+
|
54
|
+
it 'returns errors' do
|
55
|
+
expect(subject.save).to eq(false)
|
56
|
+
expect(subject.errors[:file]).to eq(['Invalid parameter.'])
|
57
|
+
expect(subject.id).to be_nil
|
58
|
+
expect(subject.resource_location).to be_nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MoneyMover::Dwolla::MicroDepositInitiation do
|
4
|
+
let(:funding_source_token) { '9481924a-6795-4e7a-b436-a7a48a4141ca' }
|
5
|
+
|
6
|
+
let(:attrs) {{
|
7
|
+
funding_source_id: funding_source_token,
|
8
|
+
}}
|
9
|
+
|
10
|
+
subject { described_class.new(attrs) }
|
11
|
+
|
12
|
+
let(:create_params) {{}}
|
13
|
+
|
14
|
+
before do
|
15
|
+
dwolla_helper.stub_funding_source_microdeposits_request funding_source_token, create_params, create_response
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:resource_created_location) { 'https://some-url.com' }
|
19
|
+
|
20
|
+
describe '#save' do
|
21
|
+
context 'success' do
|
22
|
+
let(:create_response) {{
|
23
|
+
status: 201,
|
24
|
+
body: ""
|
25
|
+
}}
|
26
|
+
|
27
|
+
it 'creates new resource in dwolla' do
|
28
|
+
expect(subject.save).to eq(true)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'fail' do
|
33
|
+
let(:create_response) {{
|
34
|
+
status: 400,
|
35
|
+
body: error_response.to_json,
|
36
|
+
headers: {
|
37
|
+
'Content-Type' => 'application/json'
|
38
|
+
}
|
39
|
+
}}
|
40
|
+
|
41
|
+
let(:error_response) {{
|
42
|
+
code: "ValidationError",
|
43
|
+
message: "Some error"
|
44
|
+
}}
|
45
|
+
|
46
|
+
it 'returns errors' do
|
47
|
+
expect(subject.save).to eq(false)
|
48
|
+
expect(subject.errors[:base]).to eq(['Some error'])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|