Skip to content

Commit

Permalink
Merge branch 'kaigionrails' into kaigionrails2024
Browse files Browse the repository at this point in the history
  • Loading branch information
unasuke committed Jul 16, 2024
2 parents ec107a7 + 8e02f53 commit 762b1dd
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
73 changes: 73 additions & 0 deletions app/jobs/ensure_sponsorship_tito_discount_code_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
class EnsureSponsorshipTitoDiscountCodeJob < ApplicationJob
def perform(sponsorship, kind, ignore_quantity: false)
return unless Rails.application.config.x.tito.token
@kind = kind
@sponsorship = sponsorship
@conference = @sponsorship.conference
return unless @conference.tito_slug.present?

@discount_code = @sponsorship.tito_discount_codes.where(kind: kind).first

if @discount_code
return if @discount_code.quantity == quantity && !ignore_quantity
tito.update_discount_code(@conference.tito_slug, @discount_code.tito_discount_code_id, **discount_code_attributes)
@discount_code.update!(quantity: quantity)
else
return if quantity < 1
tito_discount_code = tito.create_discount_code(@conference.tito_slug, **discount_code_attributes)
TitoDiscountCode.create!(
sponsorship: @sponsorship,
kind: @kind,
code: code,
quantity: quantity,
tito_discount_code_id: tito_discount_code.fetch(:discount_code).fetch(:id),
)
end
end

def code
"#{code_prefix}_#{@sponsorship.id}_#{@sponsorship.ticket_key[0,12]}"
end

def discount_code_attributes
{
code: code,
type: 'PercentOffDiscountCode',
value: '100.0',
only_show_attached: true,
reveal_secret: true,
quantity: quantity,
release_ids: quantity > 0 ? [release_id] : nil,
description_for_organizer: "sponsorship=#{@sponsorship.id}, domain=#{@sponsorship.organization&.domain}, plan=#{@sponsorship.plan&.name}",
}
end

def quantity
{
'attendee' => @sponsorship.total_number_of_attendees,
'booth_staff' => @sponsorship.total_number_of_booth_staff,
}.fetch(@kind)
end

def code_prefix
{
'attendee' => 'sa',
'booth_staff' => 'sb',
}.fetch(@kind)
end

def release_slug
{
'attendee' => 'sponsor',
'booth_staff' => 'booth-staff',
}.fetch(@kind)
end

def release_id
@release_id ||= tito.get_release(@conference.tito_slug, release_slug).fetch(:release).fetch(:id)
end

def tito
@tito ||= TitoApi.new
end
end
3 changes: 3 additions & 0 deletions app/jobs/process_sponsorship_edit_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ def perform(edit)
)

# GenerateSponsorsYamlFileJob.perform_now(@conference)

# EnsureSponsorshipTitoDiscountCodeJob.perform_now(@sponsorship, 'attendee')
# EnsureSponsorshipTitoDiscountCodeJob.perform_now(@sponsorship, 'booth_staff')
end
end
2 changes: 2 additions & 0 deletions app/jobs/sponsorship_welcome_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ def perform(sponsorship)
SlackWebhookJob.perform_now(
{ text: ":tamago: *New sponsorship* (#{sponsorship.plan_name || '*OTHER*'}): #{sponsorship.name} <#{conference_sponsorship_url(sponsorship.conference, sponsorship)}|Open>" },
)

# EnsureSponsorshipTitoDiscountCodeJob.perform_later(sponsorship, 'attendee')
end
end
2 changes: 2 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@

config.x.mailgun.api_key = ENV['MAILGUN_API_KEY']
config.x.sentry.dsn = ENV['SENTRY_DSN']

config.x.tito.token = ENV['TITO_API_TOKEN']
end
2 changes: 2 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
config.x.github.app_id = ENV.fetch('GITHUB_APP_ID')
config.x.github.private_key = OpenSSL::PKey::RSA.new(ENV.fetch('GITHUB_CLIENT_PRIVATE_KEY').unpack1('m*'), '')

config.x.tito.token = ENV.fetch('TITO_API_TOKEN')

config.x.slack.webhook_urls = {
default: ENV.fetch('SLACK_WEBHOOK_URL'),
feed: ENV.fetch('SLACK_WEBHOOK_URL_FOR_FEED', ENV.fetch('SLACK_WEBHOOK_URL')),
Expand Down

0 comments on commit 762b1dd

Please sign in to comment.