create a user account
This commit is contained in:
parent
35f8c17e91
commit
f77ddeba31
|
@ -10,8 +10,10 @@ module DiscourseDonations
|
||||||
Stripe.api_key = SiteSetting.discourse_donations_secret_key
|
Stripe.api_key = SiteSetting.discourse_donations_secret_key
|
||||||
currency = SiteSetting.discourse_donations_currency
|
currency = SiteSetting.discourse_donations_currency
|
||||||
|
|
||||||
|
current_user = create_user(params) if current_user.nil?
|
||||||
|
|
||||||
customer = Stripe::Customer.create(
|
customer = Stripe::Customer.create(
|
||||||
:email => params[:email] || current_user.email,
|
:email => current_user.email,
|
||||||
:source => params[:stripeToken]
|
:source => params[:stripeToken]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,5 +26,16 @@ module DiscourseDonations
|
||||||
|
|
||||||
render :json => charge
|
render :json => charge
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def create_user(options)
|
||||||
|
User.create(
|
||||||
|
email: options[:email],
|
||||||
|
username: options[:username],
|
||||||
|
name: options[:name],
|
||||||
|
password: options[:password]
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,7 +54,10 @@ export default Ember.Component.extend({
|
||||||
let params = {
|
let params = {
|
||||||
stripeToken: data.token.id,
|
stripeToken: data.token.id,
|
||||||
amount: self.get('amount') * 100,
|
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 => {
|
ajax('/charges', { data: params, method: 'post' }).then(data => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
en:
|
en:
|
||||||
site_settings:
|
site_settings:
|
||||||
discourse_donations_enabled: Enable the discourse donations plugin.
|
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_secret_key: Stripe Secret Key
|
||||||
discourse_donations_public_key: Stripe Public Key
|
discourse_donations_public_key: Stripe Public Key
|
||||||
discourse_donations_currency: Currency Code
|
discourse_donations_currency: Currency Code
|
||||||
|
|
|
@ -7,12 +7,21 @@ module DiscourseDonations
|
||||||
|
|
||||||
before do
|
before do
|
||||||
SiteSetting.stubs(:discourse_donations_secret_key).returns('secret-key-yo')
|
SiteSetting.stubs(:discourse_donations_secret_key).returns('secret-key-yo')
|
||||||
current_user = log_in(:coding_horror)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'responds with ok' do
|
describe 'creating user accounts' do
|
||||||
post :create
|
it 'creates a new user account' do
|
||||||
expect(response).to have_http_status(200)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue