diff --git a/README.md b/README.md index 52b5fd7..2e82e0e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/chrisbeach/discourse-donations.svg?branch=master)](https://travis-ci.org/choiceaustralia/discourse-donations) -Accept donations in Discourse! Integrates with [Stripe](https://stripe.com). +Accept donations from visitors to your [Discourse](https://www.discourse.org/) forum. Integrates with [Stripe](https://stripe.com). ## Installation @@ -34,7 +34,7 @@ Accept donations in Discourse! Integrates with [Stripe](https://stripe.com). These numbers can be used in test mode to simulate a transaction. For more information see the [Stripe docs](https://stripe.com/docs/testing). -Card numbers in **bold** have beed tested. +Card numbers in **bold** have been tested. * **4000 0000 0000 0077** Charge succeeds and funds will be added directly to your available balance (bypassing your pending balance). * **4000 0000 0000 0093** Charge succeeds and domestic pricing is used (other test cards use international pricing). This card is only significant in countries with split pricing. @@ -42,7 +42,7 @@ Card numbers in **bold** have beed tested. * **4000 0000 0000 0028** Charge succeeds but the address_line1_check verification fails. * **4000 0000 0000 0036** The address_zip_check verification fails. If your account is blocking payments that fail postal code validation, the charge is declined. * **4000 0000 0000 0044** Charge succeeds but the address_zip_check and address_line1_check verifications are both unavailable. -* **4000 0000 0000 0101** If a CVC number is provided, the cvc_check fails. If your account is blocking payments that fail CVC code validation, the charge is declined. +* **4000 0000 0000 0101** If a CVC number is provided, the cvc_check fails. If your account is blocking payments that fail CVC code validation, the charge is declined. * **4000 0000 0000 0341** Attaching this card to a Customer object succeeds, but attempts to charge the customer fail. * **4000 0000 0000 9235** Charge succeeds with a risk_level of elevated and placed into review. * **4000 0000 0000 0002** Charge is declined with a card_declined code. diff --git a/app/controllers/discourse_donations/charges_controller.rb b/app/controllers/discourse_donations/charges_controller.rb index cf8ab50..463e50f 100644 --- a/app/controllers/discourse_donations/charges_controller.rb +++ b/app/controllers/discourse_donations/charges_controller.rb @@ -7,8 +7,7 @@ module DiscourseDonations skip_before_action :check_xhr def create - Rails.logger.debug params.inspect - Rails.logger.debug user_params.inspect + Rails.logger.info user_params.inspect output = { 'messages' => [], 'rewards' => [] } @@ -28,10 +27,12 @@ module DiscourseDonations render(:json => output.merge(success: false)) and return end + Rails.logger.debug "Creating a Stripe payment" payment = DiscourseDonations::Stripe.new(secret_key, stripe_options) begin - charge = payment.charge(email, opts: user_params) + Rails.logger.debug "Creating a Stripe charge for #{user_params[:amount]}" + charge = payment.charge(email, user_params[:stripeToken], user_params[:amount]) rescue ::Stripe::CardError => e err = e.json_body[:error] diff --git a/app/services/discourse_donations/stripe.rb b/app/services/discourse_donations/stripe.rb index 7c4f5d2..5283453 100644 --- a/app/services/discourse_donations/stripe.rb +++ b/app/services/discourse_donations/stripe.rb @@ -23,14 +23,14 @@ module DiscourseDonations charge end - def charge(email, opts) + def charge(email, token, amount) customer = ::Stripe::Customer.create( email: email, - source: opts[:stripeToken] + source: token ) @charge = ::Stripe::Charge.create( customer: customer.id, - amount: opts[:amount], + amount: amount, description: description, currency: currency ) diff --git a/assets/javascripts/discourse/components/stripe-card.js.es6 b/assets/javascripts/discourse/components/stripe-card.js.es6 index 14e50ca..56016ac 100644 --- a/assets/javascripts/discourse/components/stripe-card.js.es6 +++ b/assets/javascripts/discourse/components/stripe-card.js.es6 @@ -3,12 +3,12 @@ import { getRegister } from 'discourse-common/lib/get-owner'; export default Ember.Component.extend({ donateAmounts: [ - { value: 1, name: '$1.00'}, - { value: 2, name: '$2.00'}, - { value: 5, name: '$5.00'}, - { value: 10, name: '$10.00'}, - { value: 20, name: '$20.00'}, - { value: 50, name: '$50.00'} + { value: 1, name: '1.00'}, + { value: 2, name: '2.00'}, + { value: 5, name: '5.00'}, + { value: 10, name: '10.00'}, + { value: 20, name: '20.00'}, + { value: 50, name: '50.00'} ], result: [], amount: null, @@ -27,7 +27,7 @@ export default Ember.Component.extend({ card: function() { let elements = this.get('stripe').elements(); return elements.create('card', { - hidePostalCode: this.get('settings').discourse_donations_hide_zip_code + hidePostalCode: !this.get('settings').discourse_donations_zip_code }); }.property('stripe'), diff --git a/assets/javascripts/lib/discourse-markdown/stripe.js.es6 b/assets/javascripts/lib/discourse-markdown/stripe.js.es6 index adb1e6a..347a56a 100644 --- a/assets/javascripts/lib/discourse-markdown/stripe.js.es6 +++ b/assets/javascripts/lib/discourse-markdown/stripe.js.es6 @@ -3,7 +3,7 @@ function validationErrors(tagInfo, content, siteSettings) { if (!siteSettings.discourse_donations_public_key) { errors.push("missing key (site setting)"); } if (!siteSettings.discourse_donations_currency) { errors.push("missing currency (site setting)"); } if (!siteSettings.discourse_donations_shop_name) { errors.push("missing name (site setting)"); } - if (!siteSettings.discourse_donations_hide_zip_code) { errors.push("missing zip code toggle (site setting)"); } + if (!siteSettings.discourse_donations_zip_code) { errors.push("missing zip code toggle (site setting)"); } if (!siteSettings.discourse_donations_billing_address) { errors.push("missing billing address toggle (site setting)"); } if (!tagInfo.attrs['amount']) { errors.push("missing amount"); } if (!content) { errors.push("missing description"); } @@ -47,7 +47,7 @@ function insertCheckout(state, tagInfo, content, siteSettings) { ['data-description', content], ['data-image', tagInfo.attrs['image'] || ''], ['data-locale', 'auto'], - ['data-zip-code', !siteSettings.discourse_donations_hide_zip_code], + ['data-zip-code', siteSettings.discourse_donations_zip_code], ['data-billing-address', siteSettings.discourse_donations_billing_address], ['data-currency', siteSettings.discourse_donations_currency] ]; diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index bcd8b03..2dfa97c 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1,4 +1,16 @@ en: + site_settings: + discourse_donations_enabled: "Enable the Discourse Donations plugin." + 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_shop_name: "Shop Name shown in Stripe Checkout form" + discourse_donations_description: "Description shown in Stripe Checkout form" + discourse_donations_currency: "Currency Code" + discourse_donations_zip_code: "Show Zip Code" + discourse_donations_billing_address: "Collect billing address" + discourse_donations_reward_badge_name: "Grant this badge to user when a payment is successful" + discourse_donations_reward_group_name: "Add the user to this group when a payment is successful" js: discourse_donations: title: Donate diff --git a/config/locales/client.fi.yml b/config/locales/client.fi.yml index 485a800..351f1cd 100644 --- a/config/locales/client.fi.yml +++ b/config/locales/client.fi.yml @@ -1,4 +1,9 @@ fi: + site_settings: + discourse_donations_enabled: Ota käyttöön lahjoituslisäosa. + discourse_donations_secret_key: Stripen Secret Key -salausavain + discourse_donations_public_key: Stripen Public Key -tunnistusavain + discourse_donations_currency: Valuuttakoodi js: discourse_donations: title: Lahjoita diff --git a/config/locales/client.it.yml b/config/locales/client.it.yml index b0dfe9c..fe95322 100644 --- a/config/locales/client.it.yml +++ b/config/locales/client.it.yml @@ -1,4 +1,12 @@ it: + site_settings: + discourse_donations_enabled: Abilita il plugin per le donazioni. + discourse_donations_enable_create_accounts: "SPERIMENTALE: Permetti agli utenti anonimi la creazione di un account dopo un pagamento effettuato con successo" + discourse_donations_secret_key: Stripe Secret Key + discourse_donations_public_key: Stripe Public Key + discourse_donations_currency: Codice Valuta + discourse_donations_reward_badge_name: Assegna questo distintivo all'utente quando un pagamento viene effettuato con successo + discourse_donations_reward_group_name: Aggiungi l'utente a questo gruppo quando un pagamento viene effettuato con successo js: discourse_donations: title: Donazione diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 36fc3f7..dc63d40 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1,15 +1,3 @@ -en: - site_settings: - discourse_donations_enabled: "Enable the discourse donations plugin." - 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_shop_name: "Stripe Shop Name" - discourse_donations_currency: "Currency Code" - discourse_donations_hide_zip_code: "Hide Zip Code" - discourse_donations_billing_address: "Collect billing address" - discourse_donations_reward_badge_name: "Grant this badge to user when a payment is successful" - discourse_donations_reward_group_name: "Add the user to this group when a payment is successful" en: donations: payment: diff --git a/config/locales/server.fi.yml b/config/locales/server.fi.yml deleted file mode 100644 index d395ca7..0000000 --- a/config/locales/server.fi.yml +++ /dev/null @@ -1,7 +0,0 @@ -fi: - site_settings: - discourse_donations_enabled: Ota käyttöön lahjoituslisäosa. - discourse_donations_secret_key: Stripen Secret Key -salausavain - discourse_donations_public_key: Stripen Public Key -tunnistusavain - discourse_donations_currency: Valuuttakoodi - discourse_donations_hide_zip_code: Piilota postinumero diff --git a/config/locales/server.it.yml b/config/locales/server.it.yml index 7b92621..059a90b 100644 --- a/config/locales/server.it.yml +++ b/config/locales/server.it.yml @@ -1,13 +1,3 @@ -it: - site_settings: - discourse_donations_enabled: Abilita il plugin per le donazioni. - discourse_donations_enable_create_accounts: "SPERIMENTALE: Permetti agli utenti anonimi la creazione di un account dopo un pagamento effettuato con successo" - 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. - discourse_donations_reward_badge_name: Assegna questo distintivo all'utente quando un pagamento viene effettuato con successo - discourse_donations_reward_group_name: Aggiungi l'utente a questo gruppo quando un pagamento viene effettuato con successo it: donations: payment: diff --git a/config/settings.yml b/config/settings.yml index 71c4724..bc21ebd 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -16,12 +16,12 @@ plugins: default: 'Donation' discourse_donations_shop_name: client: true - default: 'Shop Name' + default: 'Your shop name' discourse_donations_currency: client: true default: 'USD' - discourse_donations_hide_zip_code: - default: true + discourse_donations_zip_code: + default: false client: true discourse_donations_billing_address: default: true diff --git a/plugin.rb b/plugin.rb index 62ab26d..e556726 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,8 +1,8 @@ # name: discourse-donations -# about: Integrating Discourse with Stripe for donations +# about: Integrates Stripe into Discourse to allow forum visitors to make donations # version: 1.11.1 -# url: https://github.com/choiceaustralia/discourse-donations -# authors: Rimian Perkins +# url: https://github.com/chrisbeach/discourse-donations +# authors: Rimian Perkins, Chris Beach gem 'stripe', '2.8.0'