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)
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.

View File

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

View File

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

View File

@ -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'),

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_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]
];

View File

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

View File

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

View File

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

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

View File

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

View File

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