diff --git a/Changelog.md b/Changelog.md index 2af7e8c0a..58a77411d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,6 +16,7 @@ * Update comment in database example config [#7282](https://github.com/diaspora/diaspora/pull/7282) ## Features +* Add support for [Liberapay](https://liberapay.com) donations [#7290](https://github.com/diaspora/diaspora/pull/7290) # 0.6.3.0 diff --git a/app/assets/images/buttons/liberapay-button.svg b/app/assets/images/buttons/liberapay-button.svg new file mode 100644 index 000000000..995dd029c --- /dev/null +++ b/app/assets/images/buttons/liberapay-button.svg @@ -0,0 +1,10 @@ + + + + + + + + + Donate + diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6fed2b8b6..3a89c597d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -23,6 +23,12 @@ module ApplicationHelper AppConfig.settings.source_url.presence || "#{root_path.chomp('/')}/source.tar.gz" end + def donations_enabled? + AppConfig.settings.paypal_donations.enable? || + AppConfig.settings.liberapay_username.present? || + AppConfig.bitcoin_donation_address.present? + end + def timeago(time, options={}) timeago_tag(time, options.merge(:class => 'timeago', :title => time.iso8601, :force => true)) if time end diff --git a/app/views/shared/_donatepod.html.haml b/app/views/shared/_donatepod.html.haml index 430525e6f..c2d860f92 100644 --- a/app/views/shared/_donatepod.html.haml +++ b/app/views/shared/_donatepod.html.haml @@ -1,15 +1,29 @@ - if AppConfig.settings.paypal_donations.enable? - PayPal: - %form{action: "https://www.paypal.com/cgi-bin/webscr", method: "post", target: "_blank"} - %input{name: "cmd", type: "hidden", value: "_s-xclick"} - - if AppConfig.settings.paypal_donations.paypal_hosted_button_id.present? - %input{name: "hosted_button_id", type: "hidden", value: AppConfig.settings.paypal_donations.paypal_hosted_button_id} - -if AppConfig.settings.paypal_donations.paypal_unhosted_button_encrypted.present? - %input{name: "encrypted", type: "hidden", value: AppConfig.settings.paypal_donations.paypal_unhosted_button_encrypted} - %input{name: "currency_code", type: "hidden", value: AppConfig.settings.paypal_donations.currency} - %input{name: "submit", type: "submit", value: t("aspects.index.donate"), class: "btn btn-default"} + %p + PayPal: + %br + %form{action: "https://www.paypal.com/cgi-bin/webscr", method: "post", target: "_blank"} + %input{name: "cmd", type: "hidden", value: "_s-xclick"} + - if AppConfig.settings.paypal_donations.paypal_hosted_button_id.present? + %input{name: "hosted_button_id", type: "hidden", + value: AppConfig.settings.paypal_donations.paypal_hosted_button_id} + - if AppConfig.settings.paypal_donations.paypal_unhosted_button_encrypted.present? + %input{name: "encrypted", type: "hidden", + value: AppConfig.settings.paypal_donations.paypal_unhosted_button_encrypted} + %input{name: "currency_code", type: "hidden", value: AppConfig.settings.paypal_donations.currency} + %input.btn.btn-default{name: "submit", type: "submit", value: t("aspects.index.donate")} + +- if AppConfig.settings.liberapay_username.present? + %p + Liberapay: + %br + %a{id: "liberapay-button", href: "https://liberapay.com/#{AppConfig.settings.liberapay_username}/donate"} + = image_tag "buttons/liberapay-button.svg", + alt: t("aspects.index.donate"), + title: t("aspects.index.donate_liberapay") - if AppConfig.bitcoin_donation_address - Bitcoin: - %input{type: "text", id: "bitcoin_address", value: AppConfig.bitcoin_donation_address, readonly: true} - + %p + Bitcoin: + %br + %input{type: "text", id: "bitcoin_address", value: AppConfig.bitcoin_donation_address, readonly: true} diff --git a/app/views/streams/main_stream.html.haml b/app/views/streams/main_stream.html.haml index ed210d185..b5130de8c 100644 --- a/app/views/streams/main_stream.html.haml +++ b/app/views/streams/main_stream.html.haml @@ -124,7 +124,7 @@ .content != t("bookmarklet.explanation", link: link_to(t("bookmarklet.post_something"), bookmarklet_code)) - - if AppConfig.settings.paypal_donations.enable? || AppConfig.bitcoin_donation_address + - if donations_enabled? .section.collapsed .title %h5.title-header diff --git a/config/defaults.yml b/config/defaults.yml index 7abc2d4b4..c7afac76c 100644 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -105,6 +105,7 @@ defaults: currency: USD paypal_hosted_button_id: paypal_unhosted_button_encrypted: + liberapay_username: bitcoin_address: bitcoin_wallet_id: # DEPRECATED: Remove with 0.6 community_spotlight: diff --git a/config/diaspora.yml.example b/config/diaspora.yml.example index d4f0622e5..833f36bb0 100644 --- a/config/diaspora.yml.example +++ b/config/diaspora.yml.example @@ -430,6 +430,10 @@ configuration: ## Section ## OR encrypted key of unhosted button #paypal_unhosted_button_encrypted: "-----BEGIN PKCS7-----" + ## Liberapay.com is a free platform which allow donations like patreon + ## Set your username to include your liberapay button + # liberapay_username: "change_me" + ## Bitcoin donations ## You can provide a bitcoin address here to allow your users to provide ## donations towards the running of their pod. diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index f4e844f58..f280e4c69 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -194,6 +194,7 @@ en: index: donate: "Donate" keep_pod_running: "Keep %{pod} running fast and buy servers their coffee fix with a monthly donation!" + donate_liberapay: "Donate to liberapay" welcome_to_diaspora: "Welcome to diaspora*, %{name}!" introduce_yourself: "This is your stream. Jump in and introduce yourself." diff --git a/features/desktop/donations.feature b/features/desktop/donations.feature index 0985ff132..8ef798acb 100644 --- a/features/desktop/donations.feature +++ b/features/desktop/donations.feature @@ -16,3 +16,10 @@ Feature: donations Then I should see "Donate" within ".info-bar" And I click on "Donate" navbar title Then I should see the Bitcoin address + + Scenario: Liberapay donations + Given I have configured a Liberapay username + And I go to the home page + Then I should see "Donate" within ".info-bar" + And I click on "Donate" navbar title + Then I should see the Liberapay donate button diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index be4e29555..f15a8dd68 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -288,6 +288,14 @@ Then /^I should see the Bitcoin address$/ do find("#bitcoin_address")['value'].should == "AAAAAA" end +Given /^I have configured a Liberapay username$/ do + AppConfig.settings.liberapay_username = "BBBBBB" +end + +Then /^I should see the Liberapay donate button$/ do + find("#liberapay-button")["href"].should == "https://liberapay.com/BBBBBB/donate" +end + Given /^"([^"]*)" is hidden$/ do |selector| page.should have_selector(selector, visible: false) page.should_not have_selector(selector) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 84bc7cc35..8a277d41a 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -68,6 +68,34 @@ describe ApplicationHelper, :type => :helper do end end + describe "#donations_enabled?" do + it "returns false when nothing is set" do + expect(helper.donations_enabled?).to be false + end + + it "returns true when the paypal donations is enabled" do + AppConfig.settings.paypal_donations.enable = true + expect(helper.donations_enabled?).to be true + end + + it "returns true when the liberapay username is set" do + AppConfig.settings.liberapay_username = "foo" + expect(helper.donations_enabled?).to be true + end + + it "returns true when the bitcoin_address is set" do + AppConfig.settings.bitcoin_address = "bar" + expect(helper.donations_enabled?).to be true + end + + it "returns true when all the donations are enabled" do + AppConfig.settings.paypal_donations.enable = true + AppConfig.settings.liberapay_username = "foo" + AppConfig.settings.bitcoin_address = "bar" + expect(helper.donations_enabled?).to be true + end + end + describe "#changelog_url" do let(:changelog_url_setting) { double.tap {|double| allow(AppConfig).to receive(:settings).and_return(double(changelog_url: double)) }