Merge pull request #22 from houdiniproject/fix_for_stripe_email
Stripe can now be created when org doesn't have email address
This commit is contained in:
commit
2b85e7ce83
2 changed files with 44 additions and 3 deletions
|
@ -23,7 +23,7 @@ module StripeAccount
|
||||||
ParamValidation.new({:np => np}, {:np => {:required=> true, :is_a => Nonprofit}})
|
ParamValidation.new({:np => np}, {:np => {:required=> true, :is_a => Nonprofit}})
|
||||||
params = {
|
params = {
|
||||||
managed: true,
|
managed: true,
|
||||||
email: np['email'],
|
email: np['email'].present? ? np['email'] : np.roles.nonprofit_admins.order('created_at ASC').first.user.email,
|
||||||
business_name: np['name'],
|
business_name: np['name'],
|
||||||
legal_entity: {
|
legal_entity: {
|
||||||
type: 'company',
|
type: 'company',
|
||||||
|
|
|
@ -7,7 +7,7 @@ describe StripeAccount do
|
||||||
let(:stripe_helper) { StripeMock.create_test_helper }
|
let(:stripe_helper) { StripeMock.create_test_helper }
|
||||||
before(:each) { StripeMock.start}
|
before(:each) { StripeMock.start}
|
||||||
after(:each) { StripeMock.stop}
|
after(:each) { StripeMock.stop}
|
||||||
let!(:nonprofit) { force_create(:nonprofit)}
|
let(:nonprofit) { force_create(:nonprofit)}
|
||||||
|
|
||||||
describe '.find_or_create' do
|
describe '.find_or_create' do
|
||||||
describe 'param validation' do
|
describe 'param validation' do
|
||||||
|
@ -92,7 +92,7 @@ describe StripeAccount do
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'saves properly' do
|
describe 'saves properly without org email' do
|
||||||
|
|
||||||
let!(:result) { StripeAccount.create(nonprofit)}
|
let!(:result) { StripeAccount.create(nonprofit)}
|
||||||
|
|
||||||
|
@ -118,6 +118,47 @@ describe StripeAccount do
|
||||||
expect(np.stripe_account_id).to eq result
|
expect(np.stripe_account_id).to eq result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'saves properly without org email' do
|
||||||
|
|
||||||
|
before(:each){
|
||||||
|
nonprofit.email = nil
|
||||||
|
nonprofit.save!
|
||||||
|
|
||||||
|
role
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:admin_role_email) { "email_user@email.email"}
|
||||||
|
let(:user) { force_create(:user, email: admin_role_email)}
|
||||||
|
let(:role) { force_create(:role, user: user, host: nonprofit, name: :nonprofit_admin)}
|
||||||
|
|
||||||
|
|
||||||
|
let(:result) { StripeAccount.create(nonprofit)}
|
||||||
|
|
||||||
|
it 'returns a Stripe acct id' do
|
||||||
|
|
||||||
|
expect(result).to_not be_blank
|
||||||
|
end
|
||||||
|
it 'sets the Account values on Stripe' do
|
||||||
|
saved_account = Stripe::Account.retrieve(result)
|
||||||
|
expect(saved_account['managed']).to eq true
|
||||||
|
expect(saved_account['business_name']).to eq (nonprofit.name)
|
||||||
|
expect(saved_account['email']).to eq (admin_role_email)
|
||||||
|
expect(saved_account['business_url']).to eq (nonprofit.website)
|
||||||
|
expect(saved_account['legal_entity']['type']).to eq ("company")
|
||||||
|
expect(saved_account['legal_entity']['address']['city']).to eq (nonprofit.city)
|
||||||
|
expect(saved_account['legal_entity']['address']['state']).to eq (nonprofit.state_code)
|
||||||
|
expect(saved_account['legal_entity']['business_name']).to eq (nonprofit.name)
|
||||||
|
expect(saved_account['product_description']).to eq ('Nonprofit donations')
|
||||||
|
expect(saved_account['transfer_schedule']['interval']).to eq('manual')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'updates the nonprofit itself' do
|
||||||
|
result
|
||||||
|
np = Nonprofit.find(nonprofit.id)
|
||||||
|
expect(np.stripe_account_id).to eq result
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue