6772312ea7
The primary license of the project is changing to: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later with some specific files to be licensed under the one of two licenses: CC0-1.0 LGPL-3.0-or-later This commit is one of the many steps to relicense the entire codebase. Documentation granting permission for this relicensing (from all past contributors who hold copyrights) is on file with Software Freedom Conservancy, Inc.
51 lines
1.4 KiB
Ruby
51 lines
1.4 KiB
Ruby
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
|
|
|
module StripeAccount
|
|
|
|
# Returns the stripe account ID string
|
|
def self.find_or_create(nonprofit_id)
|
|
ParamValidation.new({:nonprofit_id => nonprofit_id}, {:nonprofit_id => {:required=> true, :is_integer => true}})
|
|
begin
|
|
np = Nonprofit.find(nonprofit_id)
|
|
rescue => e
|
|
raise ParamValidation::ValidationError.new("#{nonprofit_id} is not a valid nonprofit", {:key => :nonprofit_id})
|
|
end
|
|
|
|
if !np['stripe_account_id']
|
|
return create(np)
|
|
else
|
|
return np['stripe_account_id']
|
|
end
|
|
end
|
|
|
|
# np should be a hash with string keys
|
|
def self.create(np)
|
|
ParamValidation.new({:np => np}, {:np => {:required=> true, :is_a => Nonprofit}})
|
|
params = {
|
|
managed: true,
|
|
email: np['email'],
|
|
business_name: np['name'],
|
|
legal_entity: {
|
|
type: 'company',
|
|
address: {
|
|
city: np['city'],
|
|
state: np['state_code'],
|
|
postal_code: np['zip_code'],
|
|
country: 'US'
|
|
},
|
|
business_name: np['name'],
|
|
},
|
|
product_description: 'Nonprofit donations',
|
|
transfer_schedule: { interval: 'manual' }
|
|
}
|
|
|
|
if np['website'] && np['website'] =~ URI::regexp
|
|
params[:business_url] = np['website']
|
|
end
|
|
|
|
acct = Stripe::Account.create(params)
|
|
Qx.update(:nonprofits).set(stripe_account_id: acct.id).where(id: np['id']).execute
|
|
NonprofitMailer.delay.setup_verification(np['id'])
|
|
return acct.id
|
|
end
|
|
end
|