create a user account

This commit is contained in:
Rimian Perkins 2017-03-21 11:52:48 +11:00
parent 35f8c17e91
commit f77ddeba31
4 changed files with 32 additions and 7 deletions

View File

@ -10,8 +10,10 @@ module DiscourseDonations
Stripe.api_key = SiteSetting.discourse_donations_secret_key
currency = SiteSetting.discourse_donations_currency
current_user = create_user(params) if current_user.nil?
customer = Stripe::Customer.create(
:email => params[:email] || current_user.email,
:email => current_user.email,
:source => params[:stripeToken]
)
@ -24,5 +26,16 @@ module DiscourseDonations
render :json => charge
end
private
def create_user(options)
User.create(
email: options[:email],
username: options[:username],
name: options[:name],
password: options[:password]
)
end
end
end

View File

@ -54,7 +54,10 @@ export default Ember.Component.extend({
let params = {
stripeToken: data.token.id,
amount: self.get('amount') * 100,
email: self.get('email')
email: self.get('email'),
username: self.get('username'),
name: self.get('name'),
password: self.get('password')
};
ajax('/charges', { data: params, method: 'post' }).then(data => {

View File

@ -1,7 +1,7 @@
en:
site_settings:
discourse_donations_enabled: Enable the discourse donations plugin.
discourse_donations_enable_create_accounts: Enable anonymous users to create accounts after successful payment
discourse_donations_enable_create_accounts: "EXPERIMENTAL: Enable anonymous users to create accounts after successful payment"
discourse_donations_secret_key: Stripe Secret Key
discourse_donations_public_key: Stripe Public Key
discourse_donations_currency: Currency Code

View File

@ -7,12 +7,21 @@ module DiscourseDonations
before do
SiteSetting.stubs(:discourse_donations_secret_key).returns('secret-key-yo')
current_user = log_in(:coding_horror)
end
it 'responds with ok' do
post :create
expect(response).to have_http_status(200)
describe 'creating user accounts' do
it 'creates a new user account' do
controller.expects(:create_user).once
post :create, { email: 'foobar@example.com' }
expect(response).to have_http_status(200)
end
it 'does not create a new user account' do
controller.expects(:create_user).never
current_user = log_in(:coding_horror)
post :create
expect(response).to have_http_status(200)
end
end
end
end