add the current user to a group when the payment is successful
This commit is contained in:
parent
51087d53a3
commit
b2393cb2aa
|
@ -14,11 +14,24 @@ module DiscourseDonations
|
|||
response = {}
|
||||
end
|
||||
|
||||
if reward_user?(payment)
|
||||
reward = DiscourseDonations::Rewards.new(current_user)
|
||||
reward.add_to_group(SiteSetting.discourse_donations_reward_group) if add_to_group?
|
||||
end
|
||||
|
||||
render :json => response
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def reward_user?(payment)
|
||||
payment.present? && payment.successful? && current_user.present?
|
||||
end
|
||||
|
||||
def add_to_group?
|
||||
SiteSetting.discourse_donations_reward_group.present?
|
||||
end
|
||||
|
||||
def secret_key
|
||||
SiteSetting.discourse_donations_secret_key
|
||||
end
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
|
||||
module DiscourseDonations
|
||||
class Rewards
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def add_to_group(name)
|
||||
group = ::Group.find_by_name(name)
|
||||
group.add(@user) if group.present?
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,5 +5,5 @@ en:
|
|||
discourse_donations_public_key: Stripe Public Key
|
||||
discourse_donations_currency: Currency Code
|
||||
discourse_donations_hide_zip_code: Hide Zip Code
|
||||
discourse_donations_grant_badge: Grant this badge to user when a payment is successful
|
||||
discourse_donations_add_to_group: Add the user to this group when a payment is successful
|
||||
discourse_donations_reward_badge: Grant this badge to user when a payment is successful
|
||||
discourse_donations_reward_group: Add the user to this group when a payment is successful
|
||||
|
|
|
@ -15,9 +15,9 @@ plugins:
|
|||
discourse_donations_hide_zip_code:
|
||||
default: true
|
||||
client: true
|
||||
discourse_donations_grant_badge:
|
||||
discourse_donations_reward_badge:
|
||||
client: false
|
||||
default: 'Donation'
|
||||
discourse_donations_add_to_group:
|
||||
discourse_donations_reward_group:
|
||||
client: false
|
||||
default: 'Donation'
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
require 'rails_helper'
|
||||
|
||||
module DiscourseDonations
|
||||
RSpec.describe DiscourseDonations::Rewards do
|
||||
let(:grp) { Fabricate(:group, name: 'w00t') }
|
||||
let(:user) { Fabricate(:user) }
|
||||
subject { described_class.new(user) }
|
||||
|
||||
it 'adds the user to a group' do
|
||||
Group.expects(:find_by_name).with(grp.name).returns(grp)
|
||||
grp.expects(:add).with(user)
|
||||
subject.add_to_group(grp.name)
|
||||
end
|
||||
|
||||
it 'grants the user a badge'
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue