fix client/server messages and locales

zip code should be a positive boolean not negative
remove dollar signs
fix stripe.rb method signature and charging logic
This commit is contained in:
Chris Beach 2017-11-26 12:24:27 +00:00
parent 876edfc0d7
commit df91a44277
13 changed files with 50 additions and 53 deletions

View File

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/chrisbeach/discourse-donations.svg?branch=master)](https://travis-ci.org/choiceaustralia/discourse-donations) [![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 ## 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). 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 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. * **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 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 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 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 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 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. * **4000 0000 0000 0002** Charge is declined with a card_declined code.

View File

@ -7,8 +7,7 @@ module DiscourseDonations
skip_before_action :check_xhr skip_before_action :check_xhr
def create def create
Rails.logger.debug params.inspect Rails.logger.info user_params.inspect
Rails.logger.debug user_params.inspect
output = { 'messages' => [], 'rewards' => [] } output = { 'messages' => [], 'rewards' => [] }
@ -28,10 +27,12 @@ module DiscourseDonations
render(:json => output.merge(success: false)) and return render(:json => output.merge(success: false)) and return
end end
Rails.logger.debug "Creating a Stripe payment"
payment = DiscourseDonations::Stripe.new(secret_key, stripe_options) payment = DiscourseDonations::Stripe.new(secret_key, stripe_options)
begin 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 rescue ::Stripe::CardError => e
err = e.json_body[:error] err = e.json_body[:error]

View File

@ -23,14 +23,14 @@ module DiscourseDonations
charge charge
end end
def charge(email, opts) def charge(email, token, amount)
customer = ::Stripe::Customer.create( customer = ::Stripe::Customer.create(
email: email, email: email,
source: opts[:stripeToken] source: token
) )
@charge = ::Stripe::Charge.create( @charge = ::Stripe::Charge.create(
customer: customer.id, customer: customer.id,
amount: opts[:amount], amount: amount,
description: description, description: description,
currency: currency currency: currency
) )

View File

@ -3,12 +3,12 @@ import { getRegister } from 'discourse-common/lib/get-owner';
export default Ember.Component.extend({ export default Ember.Component.extend({
donateAmounts: [ donateAmounts: [
{ value: 1, name: '$1.00'}, { value: 1, name: '1.00'},
{ value: 2, name: '$2.00'}, { value: 2, name: '2.00'},
{ value: 5, name: '$5.00'}, { value: 5, name: '5.00'},
{ value: 10, name: '$10.00'}, { value: 10, name: '10.00'},
{ value: 20, name: '$20.00'}, { value: 20, name: '20.00'},
{ value: 50, name: '$50.00'} { value: 50, name: '50.00'}
], ],
result: [], result: [],
amount: null, amount: null,
@ -27,7 +27,7 @@ export default Ember.Component.extend({
card: function() { card: function() {
let elements = this.get('stripe').elements(); let elements = this.get('stripe').elements();
return elements.create('card', { return elements.create('card', {
hidePostalCode: this.get('settings').discourse_donations_hide_zip_code hidePostalCode: !this.get('settings').discourse_donations_zip_code
}); });
}.property('stripe'), }.property('stripe'),

View File

@ -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_public_key) { errors.push("missing key (site setting)"); }
if (!siteSettings.discourse_donations_currency) { errors.push("missing currency (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_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 (!siteSettings.discourse_donations_billing_address) { errors.push("missing billing address toggle (site setting)"); }
if (!tagInfo.attrs['amount']) { errors.push("missing amount"); } if (!tagInfo.attrs['amount']) { errors.push("missing amount"); }
if (!content) { errors.push("missing description"); } if (!content) { errors.push("missing description"); }
@ -47,7 +47,7 @@ function insertCheckout(state, tagInfo, content, siteSettings) {
['data-description', content], ['data-description', content],
['data-image', tagInfo.attrs['image'] || ''], ['data-image', tagInfo.attrs['image'] || ''],
['data-locale', 'auto'], ['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-billing-address', siteSettings.discourse_donations_billing_address],
['data-currency', siteSettings.discourse_donations_currency] ['data-currency', siteSettings.discourse_donations_currency]
]; ];

View File

@ -1,4 +1,16 @@
en: 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: js:
discourse_donations: discourse_donations:
title: Donate title: Donate

View File

@ -1,4 +1,9 @@
fi: 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: js:
discourse_donations: discourse_donations:
title: Lahjoita title: Lahjoita

View File

@ -1,4 +1,12 @@
it: 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: js:
discourse_donations: discourse_donations:
title: Donazione title: Donazione

View File

@ -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: en:
donations: donations:
payment: payment:

View File

@ -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

View File

@ -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: it:
donations: donations:
payment: payment:

View File

@ -16,12 +16,12 @@ plugins:
default: 'Donation' default: 'Donation'
discourse_donations_shop_name: discourse_donations_shop_name:
client: true client: true
default: 'Shop Name' default: 'Your shop name'
discourse_donations_currency: discourse_donations_currency:
client: true client: true
default: 'USD' default: 'USD'
discourse_donations_hide_zip_code: discourse_donations_zip_code:
default: true default: false
client: true client: true
discourse_donations_billing_address: discourse_donations_billing_address:
default: true default: true

View File

@ -1,8 +1,8 @@
# name: discourse-donations # 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 # version: 1.11.1
# url: https://github.com/choiceaustralia/discourse-donations # url: https://github.com/chrisbeach/discourse-donations
# authors: Rimian Perkins # authors: Rimian Perkins, Chris Beach
gem 'stripe', '2.8.0' gem 'stripe', '2.8.0'