forked from svsticky/constipated-koala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook_controller.rb
43 lines (31 loc) · 1.35 KB
/
webhook_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#:nodoc:
class Api::WebhookController < ApiController
def payment_redirect
transaction = Payment.find_by!(token: params[:token])
transaction.finalize! if transaction.update_transaction!
flash[:notice] = transaction.message if transaction.successful? || transaction.in_progress?
logger.debug(transaction.message.inspect)
flash[:warning] = transaction.message if transaction.failed?
redirect_to(transaction.redirect_uri)
end
def mollie_hook
transaction = Payment.find_by!(trxid: params[:id])
transaction.finalize! if transaction.update_transaction!
head(:ok)
end
# send ok status to convince mailchimp everything works
def mailchimp_confirm_callback
head(:unauthorized) && return unless params[:token] == ENV['MAILCHIMP_SECRET']
head(:ok)
end
# invalidate cache on mailchimp change
def mailchimp
head(:unauthorized) && return unless params[:token] == ENV['MAILCHIMP_SECRET']
head(:precondition_failed) && return unless params[:data][:list_id] == ENV['MAILCHIMP_LIST_ID']
head(:method_not_allowed) && return unless ['subscribe', 'unsubscribe', 'profile',
'cleaned'].include?(params[:type])
member = Member.find_by!(email: params[:data][:email])
Rails.cache.delete("members/#{ member.id }/mailchimp/interests")
head(:no_content)
end
end