From 2d8878b0b75c128b8df4e80cdd8ecadd9a2f352e Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Thu, 30 Mar 2017 10:40:08 +1100 Subject: [PATCH 1/5] upgrade stripe gem --- plugin.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.rb b/plugin.rb index 4e4bfd6..78a8033 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,10 +1,10 @@ # name: discourse-donations # about: Integrating Discourse with Stripe for donations -# version: 1.7.0 +# version: 1.7.1 # url: https://github.com/choiceaustralia/discourse-donations # authors: Rimian Perkins -gem 'stripe', '2.0.3' +gem 'stripe', '2.1.0' load File.expand_path('../lib/discourse_donations/engine.rb', __FILE__) From 62920636573427e73113118588053edb2c47d0dc Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Fri, 31 Mar 2017 10:17:13 +1100 Subject: [PATCH 2/5] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 041d932..d428a55 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,9 @@ [![Build Status](https://travis-ci.org/choiceaustralia/discourse-donations.svg?branch=master)](https://travis-ci.org/choiceaustralia/discourse-donations) -Accept donations in Discourse! Integrates with [Stripe](https://stripe.com). +Accept donations in Discourse! Integrates with [Stripe](https://stripe.com). + +Note: Stripe requires HTTPS. ## Installation From 6ff18309e4fe6283e6ed67c542eefbdac75ee628 Mon Sep 17 00:00:00 2001 From: Dax74 Date: Sun, 2 Apr 2017 20:15:39 +0200 Subject: [PATCH 3/5] Create client.it.yml Italian translation --- config/locales/client.it.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 config/locales/client.it.yml diff --git a/config/locales/client.it.yml b/config/locales/client.it.yml new file mode 100644 index 0000000..65d96ad --- /dev/null +++ b/config/locales/client.it.yml @@ -0,0 +1,10 @@ +it: + js: + discourse_donations: + title: Donazione + nav_item: Donazione + amount: Importo + card: Carta di credito o debito + submit: Effettua il pagamento + messages: + success: Grazie per la tua donazione! From 136755aa8b69937b9858beb2e54690a928b501ce Mon Sep 17 00:00:00 2001 From: Dax74 Date: Sun, 2 Apr 2017 20:15:59 +0200 Subject: [PATCH 4/5] Create server.it.yml Italian translation --- config/locales/server.it.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 config/locales/server.it.yml diff --git a/config/locales/server.it.yml b/config/locales/server.it.yml new file mode 100644 index 0000000..f2c08fa --- /dev/null +++ b/config/locales/server.it.yml @@ -0,0 +1,7 @@ +it: + site_settings: + discourse_donations_enabled: Abilita il plugin per le donazioni. + discourse_donations_secret_key: Stripe Secret Key + discourse_donations_public_key: Stripe Public Key + discourse_donations_currency: Codice Valuta + discourse_donations_hide_zip_code: Nascondi C.A.P. From 5d3db5373bd1c8687ae44fbddbf00f17a33973e3 Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Tue, 4 Apr 2017 12:00:23 +1000 Subject: [PATCH 5/5] respond with empty json if email does not exist --- .../discourse_donations/charges_controller.rb | 38 ++++++++++++------- plugin.rb | 2 +- .../charges_controller_spec.rb | 14 ++++++- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/app/controllers/discourse_donations/charges_controller.rb b/app/controllers/discourse_donations/charges_controller.rb index c45122c..308747b 100644 --- a/app/controllers/discourse_donations/charges_controller.rb +++ b/app/controllers/discourse_donations/charges_controller.rb @@ -7,22 +7,34 @@ module DiscourseDonations skip_before_filter :verify_authenticity_token, only: [:create] def create - Stripe.api_key = SiteSetting.discourse_donations_secret_key - currency = SiteSetting.discourse_donations_currency + if email.nil? + response = { - customer = Stripe::Customer.create( - :email => params[:email] || current_user.email, - :source => params[:stripeToken] - ) + } + else + Stripe.api_key = SiteSetting.discourse_donations_secret_key + currency = SiteSetting.discourse_donations_currency - charge = Stripe::Charge.create( - :customer => customer.id, - :amount => params[:amount], - :description => SiteSetting.discourse_donations_description, - :currency => currency - ) + customer = Stripe::Customer.create( + :email => email, + :source => params[:stripeToken] + ) - render :json => charge + response = Stripe::Charge.create( + :customer => customer.id, + :amount => params[:amount], + :description => SiteSetting.discourse_donations_description, + :currency => currency + ) + end + + render :json => response + end + + private + + def email + params[:email] || current_user.try(:email) end end end diff --git a/plugin.rb b/plugin.rb index 78a8033..2745f9e 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,6 +1,6 @@ # name: discourse-donations # about: Integrating Discourse with Stripe for donations -# version: 1.7.1 +# version: 1.7.2 # url: https://github.com/choiceaustralia/discourse-donations # authors: Rimian Perkins diff --git a/spec/controllers/discourse_donations/charges_controller_spec.rb b/spec/controllers/discourse_donations/charges_controller_spec.rb index 09aab13..13b51d4 100644 --- a/spec/controllers/discourse_donations/charges_controller_spec.rb +++ b/spec/controllers/discourse_donations/charges_controller_spec.rb @@ -7,10 +7,20 @@ 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 + it 'responds ok for anonymous users' do + post :create, { email: 'foobar@example.com' } + expect(response).to have_http_status(200) + end + + it 'responds ok when the email is empty' do + post :create, { } + expect(response).to have_http_status(200) + end + + it 'responds ok for logged in user' do + current_user = log_in(:coding_horror) post :create expect(response).to have_http_status(200) end