repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/handle_paypal_event_worker.rb
app/sidekiq/handle_paypal_event_worker.rb
# frozen_string_literal: true class HandlePaypalEventWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :default def perform(paypal_event) PaypalEventHandler.new(paypal_event).handle_paypal_event end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/create_india_sales_report_job.rb
app/sidekiq/create_india_sales_report_job.rb
# frozen_string_literal: true class CreateIndiaSalesReportJob include Sidekiq::Job sidekiq_options retry: 1, queue: :default, lock: :until_executed, on_conflict: :replace VALID_INDIAN_STATES = %w[ AP AR AS BR CG GA GJ HR HP JK JH KA KL MP MH MN ML MZ NL OR PB RJ SK TN TR UK UP WB AN CH DH DD DL LD PY ].to_set.freeze def perform(month = nil, year = nil) if month.nil? || year.nil? previous_month = 1.month.ago month ||= previous_month.month year ||= previous_month.year end raise ArgumentError, "Invalid month" unless month.in?(1..12) raise ArgumentError, "Invalid year" unless year.in?(2014..3200) s3_filename = "india-sales-report-#{year}-#{month.to_s.rjust(2, '0')}-#{SecureRandom.hex(4)}.csv" s3_report_key = "sales-tax/in-sales-monthly/#{s3_filename}" begin temp_file = Tempfile.new temp_file.write(row_headers.to_csv) start_date = Date.new(year, month).beginning_of_month.beginning_of_day end_date = Date.new(year, month).end_of_month.end_of_day india_tax_rate = ZipTaxRate.where(country: "IN", state: nil, user_id: nil).alive.last.combined_rate india_tax_rate_percentage = (india_tax_rate * 100).to_i timeout_seconds = ($redis.get("create_india_sales_report_job_max_execution_time_seconds") || 1.hour).to_i WithMaxExecutionTime.timeout_queries(seconds: timeout_seconds) do Purchase.joins("LEFT JOIN purchase_sales_tax_infos ON purchases.id = purchase_sales_tax_infos.purchase_id") .where("purchase_state != 'failed'") .where.not(stripe_transaction_id: nil) .where(created_at: start_date..end_date) .where("(country = 'India') OR (country IS NULL AND ip_country = 'India') OR (card_country = 'IN')") .where("price_cents > 0") .where("purchase_sales_tax_infos.business_vat_id IS NULL OR purchase_sales_tax_infos.business_vat_id = ''") .find_each do |purchase| next if purchase.chargeback_date.present? && !purchase.chargeback_reversed? next if purchase.stripe_refunded == true price_cents = purchase.price_cents tax_amount_cents = purchase.gumroad_tax_cents || 0 raw_state = (purchase.ip_state || "").strip.upcase display_state = if raw_state.match?(/^\d+$/) || !VALID_INDIAN_STATES.include?(raw_state) "" else raw_state end expected_tax_rounded = (price_cents * india_tax_rate).round expected_tax_floored = (price_cents * india_tax_rate).floor diff_rounded = expected_tax_rounded - tax_amount_cents diff_floored = expected_tax_floored - tax_amount_cents calc_tax_rate = if price_cents > 0 && tax_amount_cents > 0 (BigDecimal(tax_amount_cents.to_s) / BigDecimal(price_cents.to_s) * 100).round(4).to_f else 0 end row = [ purchase.external_id, purchase.created_at.strftime("%Y-%m-%d"), display_state, india_tax_rate_percentage, price_cents, tax_amount_cents, calc_tax_rate, expected_tax_rounded, expected_tax_floored, diff_rounded, diff_floored ] temp_file.write(row.to_csv) temp_file.flush end end temp_file.rewind s3_object = Aws::S3::Resource.new.bucket(REPORTING_S3_BUCKET).object(s3_report_key) s3_object.upload_file(temp_file) s3_signed_url = s3_object.presigned_url(:get, expires_in: 1.week.to_i).to_s SlackMessageWorker.perform_async("payments", "India Sales Reporting", "India #{year}-#{month.to_s.rjust(2, '0')} sales report is ready - #{s3_signed_url}", "green") ensure temp_file.close end end private def row_headers [ "ID", "Date", "Place of Supply (State)", "Zip Tax Rate (%) (Rate from Database)", "Taxable Value (cents)", "Integrated Tax Amount (cents)", "Tax Rate (%) (Calculated From Tax Collected)", "Expected Tax (cents, rounded)", "Expected Tax (cents, floored)", "Tax Difference (rounded)", "Tax Difference (floored)" ] end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/send_memberships_price_update_emails_job.rb
app/sidekiq/send_memberships_price_update_emails_job.rb
# frozen_string_literal: true class SendMembershipsPriceUpdateEmailsJob include Sidekiq::Job sidekiq_options retry: 5, queue: :low def perform SubscriptionPlanChange.includes(:subscription) .applicable_for_product_price_change_as_of(7.days.from_now.to_date) .where(notified_subscriber_at: nil) .find_each do |subscription_plan_change| subscription = subscription_plan_change.subscription next if !subscription.alive? || subscription.pending_cancellation? subscription_plan_change.update!(notified_subscriber_at: Time.current) CustomerLowPriorityMailer.subscription_price_change_notification( subscription_id: subscription.id, new_price: subscription_plan_change.perceived_price_cents, ).deliver_later(queue: "low") end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/refund_unpaid_purchases_worker.rb
app/sidekiq/refund_unpaid_purchases_worker.rb
# frozen_string_literal: true class RefundUnpaidPurchasesWorker include Sidekiq::Job sidekiq_options retry: 1, queue: :default def perform(user_id, admin_user_id) user = User.find(user_id) return unless user.suspended? unpaid_balance_ids = user.balances.unpaid.ids user.sales.where(purchase_success_balance_id: unpaid_balance_ids).successful.not_fully_refunded.ids.each do |purchase_id| RefundPurchaseWorker.perform_async(purchase_id, admin_user_id) end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/slack_message_worker.rb
app/sidekiq/slack_message_worker.rb
# frozen_string_literal: true class SlackMessageWorker include Sidekiq::Job sidekiq_options retry: 9, queue: :default SLACK_MESSAGE_SEND_TIMEOUT = 5.seconds SLACK_WEBHOOK_URL = GlobalConfig.get("SLACK_WEBHOOK_URL") ## # Creates a Slack message in a given channel # # All messages from development or staging will appear in the 'test' channel # # Throws an error in order for Sidekiq to retry. Throws a SlackError so we # can ignore it for bug reporting # # Examples # # SlackMessageWorker.perform_async("announcements", "Example Service", "This is an example message") # # Options supports the key 'attachments': # Provide an array of hashes for attachments. See for more information about how # to format the hash for an attachment: https://api.slack.com/docs/attachments def perform(room_name, sender, message_text, color = "gray", options = {}) room_name = "test" unless Rails.env.production? chat_room = CHAT_ROOMS[room_name.to_sym][:slack] return if chat_room.nil? hex_color = Color::CSS[color].html Timeout.timeout(SLACK_MESSAGE_SEND_TIMEOUT) do client = Slack::Notifier.new SLACK_WEBHOOK_URL do defaults channel: "##{chat_room[:channel]}", username: sender end extra_attachments = (options["attachments"].nil? ? [] : options["attachments"]) client.ping("", attachments: [{ fallback: message_text, color: hex_color, text: message_text }] + extra_attachments) end rescue StandardError, Timeout::Error => e unless e.message.include? "rate_limited" raise SlackError, e.message end end end class SlackError < StandardError end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/stripe_create_merchant_accounts_worker.rb
app/sidekiq/stripe_create_merchant_accounts_worker.rb
# frozen_string_literal: true class StripeCreateMerchantAccountsWorker include Sidekiq::Job sidekiq_options retry: 1, queue: :default PERIOD_INDICATING_USER_IS_ACTIVE = 3.months private_constant :PERIOD_INDICATING_USER_IS_ACTIVE def perform # Create Stripe accounts for users that have user compliance info, in the countries above, and who have bank accounts and have agreed to the TOS. # Will not create accounts if a user has a merchant account that's been marked as deleted, because we don't want users to have # many Stripe accounts and there's probably a good reason we've taken them off Stripe Connect. sql = <<~SQL WITH cte AS ( SELECT * FROM users WHERE users.user_risk_state IN ("compliant", "not_reviewed") ) SELECT distinct(cte.id) FROM cte INNER JOIN user_compliance_info ON user_compliance_info.user_id = cte.id AND user_compliance_info.deleted_at IS NULL INNER JOIN bank_accounts ON bank_accounts.user_id = cte.id AND bank_accounts.deleted_at IS NULL INNER JOIN tos_agreements ON tos_agreements.user_id = cte.id INNER JOIN balances ON balances.user_id = cte.id AND balances.created_at > "#{PERIOD_INDICATING_USER_IS_ACTIVE.ago.to_formatted_s(:db)}" LEFT JOIN merchant_accounts ON merchant_accounts.user_id = cte.id WHERE merchant_accounts.id IS NULL SQL user_ids = ApplicationRecord.connection.execute(sql).to_a.flatten User.where(id: user_ids).each do |user| next unless user.native_payouts_supported? CreateStripeMerchantAccountWorker.perform_async(user.id) end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/cache_product_data_worker.rb
app/sidekiq/cache_product_data_worker.rb
# frozen_string_literal: true class CacheProductDataWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :low, lock: :until_executed def perform(product_id) product = Link.find(product_id) product.invalidate_cache product.product_cached_values.create! end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/check_purchase_heuristics_worker.rb
app/sidekiq/check_purchase_heuristics_worker.rb
# frozen_string_literal: true class CheckPurchaseHeuristicsWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :default def perform(purchase_id) return unless Rails.env.production? sqs = Aws::SQS::Client.new queue_url = sqs.get_queue_url(queue_name: "risk_queue").queue_url sqs.send_message(queue_url:, message_body: { "type" => "purchase", "id" => purchase_id }.to_s) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/delete_expired_product_cached_values_worker.rb
app/sidekiq/delete_expired_product_cached_values_worker.rb
# frozen_string_literal: true class DeleteExpiredProductCachedValuesWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :low QUERY_BATCH_SIZE = 200 DELETION_BATCH_SIZE = 100 # Deletes all rows, except the latest one per product. # While still present in the queries for performance, the `expired` status is effectively ignored. def perform ProductCachedValue.expired.group(:product_id).in_batches(of: QUERY_BATCH_SIZE) do |relation| product_ids = relation.select(:product_id).distinct.map(&:product_id) kept_max_ids = ProductCachedValue.where(product_id: product_ids).group(:product_id).maximum(:id).values loop do ReplicaLagWatcher.watch rows = ProductCachedValue.expired.where(product_id: product_ids).where.not(id: kept_max_ids).limit(DELETION_BATCH_SIZE) deleted_rows = rows.delete_all break if deleted_rows < DELETION_BATCH_SIZE end end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/charge_successful_preorders_worker.rb
app/sidekiq/charge_successful_preorders_worker.rb
# frozen_string_literal: true class ChargeSuccessfulPreordersWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :default def perform(preorder_link_id) preorder_link = PreorderLink.find_by(id: preorder_link_id) preorder_link.preorders.authorization_successful.each do |preorder| ChargePreorderWorker.perform_async(preorder.id) end if preorder_link.preorders.authorization_successful.present? SendPreorderSellerSummaryWorker.perform_in(20.minutes, preorder_link_id) end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/sync_stuck_purchases_job.rb
app/sidekiq/sync_stuck_purchases_job.rb
# frozen_string_literal: true class SyncStuckPurchasesJob include Sidekiq::Job sidekiq_options retry: 1, queue: :default, lock: :until_executed def perform purchase_creation_time_range = Range.new(3.days.ago, 4.hours.ago) Purchase.in_progress.created_between(purchase_creation_time_range).each do |purchase| next unless purchase.can_force_update? purchase.sync_status_with_charge_processor(mark_as_failed: true) next unless purchase.successful? if Purchase.successful .not_fully_refunded .not_chargedback_or_chargedback_reversed .where(link: purchase.link, email: purchase.email) .where("created_at > ?", purchase.created_at) .any? { |subsequent_purchase| subsequent_purchase.variant_attributes.pluck(:id).sort == purchase.variant_attributes.pluck(:id).sort } success = purchase.refund_and_save!(GUMROAD_ADMIN_ID) unless success Rails.logger.warn("SyncStuckPurchasesJob: Did not refund purchase with ID #{purchase.id}") end end end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/expire_rental_purchases_worker.rb
app/sidekiq/expire_rental_purchases_worker.rb
# frozen_string_literal: true class ExpireRentalPurchasesWorker include Sidekiq::Job sidekiq_options retry: 0, queue: :default def perform Purchase.rentals_to_expire.find_each do |purchase| purchase.rental_expired = true purchase.save! end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/handle_new_bank_account_worker.rb
app/sidekiq/handle_new_bank_account_worker.rb
# frozen_string_literal: true class HandleNewBankAccountWorker include Sidekiq::Job sidekiq_options retry: 10, queue: :default def perform(bank_account_id) bank_account = BankAccount.find(bank_account_id) StripeMerchantAccountManager.handle_new_bank_account(bank_account) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/send_preorder_seller_summary_worker.rb
app/sidekiq/send_preorder_seller_summary_worker.rb
# frozen_string_literal: true class SendPreorderSellerSummaryWorker include Sidekiq::Job sidekiq_options retry: 1, queue: :low MAX_ATTEMPTS_TO_WAIT_FOR_ALL_CHARGED = 72 # roughly 24h, but could be longer if the queue is backed up WAIT_PERIOD = 20.minutes def perform(preorder_link_id, attempts = 0) if attempts >= MAX_ATTEMPTS_TO_WAIT_FOR_ALL_CHARGED notify_bugsnag_and_raise "Timed out waiting for all preorders to be charged. PreorderLink: #{preorder_link_id}." end preorder_link = PreorderLink.find(preorder_link_id) preorders = preorder_link.preorders.authorization_successful are_all_preorders_charged = preorders.joins(:purchases).merge(Purchase.not_in_progress) .group("preorders.id").having("count(*) = 1").count("preorders.id") .empty? if are_all_preorders_charged ContactingCreatorMailer.preorder_summary(preorder_link_id).deliver_later(queue: "critical") else # We're not done charging the cards. Try again later. SendPreorderSellerSummaryWorker.perform_in(WAIT_PERIOD, preorder_link_id, attempts + 1) end end private def notify_bugsnag_and_raise(error_message) Bugsnag.notify(error_message) raise error_message end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/build_tax_rate_cache_worker.rb
app/sidekiq/build_tax_rate_cache_worker.rb
# frozen_string_literal: true class BuildTaxRateCacheWorker include Sidekiq::Job sidekiq_options retry: 1, queue: :default def perform us_tax_cache_namespace = Redis::Namespace.new(:max_tax_rate_per_state_cache_us, redis: $redis) ZipTaxRate.where("state is NOT NULL").group(:state).maximum(:combined_rate).each do |state_and_max_rate| state_with_prefix = "US_" + state_and_max_rate[0] us_tax_cache_namespace.set(state_with_prefix, state_and_max_rate[1]) end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/send_paypal_topup_notification_job.rb
app/sidekiq/send_paypal_topup_notification_job.rb
# frozen_string_literal: true class SendPaypalTopupNotificationJob include Sidekiq::Job include CurrencyHelper sidekiq_options retry: 1, queue: :default, lock: :until_executed, on_conflict: :replace def perform(notify_only_if_topup_needed = false) return unless Rails.env.production? payout_amount_cents = Balance .unpaid .where(user_id: Payment .where("created_at > ?", 1.month.ago) .where(processor: "paypal") .select(:user_id)) .where("date <= ?", User::PayoutSchedule.next_scheduled_payout_date) .sum(:amount_cents) current_balance_cents = PaypalPayoutProcessor.current_paypal_balance_cents topup_amount_in_transit_cents = PaypalPayoutProcessor.topup_amount_in_transit * 100 topup_amount_cents = payout_amount_cents - current_balance_cents - topup_amount_in_transit_cents topup_needed = topup_amount_cents > 0 return if notify_only_if_topup_needed && !topup_needed notification_msg = "PayPal balance needs to be #{formatted_dollar_amount(payout_amount_cents)} by Friday to payout all creators.\n"\ "Current PayPal balance is #{formatted_dollar_amount(current_balance_cents)}.\n" notification_msg += "Top-up amount in transit is #{formatted_dollar_amount(topup_amount_in_transit_cents)}.\n" if topup_amount_in_transit_cents > 0 notification_msg += if topup_needed "A top-up of #{formatted_dollar_amount(topup_amount_cents)} is needed." else "No more top-up required." end SlackMessageWorker.perform_async("payments", "PayPal Top-up", notification_msg, topup_needed ? "red" : "green") end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/block_stripe_suspected_fraudulent_payments_worker.rb
app/sidekiq/block_stripe_suspected_fraudulent_payments_worker.rb
# frozen_string_literal: true class BlockStripeSuspectedFraudulentPaymentsWorker include Sidekiq::Job sidekiq_options retry: 3, queue: :low TRAILING_DAYS = 90 STRIPE_EMAIL_SENDER = "notifications@stripe.com" HELPER_NOTE_CONTENT = "Done with code" POSSIBLE_CONVERSATION_SUBJECTS = [ "Suspected fraudulent payments on your Stripe account", "Suspected fraudulent payment on your Stripe account", ] def perform(conversation_id, email_from, body) return unless email_from == STRIPE_EMAIL_SENDER records = parse_payment_records_from_body(body) return if records.empty? handle_suspected_fraudulent_payments(records) helper.add_note(conversation_id:, message: HELPER_NOTE_CONTENT) helper.close_conversation(conversation_id:) end private def helper @helper ||= Helper::Client.new end def handle_suspected_fraudulent_payments(records) records.each do |transaction_id| Purchase.created_after(TRAILING_DAYS.days.ago) .not_fully_refunded .not_chargedback .where(stripe_transaction_id: transaction_id) .each do |purchase| purchase.refund_for_fraud!(GUMROAD_ADMIN_ID) next if purchase.buyer_blocked? comment_content = "Buyer blocked by Helper webhook" purchase.block_buyer!(blocking_user_id: GUMROAD_ADMIN_ID, comment_content:) end end end def parse_payment_records_from_body(body) body.scan(/>(ch_[a-zA-Z\d]{8,})<\/a>/).flatten rescue StandardError => error Bugsnag.notify error [] end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/schedule_abandoned_cart_emails_job.rb
app/sidekiq/schedule_abandoned_cart_emails_job.rb
# frozen_string_literal: true class ScheduleAbandonedCartEmailsJob include Sidekiq::Job BATCH_SIZE = 500 sidekiq_options queue: :low, retry: 5, lock: :until_executed def perform # cart_product_ids_with_cart_ids is a hash of { product_id => { cart_id => [variant_ids] } } cart_product_ids_with_cart_ids = {} days_to_process = (Cart::ABANDONED_IF_UPDATED_AFTER_AGO.to_i / 1.day.to_i) (1..days_to_process).each do |day| day_start = day.days.ago.beginning_of_day day_end = day == 1 ? Cart::ABANDONED_IF_UPDATED_BEFORE_AGO.ago : (day - 1).days.ago.beginning_of_day start_time = Time.current cart_ids = Cart.abandoned(updated_at: day_start..day_end).pluck(:id) cart_ids.each_slice(BATCH_SIZE) do |batch_ids| Cart.includes(:alive_cart_products).where(id: batch_ids).each do |cart| next if cart.user_id.blank? && cart.email.blank? cart.alive_cart_products.each do |cart_product| product_id = cart_product.product_id variant_id = cart_product.option_id cart_product_ids_with_cart_ids[product_id] ||= {} cart_product_ids_with_cart_ids[product_id][cart.id] ||= [] cart_product_ids_with_cart_ids[product_id][cart.id] << variant_id if variant_id.present? end end end Rails.logger.info "Fetched #{cart_ids.count} carts for #{day_start} to #{day_end} in #{(Time.current - start_time).round(2)} seconds" end # cart_ids_with_matched_workflow_ids_and_product_ids is a hash of { cart_id => { workflow_id => [product_ids] } } cart_ids_with_matched_workflow_ids_and_product_ids = {} start_time = Time.current Workflow.distinct.alive.abandoned_cart_type.published.joins(seller: :links).merge(User.alive.not_suspended).merge(Link.visible_and_not_archived).includes(:seller).find_each do |workflow| next unless workflow.seller&.eligible_for_abandoned_cart_workflows? workflow.abandoned_cart_products(only_product_and_variant_ids: true).each do |product_id, variant_ids| next unless cart_product_ids_with_cart_ids.key?(product_id) cart_product_ids_with_cart_ids[product_id].each do |cart_id, cart_variant_ids| has_matching_variants = variant_ids.empty? || (variant_ids & cart_variant_ids).any? next unless has_matching_variants cart_ids_with_matched_workflow_ids_and_product_ids[cart_id] ||= {} cart_ids_with_matched_workflow_ids_and_product_ids[cart_id][workflow.id] ||= [] cart_ids_with_matched_workflow_ids_and_product_ids[cart_id][workflow.id] << product_id end end end Rails.logger.info "Fetched #{cart_ids_with_matched_workflow_ids_and_product_ids.count} cart ids with matched workflow ids and product ids in #{(Time.current - start_time).round(2)} seconds" cart_ids_with_matched_workflow_ids_and_product_ids.each do |cart_id, workflow_ids_with_product_ids| CustomerMailer.abandoned_cart(cart_id, workflow_ids_with_product_ids.stringify_keys).deliver_later(queue: "low") end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/recover_aus_backtax_from_stripe_account_job.rb
app/sidekiq/recover_aus_backtax_from_stripe_account_job.rb
# frozen_string_literal: true class RecoverAusBacktaxFromStripeAccountJob include Sidekiq::Job sidekiq_options retry: 5, queue: :default def perform(creator_id) creator = User.find_by_id(creator_id) return unless creator.present? australia_backtax_agreement = creator.australia_backtax_agreement return unless australia_backtax_agreement.present? return if australia_backtax_agreement.collected? credit = australia_backtax_agreement.credit return unless credit.present? StripeChargeProcessor.debit_stripe_account_for_australia_backtaxes(credit:) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/check_payment_address_worker.rb
app/sidekiq/check_payment_address_worker.rb
# frozen_string_literal: true class CheckPaymentAddressWorker include Sidekiq::Job sidekiq_options retry: 0, queue: :default def perform(user_id) user = User.find_by(id: user_id) return if !user.can_flag_for_fraud? || user.payment_address.blank? banned_accounts_with_same_payment_address = User.where( payment_address: user.payment_address, user_risk_state: ["suspended_for_tos_violation", "suspended_for_fraud"] ) blocked_email = BlockedObject.find_active_object(user.payment_address) user.flag_for_fraud!(author_name: "CheckPaymentAddress") if banned_accounts_with_same_payment_address.exists? || blocked_email.present? end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/update_installment_events_count_cache_worker.rb
app/sidekiq/update_installment_events_count_cache_worker.rb
# frozen_string_literal: true class UpdateInstallmentEventsCountCacheWorker include Sidekiq::Job sidekiq_options retry: 1, queue: :low, lock: :until_executed def perform(installment_id) installment = Installment.find(installment_id) total = installment.installment_events.count # This is a hot-fix for https://gumroad.slack.com/archives/C5Z7LG6Q1/p1583131085132100 # TODO: Remove the hot-fix and skip validation selectively. installment.update_column(:installment_events_count, total) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/generate_sales_report_job.rb
app/sidekiq/generate_sales_report_job.rb
# frozen_string_literal: true class GenerateSalesReportJob include Sidekiq::Job sidekiq_options retry: 1, queue: :default, lock: :until_executed, on_conflict: :replace ALL_SALES = "all_sales" DISCOVER_SALES = "discover_sales" SALES_TYPES = [ALL_SALES, DISCOVER_SALES] def perform(country_code, start_date, end_date, sales_type, send_slack_notification = true, s3_prefix = nil) country = ISO3166::Country[country_code].tap { |value| raise ArgumentError, "Invalid country code" unless value } raise ArgumentError, "Invalid sales type" unless SALES_TYPES.include?(sales_type) start_time = Date.parse(start_date.to_s).beginning_of_day end_time = Date.parse(end_date.to_s).end_of_day begin temp_file = Tempfile.new temp_file.write(row_headers(country_code).to_csv) timeout_seconds = ($redis.get(RedisKey.generate_sales_report_job_max_execution_time_seconds) || 1.hour).to_i WithMaxExecutionTime.timeout_queries(seconds: timeout_seconds) do sales = Purchase.successful .not_fully_refunded .not_chargedback_or_chargedback_reversed .where.not(stripe_transaction_id: nil) .where("purchases.created_at BETWEEN ? AND ?", start_time, end_time) .where("(country = ?) OR ((country IS NULL OR country = ?) AND ip_country = ?)", country.common_name, country.common_name, country.common_name) sales = sales.where("purchases.flags & ? > 0", Purchase.flag_mapping["flags"][:was_product_recommended]) if sales_type == DISCOVER_SALES sales.find_each do |purchase| row = [purchase.created_at, purchase.external_id, purchase.seller.external_id, purchase.seller.form_email&.gsub(/.{0,4}@/, '####@'), purchase.seller.user_compliance_infos.last&.legal_entity_country, purchase.email&.gsub(/.{0,4}@/, '####@'), purchase.card_visual&.gsub(/.{0,4}@/, '####@'), purchase.price_cents_net_of_refunds, purchase.fee_cents_net_of_refunds, purchase.gumroad_tax_cents_net_of_refunds, purchase.shipping_cents, purchase.total_cents_net_of_refunds] if %w(AU SG).include?(country_code) row += [purchase.link.is_physical? ? "DTC" : "BS", purchase.zip_tax_rate_id, purchase.purchase_sales_tax_info.business_vat_id] end # Do not include free recommendations like library and more-like-this in the discover sales report # because we don't charge our discover/marketplace fee in those cases. next if sales_type == DISCOVER_SALES && RecommendationType.is_free_recommendation_type?(purchase.recommended_by) temp_file.write(row.to_csv) temp_file.flush end end temp_file.rewind s3_filename = "#{country.common_name.downcase.tr(' ', '-')}-#{sales_type.tr("_", "-")}-report-#{start_time.to_date}-to-#{end_time.to_date}-#{SecureRandom.hex(4)}.csv" s3_path = s3_prefix.present? ? "#{s3_prefix.chomp('/')}/sales-tax/#{country.alpha2.downcase}-sales-quarterly" : "sales-tax/#{country.alpha2.downcase}-sales-quarterly" s3_signed_url = ExpiringS3FileService.new( file: temp_file, filename: s3_filename, path: s3_path, expiry: 1.week, bucket: REPORTING_S3_BUCKET ).perform update_job_status_to_completed(country_code, start_time, end_time, sales_type, s3_signed_url) if send_slack_notification message = "#{country.common_name} sales report (#{start_time.to_date} to #{end_time.to_date}) is ready - #{s3_signed_url}" SlackMessageWorker.perform_async("payments", slack_sender(country_code), message, "green") end ensure temp_file.close end end private def row_headers(country_code) headers = ["Sale time", "Sale ID", "Seller ID", "Seller Email", "Seller Country", "Buyer Email", "Buyer Card", "Price", "Gumroad Fee", "GST", "Shipping", "Total"] if country_code == "AU" headers += ["Direct-To-Customer / Buy-Sell", "Zip Tax Rate ID", "Customer ABN Number"] elsif country_code == "SG" headers += ["Direct-To-Customer / Buy-Sell", "Zip Tax Rate ID", "Customer GST Number"] end headers end def slack_sender(country_code) if %w(AU SG).include?(country_code) "GST Reporting" else "VAT Reporting" end end def update_job_status_to_completed(country_code, start_time, end_time, sales_type, download_url) job_data = $redis.lrange(RedisKey.sales_report_jobs, 0, 19) job_data.each_with_index do |data, index| job = JSON.parse(data) if job["country_code"] == country_code && job["start_date"] == start_time.to_date.to_s && job["end_date"] == end_time.to_date.to_s && job["sales_type"] == sales_type && job["status"] == "processing" job["status"] = "completed" job["download_url"] = download_url $redis.lset(RedisKey.sales_report_jobs, index, job.to_json) break end end rescue JSON::ParserError end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/send_workflow_installment_worker.rb
app/sidekiq/send_workflow_installment_worker.rb
# frozen_string_literal: true class SendWorkflowInstallmentWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :low def perform(installment_id, version, purchase_id, follower_id, affiliate_user_id = nil, subscription_id = nil) installment = Installment.find_by(id: installment_id) return if installment.nil? return if installment.seller&.suspended? return unless installment.workflow.alive? return unless installment.alive? return unless installment.published? installment_rule = installment.installment_rule return if installment_rule.nil? return if installment_rule.version != version if purchase_id.present? && follower_id.nil? && affiliate_user_id.nil? && subscription_id.nil? installment.send_installment_from_workflow_for_purchase(purchase_id) elsif follower_id.present? && purchase_id.nil? && affiliate_user_id.nil? && subscription_id.nil? installment.send_installment_from_workflow_for_follower(follower_id) elsif affiliate_user_id.present? && purchase_id.nil? && follower_id.nil? && subscription_id.nil? installment.send_installment_from_workflow_for_affiliate_user(affiliate_user_id) elsif subscription_id.present? && purchase_id.nil? && follower_id.nil? && affiliate_user_id.nil? installment.send_installment_from_workflow_for_member_cancellation(subscription_id) end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/generate_community_chat_recap_job.rb
app/sidekiq/generate_community_chat_recap_job.rb
# frozen_string_literal: true class GenerateCommunityChatRecapJob include Sidekiq::Job sidekiq_options queue: :low, retry: 1, lock: :until_executed def perform(community_chat_recap_id) community_chat_recap = CommunityChatRecap.find(community_chat_recap_id) CommunityChatRecapGeneratorService.new(community_chat_recap:).process community_chat_recap.community_chat_recap_run.check_if_finished! end FailureHandler = ->(job, e) do if job["class"] == "GenerateCommunityChatRecapJob" recap_id = job["args"]&.first return if recap_id.blank? recap = CommunityChatRecap.find_by(id: recap_id) return if recap.blank? recap.update!(status: "failed", error_message: e.message) recap.community_chat_recap_run.check_if_finished! end end sidekiq_retries_exhausted(&FailureHandler) end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/log_sendgrid_event_worker.rb
app/sidekiq/log_sendgrid_event_worker.rb
# frozen_string_literal: true class LogSendgridEventWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :mongo def perform(params) events = params["_json"] # Handling potential SendGrid weirdness where sometimes it might not give us an array. events = [events] unless events.is_a?(Array) events.each do |event| event_type = event["event"] next unless %w[open click].include?(event_type) timestamp = Time.zone.at(event["timestamp"]) case event_type when "open" EmailEvent.log_open_event(event["email"], timestamp) when "click" EmailEvent.log_click_event(event["email"], timestamp) end end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/block_object_worker.rb
app/sidekiq/block_object_worker.rb
# frozen_string_literal: true class BlockObjectWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :default def perform(object_type, identifier, author_id, expires_in = nil) BlockedObject.block!(BLOCKED_OBJECT_TYPES[object_type.to_sym], identifier, author_id, expires_in:) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/handle_stripe_event_worker.rb
app/sidekiq/handle_stripe_event_worker.rb
# frozen_string_literal: true class HandleStripeEventWorker include Sidekiq::Job sidekiq_options retry: 10, queue: :default def perform(params) StripeEventHandler.new(params).handle_stripe_event end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/elasticsearch_indexer_worker.rb
app/sidekiq/elasticsearch_indexer_worker.rb
# frozen_string_literal: true class ElasticsearchIndexerWorker include Sidekiq::Job sidekiq_options retry: 10, queue: :default UPDATE_BY_QUERY_SCROLL_SIZE = 100 # Usage examples: # .perform("index", { "class_name" => "Link", "record_id" => 1 } ) # .perform("delete", { "class_name" => "Link", "record_id" => 1 } ) # .perform("update", { "class_name" => "Link", "record_id" => 1, "fields" => ["price_cents"] } ) # .perform("update_by_query", { "class_name" => "Link", "source_record_id" => 1, "fields" => ["price_cents"], "query" => {...} } ) # .perform("index", { "class_name" => "SomeEvent", "id" => "0ab1c2", "body" => { "timestamp" => "2021-07-20T01:00:00Z" } } ) def perform(operation, params) if operation == "update_by_query" if Feature.active?(:esiw_delay_ubqs) ElasticsearchIndexerWorker.perform_in(rand(72.hours) + 6.hours, operation, params) return else return perform_update_by_query(params) end end klass = params.fetch("class_name").constantize client_params = { index: klass.index_name, ignore: Set.new } client_params[:ignore] << 404 if ignore_404_errors_on_indices.include?(klass.index_name) if params.key?("record_id") record_id = params.fetch("record_id") client_params[:id] = record_id else client_params[:id] = params.fetch("id") end case operation when "index" client_params[:body] = params["body"] || klass.find(record_id).as_indexed_json client_params[:index] = klass.index_name_from_body(client_params[:body]) if klass.respond_to?(:index_name_from_body) EsClient.index(client_params) when "update" fields = params.fetch("fields") client_params[:body] = { "doc" => klass.find(record_id).as_indexed_json(only: fields) } EsClient.update(client_params) when "delete" client_params[:ignore] << 404 EsClient.delete(client_params) end end def self.columns_to_fields(columns, mapping:) mapping.values_at(*columns).flatten.uniq.compact end private # The updates and deletion to the following index names will have 404 errors ignored. # This is useful when adding a new index and all records aren't indexed yet. # You can add an indice here by doing something like: # $redis.sadd(RedisKey.elasticsearch_indexer_worker_ignore_404_errors_on_indices, 'purchases_v2') def ignore_404_errors_on_indices $redis.smembers(RedisKey.elasticsearch_indexer_worker_ignore_404_errors_on_indices) end # Helps denormalization by enabling the update of a large amount of documents, # with the same values, selected via ES query. def perform_update_by_query(params) klass = params.fetch("class_name").constantize source_record = klass.find(params.fetch("source_record_id")) script = <<~SCRIPT.squish for (item in params.new_values) { ctx._source[item.key] = item.value; } SCRIPT new_values = [] params.fetch("fields").map do |field| raise "Updating nested fields ('#{field}') by query is not supported" if field.include?(".") new_values << { key: field, value: source_record.search_field_value(field) } end # Most UBQ operate without conflicts, so let's try it directly first (faster and less expensive), # otherwise, scroll through results. begin EsClient.update_by_query( index: klass.index_name, body: { script: { source: script, params: { new_values: } }, query: params.fetch("query") } ) rescue Elasticsearch::Transport::Transport::Errors::Conflict, Faraday::TimeoutError => _e # noop else return end response = EsClient.search( index: klass.index_name, scroll: "1m", body: { query: params.fetch("query") }, size: UPDATE_BY_QUERY_SCROLL_SIZE, sort: ["_doc"], _source: false ) loop do hits = response.dig("hits", "hits") break if hits.empty? ids = hits.map { |hit| hit["_id"] } update_by_query_ids( index_name: klass.index_name, script:, script_params: { new_values: }, ids: ) break if hits.size < UPDATE_BY_QUERY_SCROLL_SIZE response = EsClient.scroll( index: klass.index_name, body: { scroll_id: response["_scroll_id"] }, scroll: "1m" ) end EsClient.clear_scroll(scroll_id: response["_scroll_id"]) end def update_by_query_ids(index_name:, script:, script_params:, ids:) tries = 0 max_retries = 10 begin tries += 1 EsClient.update_by_query( index: index_name, body: { script: { source: script, params: script_params }, query: { terms: { _id: ids } } } ) rescue Elasticsearch::Transport::Transport::Errors::Conflict => e raise e if tries == max_retries sleep 1 retry end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/generate_subscribe_preview_job.rb
app/sidekiq/generate_subscribe_preview_job.rb
# frozen_string_literal: true class GenerateSubscribePreviewJob include Sidekiq::Job sidekiq_options retry: 5, queue: :low, lock: :until_executed def perform(user_id) user = User.find(user_id) image = SubscribePreviewGeneratorService.generate_pngs([user]).first if image.blank? raise "Subscribe Preview could not be generated for user.id=#{user.id}" end user.subscribe_preview.attach( io: StringIO.new(image), filename: "subscribe_preview.png", content_type: "image/png" ) user.subscribe_preview.blob.save! end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/pdf_unstampable_notifier_job.rb
app/sidekiq/pdf_unstampable_notifier_job.rb
# frozen_string_literal: true class PdfUnstampableNotifierJob include Sidekiq::Job sidekiq_options queue: :default, retry: 5 def perform(product_id) product = Link.find(product_id) total_files_checked = 0 total_unstampable_files = 0 product.product_files.alive.pdf.pdf_stamp_enabled.where(stampable_pdf: nil).find_each do |product_file| total_files_checked += 1 is_stampable = PdfStampingService.can_stamp_file?(product_file:) product_file.update!(stampable_pdf: is_stampable) total_unstampable_files += 1 if !is_stampable end return if total_files_checked == 0 if total_unstampable_files > 0 ContactingCreatorMailer.unstampable_pdf_notification(product.id).deliver_later(queue: "critical") end # if all files we checked are unstampable, we can stop here return if total_files_checked == total_unstampable_files # if some files have been newly marked as stampable, we need to stamp them for existing sales product.sales.successful_gift_or_nongift.not_is_gift_sender_purchase.not_recurring_charge.includes(:url_redirect).find_each(order: :desc) do |purchase| next if purchase.url_redirect.blank? StampPdfForPurchaseJob.perform_async(purchase.id) end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/invalidate_product_cache_worker.rb
app/sidekiq/invalidate_product_cache_worker.rb
# frozen_string_literal: true class InvalidateProductCacheWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :low, lock: :until_executed def perform(product_id) product = Link.find(product_id) product.invalidate_cache end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/concerns/transcode_event_handler.rb
app/sidekiq/concerns/transcode_event_handler.rb
# frozen_string_literal: true module TranscodeEventHandler private def handle_transcoding_job_notification(job_id, state, transcoded_video_key = nil) transcoded_video_from_job = TranscodedVideo.find_by(job_id:) return if transcoded_video_from_job.nil? TranscodedVideo.processing.where(original_video_key: transcoded_video_from_job.original_video_key).find_each do |transcoded_video| transcoded_video.update!(transcoded_video_key:) if transcoded_video_key.present? transcoded_video.mark(state.downcase) streamable = transcoded_video.streamable next if streamable.deleted? || transcoded_video.deleted? if transcoded_video.error? next if TranscodedVideo.where(original_video_key: transcoded_video_from_job.original_video_key, state: ["processing", "completed"]).exists? Rails.logger.info("TranscodeEventHandler => video_transcode_failed: #{transcoded_video.attributes}") streamable.transcoding_failed elsif transcoded_video.completed? && transcoded_video.is_hls streamable.update(is_transcoded_for_hls: true) end end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/exports/audience_export_worker.rb
app/sidekiq/exports/audience_export_worker.rb
# frozen_string_literal: true class Exports::AudienceExportWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :low, lock: :until_executed def perform(seller_id, recipient_id, audience_options = {}) seller, recipient = User.find(seller_id, recipient_id) recipient ||= seller result = Exports::AudienceExportService.new(seller, audience_options).perform ContactingCreatorMailer.subscribers_data( recipient:, tempfile: result.tempfile, filename: result.filename, ).deliver_now end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/exports/affiliate_export_worker.rb
app/sidekiq/exports/affiliate_export_worker.rb
# frozen_string_literal: true class Exports::AffiliateExportWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :low, lock: :until_executed def perform(seller_id, recipient_id) seller, recipient = User.find(seller_id, recipient_id) recipient ||= seller result = Exports::AffiliateExportService.new(seller).perform ContactingCreatorMailer.affiliates_data( recipient:, tempfile: result.tempfile, filename: result.filename, ).deliver_now end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/exports/sales/process_chunk_worker.rb
app/sidekiq/exports/sales/process_chunk_worker.rb
# frozen_string_literal: true class Exports::Sales::ProcessChunkWorker include Sidekiq::Job # This job is unique because two parallel jobs running `chunks_left_to_process?` could queue the same chunk to be reprocessed. sidekiq_options retry: 5, queue: :low, lock: :until_executed def perform(chunk_id) @chunk = SalesExportChunk.find(chunk_id) @export = @chunk.export process_chunk return if chunks_left_to_process? Exports::Sales::CompileChunksWorker.perform_async(@export.id) end private def process_chunk purchases = Purchase.where(id: @chunk.purchase_ids) service = Exports::PurchaseExportService.new(purchases) @chunk.update!( custom_fields: service.custom_fields, purchases_data: service.purchases_data, processed: true, revision: REVISION ) end def chunks_left_to_process? # If some chunks were not processed yet, we're not done yet return true if @export.chunks.where(processed: false).exists? # If all chunks were processed with the same revision, we're done return false if @export.chunks.where(processed: true, revision: REVISION).count == @export.chunks.count # Re-enqueue the chunks that were processed with an old revision, and return true because we're not done yet processed_with_old_revision = @export.chunks.where(processed: true).where.not(revision: REVISION).ids self.class.perform_bulk(processed_with_old_revision.map { |id| [id] }) true end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/exports/sales/create_and_enqueue_chunks_worker.rb
app/sidekiq/exports/sales/create_and_enqueue_chunks_worker.rb
# frozen_string_literal: true class Exports::Sales::CreateAndEnqueueChunksWorker include Sidekiq::Job sidekiq_options retry: 5, queue: :low # This is the number of purchases that will be exported in each SalesExportChunk. # It also affects: # - how long it will take to serialize/deserialize that YAML (2.5s/0.4s for 1k purchases) # - how much memory the process will hold while processing the chunk (1.2MB for 1k purchases) MAX_PURCHASES_PER_CHUNK = 1_000 def perform(export_id) @export = SalesExport.find(export_id) create_chunks enqueue_chunks end private def create_chunks # Delete stale chunks if this job is being retried. @export.chunks.in_batches(of: 1).delete_all response = EsClient.search( index: Purchase.index_name, scroll: "1m", body: { query: @export.query }, size: MAX_PURCHASES_PER_CHUNK, sort: [:created_at, :id], _source: false ) loop do hits = response.dig("hits", "hits") break if hits.empty? ids = hits.map { |hit| hit["_id"].to_i } @export.chunks.create!(purchase_ids: ids) break if hits.size < MAX_PURCHASES_PER_CHUNK response = EsClient.scroll( index: Purchase.index_name, body: { scroll_id: response["_scroll_id"] }, scroll: "1m" ) end EsClient.clear_scroll(scroll_id: response["_scroll_id"]) end def enqueue_chunks Exports::Sales::ProcessChunkWorker.perform_bulk(@export.chunks.ids.map { |id| [id] }) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/exports/sales/compile_chunks_worker.rb
app/sidekiq/exports/sales/compile_chunks_worker.rb
# frozen_string_literal: true class Exports::Sales::CompileChunksWorker include Sidekiq::Job # This job is unique because two parallel ProcessChunkWorker jobs could queue this at the same time. sidekiq_options retry: 5, queue: :low, lock: :until_executed def perform(export_id) @export = SalesExport.find(export_id) ContactingCreatorMailer.user_sales_data(@export.recipient_id, generate_compiled_tempfile).deliver_now @export.chunks.in_batches(of: 1).delete_all @export.destroy! end private def generate_compiled_tempfile custom_fields = @export.chunks.select(:custom_fields).where.not(custom_fields: []).distinct.order(:id).map(&:custom_fields).flatten.uniq # The purpose of this enumerator is to allow the code in `.compile` to call `#each` on it, # yielding an individual pair of [purchase_fields_data, custom_fields_data], # while never loading more than one chunk in memory (because of `find_each(batch_size: 1)`). purchases_data_enumerator = Enumerator.new do |yielder| @export.chunks.select(:id, :purchases_data).find_each(batch_size: 1) do |chunk| chunk.purchases_data.each do |data| yielder << data end end end Exports::PurchaseExportService.compile(custom_fields, purchases_data_enumerator) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/reports/generate_ytd_sales_report_job.rb
app/sidekiq/reports/generate_ytd_sales_report_job.rb
# frozen_string_literal: true module Reports class GenerateYtdSalesReportJob include Sidekiq::Worker sidekiq_options queue: "low", retry: 3 def perform current_year_start = Time.current.beginning_of_year.iso8601 es_query = { size: 0, query: { bool: { filter: [ { range: { created_at: { gte: current_year_start, lte: "now" } } }, { term: { not_chargedback_or_chargedback_reversed: true } }, { terms: { purchase_state: [ "successful", "preorder_concluded_successfully", "gift_receiver_purchase_successful", "pending_fulfillment", "refunded", "partially_refunded" ] } } ] } }, aggs: { sales_by_country: { terms: { field: "country_or_ip_country", size: 250, missing: "UNKNOWN_COUNTRY" }, aggs: { sales_by_state: { terms: { field: "ip_state", size: 100, missing: "UNKNOWN_STATE" }, aggs: { total_gross_revenue_cents: { sum: { field: "price_cents" } }, total_refunded_cents: { sum: { field: "amount_refunded_cents" } }, net_sales_cents: { bucket_script: { buckets_path: { gross_revenue: "total_gross_revenue_cents", refunds: "total_refunded_cents" }, script: "params.gross_revenue - params.refunds" } } } } } } } } results = Purchase.search(es_query) aggregations = results.aggregations csv_string = CSV.generate do |csv| csv << ["Country", "State", "Net Sales (USD)"] if aggregations && aggregations["sales_by_country"] && aggregations["sales_by_country"]["buckets"] aggregations["sales_by_country"]["buckets"].each do |country_bucket| country_code = country_bucket["key"] if country_bucket["sales_by_state"] && country_bucket["sales_by_state"]["buckets"] country_bucket["sales_by_state"]["buckets"].each do |state_bucket| state_code = state_bucket["key"] net_sales_in_cents = state_bucket["net_sales_cents"] ? state_bucket["net_sales_cents"]["value"] : 0.0 if state_bucket["doc_count"] > 0 csv << [country_code, state_code, (net_sales_in_cents.to_f / 100.0).round(2)] end end end end else Rails.logger.warn "Reports::GenerateYtdSalesReportJob: No aggregations found or structure not as expected. Check Elasticsearch results." end end recipient_emails = $redis.lrange(RedisKey.ytd_sales_report_emails, 0, -1) if recipient_emails.present? recipient_emails.each do |email| AccountingMailer.ytd_sales_report(csv_string, email.strip).deliver_now Rails.logger.info "Reports::GenerateYtdSalesReportJob: YTD Sales report sent to #{email.strip}" end else Rails.logger.warn "Reports::GenerateYtdSalesReportJob: No recipient emails found in Redis list '#{RedisKey.ytd_sales_report_emails}'. Report not sent." end end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/onetime/generate_subscribe_previews.rb
app/sidekiq/onetime/generate_subscribe_previews.rb
# frozen_string_literal: true class Onetime::GenerateSubscribePreviews include Sidekiq::Job sidekiq_options retry: 5, queue: :mongo def perform(user_ids) users = User.where(id: user_ids) subscribe_previews = SubscribePreviewGeneratorService.generate_pngs(users) if subscribe_previews.length != users.length || users.any?(&:nil?) raise "Failed to generate all subscribe previews for top sellers" end users.each_with_index do |user, i| user.subscribe_preview.attach( io: StringIO.new(subscribe_previews[i]), filename: "subscribe_preview.png", content_type: "image/png" ) user.subscribe_preview.blob.save! end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/iffy/event_job.rb
app/sidekiq/iffy/event_job.rb
# frozen_string_literal: true class Iffy::EventJob include Sidekiq::Job sidekiq_options retry: 3, queue: :default RECENT_PURCHASE_PERIOD = 1.year EVENTS = %w[ user.banned user.suspended user.compliant record.flagged record.compliant ] def perform(event, id, entity, user = nil) return unless event.in?(EVENTS) case event when "user.banned" Iffy::User::BanService.new(id).perform when "user.suspended" Iffy::User::SuspendService.new(id).perform when "user.compliant" Iffy::User::MarkCompliantService.new(id).perform unless user_suspended_by_admin?(id) when "record.flagged" if entity == "Product" && !user_protected?(user) Iffy::Product::FlagService.new(id).perform elsif entity == "Post" && !user_protected?(user) Iffy::Post::FlagService.new(id).perform end when "record.compliant" if entity == "Product" Iffy::Product::MarkCompliantService.new(id).perform elsif entity == "Post" Iffy::Post::MarkCompliantService.new(id).perform end end end private def user_protected?(user) user&.dig("protected") == true end def user_suspended_by_admin?(user_external_id) user = User.find_by_external_id(user_external_id) return false unless user user.suspended_by_admin? end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/iffy/product/ingest_job.rb
app/sidekiq/iffy/product/ingest_job.rb
# frozen_string_literal: true class Iffy::Product::IngestJob include Sidekiq::Job sidekiq_options queue: :default, retry: 3 def perform(product_id) product = Link.find(product_id) Iffy::Product::IngestService.new(product).perform end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/iffy/profile/ingest_job.rb
app/sidekiq/iffy/profile/ingest_job.rb
# frozen_string_literal: true class Iffy::Profile::IngestJob include Sidekiq::Job sidekiq_options queue: :default, retry: 3 def perform(user_id) user = User.find(user_id) Iffy::Profile::IngestService.new(user).perform end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/sidekiq/iffy/post/ingest_job.rb
app/sidekiq/iffy/post/ingest_job.rb
# frozen_string_literal: true class Iffy::Post::IngestJob include Sidekiq::Job sidekiq_options queue: :default, retry: 3 def perform(post_id) post = Installment.find(post_id) Iffy::Post::IngestService.new(post).perform end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/comment_mailer.rb
app/mailers/comment_mailer.rb
# frozen_string_literal: true class CommentMailer < ApplicationMailer layout "layouts/email" default from: "noreply@#{CREATOR_CONTACTING_CUSTOMERS_MAIL_DOMAIN}" def notify_seller_of_new_comment(comment_id) @comment = Comment.includes(:commentable).find(comment_id) subject = "New comment on #{@comment.commentable.name}" mail( to: @comment.commentable.seller.form_email, subject:, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :creators) ) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/service_mailer.rb
app/mailers/service_mailer.rb
# frozen_string_literal: true class ServiceMailer < ApplicationMailer after_action :deliver_email layout "layouts/email" # service charge emails def service_charge_receipt(service_charge_id) @service_charge = ServiceCharge.find(service_charge_id) @user = @service_charge.user @subject = "Gumroad — Receipt" end # recurring service emails private def deliver_email return if @do_not_send email = @user.form_email return unless EmailFormatValidator.valid?(email) mailer_args = { to: email, subject: @subject } mailer_args[:from] = @from if @from.present? mail(mailer_args) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/one_off_mailer.rb
app/mailers/one_off_mailer.rb
# frozen_string_literal: true class OneOffMailer < ApplicationMailer helper InstallmentsHelper layout "layouts/email" # Mailer used to send one-off emails to user, usually via Rails console # `from` email address is not being monitored. If you need to receive replies from users, pass the optional # param `reply_to`, e.g. reply_to: ApplicationMailer::NOREPLY_EMAIL_WITH_NAME def email(user_id: nil, email: nil, from: nil, subject:, body:, reply_to: nil, sender_domain: nil) email ||= User.alive.not_suspended.find_by(id: user_id)&.form_email return unless EmailFormatValidator.valid?(email) from ||= "Gumroad <hi@#{CUSTOMERS_MAIL_DOMAIN}>" sender_domain ||= :customers @subject = subject @body = body options = { to: email, from: from, subject: @subject, delivery_method_options: MailerInfo.random_delivery_method_options(domain: sender_domain.to_sym) } options[:reply_to] = reply_to if reply_to.present? mail options end def email_using_installment(user_id: nil, email: nil, installment_external_id:, subject: nil, reply_to: nil) @installment = Installment.find_by_external_id(installment_external_id) email(user_id:, email:, subject: subject || @installment.subject, reply_to:, body: nil) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/contacting_creator_mailer.rb
app/mailers/contacting_creator_mailer.rb
# frozen_string_literal: true class ContactingCreatorMailer < ApplicationMailer include ActionView::Helpers::NumberHelper include ActionView::Helpers::TagHelper include ActionView::Helpers::UrlHelper include ActionView::Helpers::TextHelper include CurrencyHelper include CustomMailerRouteBuilder include SocialShareUrlHelper include NotifyOfSaleHeaders helper ProductsHelper helper CurrencyHelper helper PreorderHelper helper InstallmentsHelper default from: ApplicationMailer::SUPPORT_EMAIL_WITH_NAME after_action :deliver_email after_action :send_push_notification!, only: :notify layout "layouts/email" def notify(purchase_id, is_preorder = false, email = nil, link_id = nil, price_cents = nil, variants = nil, shipping_info = nil, custom_fields = nil, offer_code_id = nil) if purchase_id @purchase = Purchase.find(purchase_id) @is_preorder = is_preorder return do_not_send if @purchase.nil? @product = @purchase.link @variants = @purchase.variants_list @quantity = @purchase.quantity @variants_count = @purchase.variant_names&.count || 0 @custom_fields = @purchase.custom_fields @offer_code = @purchase.offer_code else @product = Link.find(link_id) @variants = variants @variants_count = variants&.count || 0 @custom_fields = custom_fields @offer_code = offer_code_id.present? ? OfferCode.find(offer_code_id) : nil end if @product.is_tiered_membership? && @variants_and_quantity == "(Untitled)" @variants_and_quantity = nil end if price_cents.present? @price = Money.new(price_cents, @product.price_currency_type.to_sym).format(no_cents_if_whole: true, symbol: true) elsif @purchase&.commission.present? @price = format_just_price_in_cents(@purchase.displayed_price_cents + @purchase.commission.completion_display_price_cents, @purchase.displayed_price_currency_type) elsif @purchase.nil? @price = @product.price_formatted end if @product.require_shipping @shipping_info = shipping_info || { "full_name" => @purchase.full_name, "street_address" => @purchase.street_address, "city" => @purchase.city, "zip_code" => @purchase.zip_code, "state" => @purchase.state, "country" => @purchase.country } end if email.present? @purchaser_email = email elsif @purchase.email.present? @purchaser_email = @purchase.email elsif @purchase.purchaser.present? && @purchase.purchaser.email.present? @purchaser_email = @purchase.purchaser.email end @buyer_name = @purchase.try(:full_name) @seller = @product.user @unsub_link = user_unsubscribe_url(id: @seller.secure_external_id(scope: "email_unsubscribe"), email_type: :notify) @reply_to = @purchase.try(:email) set_notify_of_sale_headers(is_preorder:) @referrer_name = @purchase&.display_referrer do_not_send unless should_send_email? end def negative_revenue_sale_failure(purchase_id) @purchase = Purchase.find(purchase_id) @seller = @purchase.seller @subject = "A sale failed because of negative net revenue" end def chargeback_notice(dispute_id) dispute = Dispute.find(dispute_id) @disputable = dispute.disputable @is_paypal = @disputable.charge_processor == PaypalChargeProcessor.charge_processor_id @seller = @disputable.seller dispute_evidence = dispute.dispute_evidence @dispute_evidence_content = \ if dispute_evidence&.seller_contacted? safe_join( [ tag.p(tag.b("Any additional information you can provide in the next #{pluralize(dispute_evidence.hours_left_to_submit_evidence, "hour")} will help us win on your behalf.")), tag.p( link_to( "Submit additional information", purchase_dispute_evidence_url(@disputable.purchase_for_dispute_evidence.external_id), class: "button primary" ) ) ] ) end @subject = \ if @is_paypal.present? "A PayPal sale has been disputed" elsif dispute_evidence&.seller_contacted? "🚨 Urgent: Action required for resolving disputed sale" else "A sale has been disputed" end end def remind(user_id) @seller = User.find_by(id: user_id) return unless @seller @unsub_link = user_unsubscribe_url(id: @seller.secure_external_id(scope: "email_unsubscribe"), email_type: :product_update) @sales_count = @seller.sales.successful.count @subject = "Please add a payment account to Gumroad." end def video_preview_conversion_error(link_id) @product = Link.find(link_id) @seller = @product.user @subject = "We were unable to process your preview video." end def seller_update(user_id) @end_of_period = Date.today.beginning_of_week(:sunday).to_datetime @start_of_period = @end_of_period - 7.days @seller = User.find(user_id) @unsub_link = user_unsubscribe_url(id: @seller.secure_external_id(scope: "email_unsubscribe"), email_type: :seller_update) @subject = "Your last week." end def invalid_bank_account(user_id) @seller = User.find(user_id) @subject = "We were unable to verify your bank account." end def cannot_pay(payment_id) @payment = Payment.find(payment_id) @seller = @payment.user @subject = "We were unable to pay you." @amount = Money.new(@payment.amount_cents, @payment.currency).format(no_cents_if_whole: true, symbol: true) end def flagged_for_explicit_nsfw_tos_violation(user_id) @seller = User.find(user_id) @subject = "Your account has been temporarily suspended for selling sexually explicit / fetish-related content" @days_until_suspension = 10 date_of_suspension = Time.current + @days_until_suspension.days @formatted_suspension_date = I18n.l(date_of_suspension, format: "%-d %B", locale: @seller.locale) @from = NOREPLY_EMAIL_WITH_NAME end def debit_card_limit_reached(payment_id) @payment = Payment.find(payment_id) @seller = @payment.user @subject = "We were unable to pay you." @amount = Money.new(@payment.amount_cents, @payment.currency).format(no_cents_if_whole: true, symbol: true) @limit = Money.new(StripePayoutProcessor::DEBIT_CARD_PAYOUT_MAX, Currency::USD).format(no_cents_if_whole: true, symbol: true) end def subscription_product_deleted(link_id) @product = Link.find(link_id) @seller = @product.user @subject = if @product.is_recurring_billing? "Subscriptions have been canceled" else "Installment plans have been canceled" end end def credit_notification(user_id, amount_cents) @seller = User.find_by(id: user_id) @amount = Money.new(amount_cents * get_rate(@seller.currency_type).to_f, @seller.currency_type.to_sym).format(no_cents_if_whole: true, symbol: true) @subject = "You've received Gumroad credit!" end def gumroad_day_credit_notification(user_id, amount_cents) @seller = User.find_by(id: user_id) @amount = Money.new(amount_cents * get_rate(@seller.currency_type).to_f, @seller.currency_type.to_sym).format(no_cents_if_whole: true, symbol: true) @subject = "You've received Gumroad credit!" end def subscription_cancelled(subscription_id) @subscription = Subscription.find(subscription_id) @seller = @subscription.seller @subject = if @subscription.is_installment_plan? "An installment plan has been canceled." else "A subscription has been canceled." end end def subscription_cancelled_by_customer(subscription_id) @subscription = Subscription.find(subscription_id) @seller = @subscription.seller @subject = "A subscription has been canceled." end def subscription_autocancelled(subscription_id) @subscription = Subscription.find(subscription_id) @subject = if @subscription.is_installment_plan? "An installment plan has been paused." else "A subscription has been canceled." end @seller = @subscription.seller @last_failed_purchase = @subscription.purchases.failed.last end def subscription_ended(subscription_id) @subscription = Subscription.find(subscription_id) @seller = @subscription.seller @subject = if @subscription.is_installment_plan? "An installment plan has been paid in full." else "A subscription has ended." end end def subscription_downgraded(subscription_id, plan_change_id) @subscription = Subscription.find(subscription_id) @subscription_plan_change = SubscriptionPlanChange.find(plan_change_id) @seller = @subscription.seller @subject = "A subscription has been downgraded." end def subscription_restarted(subscription_id) @subscription = Subscription.find(subscription_id) @seller = @subscription.seller @subject = if @subscription.is_installment_plan? "An installment plan has been restarted." else "A subscription has been restarted." end end def unremovable_discord_member(discord_user_id, discord_server_name, purchase_id) @purchase = Purchase.find(purchase_id) @seller = @purchase.seller @discord_user_id = discord_user_id @discord_server_name = discord_server_name @subject = "We were unable to remove a Discord member from your server" end def unstampable_pdf_notification(link_id) @product = Link.find(link_id) @seller = @product.user @subject = "We were unable to stamp your PDF" end def chargeback_lost_no_refund_policy(dispute_id) dispute = Dispute.find(dispute_id) @disputable = dispute.disputable @seller = @disputable.seller @subject = "A dispute has been lost" end def chargeback_won(dispute_id) dispute = Dispute.find(dispute_id) @disputable = dispute.disputable @seller = @disputable.seller @subject = "A dispute has been won" end def preorder_release_reminder(link_id) @product = Link.find(link_id) @preorder_link = @product.preorder_link @seller = @product.user @subject = "Your pre-order will be released shortly" end def preorder_summary(preorder_link_id) preorder_link = PreorderLink.find_by(id: preorder_link_id) @product = preorder_link.link @revenue_cents = preorder_link.revenue_cents @preorders_count = preorder_link.preorders.authorization_successful_or_charge_successful.count @preorders_charged_successfully_count = preorder_link.preorders.charge_successful.count @failed_preorder_emails = Purchase.where("preorder_id IN (?)", preorder_link.preorders.authorization_successful.pluck(:id)).group(:preorder_id).pluck(:email) # Don't send the email if the seller made no money. return do_not_send if @preorders_charged_successfully_count == 0 @seller = @product.user @subject = "Your pre-order was successfully released!" end def preorder_cancelled(preorder_id) @preorder = Preorder.find_by(id: preorder_id) @seller = @preorder.seller @subject = "A preorder has been canceled." end def purchase_refunded_for_fraud(purchase_id) @purchase = Purchase.find_by(id: purchase_id) @seller = @purchase.seller @subject = "Fraud was detected on your Gumroad account." end def purchase_refunded(purchase_id) @purchase = Purchase.find_by(id: purchase_id) @seller = @purchase.seller @subject = "A sale has been refunded" end def payment_returned(payment_id) @payment = Payment.find(payment_id) @seller = @payment.user @subject = "Gumroad payout returned" end def payouts_may_be_blocked(user_id) @seller = User.find(user_id) return do_not_send unless @seller.account_active? @subject = "We need more information from you." end def more_kyc_needed(user_id, fields_needed = []) @seller = User.find(user_id) return do_not_send unless @seller.account_active? @subject = "We need more information from you." country = @seller.compliance_country_code @fields_needed_tags = fields_needed.map { |field_needed| UserComplianceInfoFieldProperty.name_tag_for_field(field_needed, country:) }.compact end def stripe_document_verification_failed(user_id, error_message) @seller = User.find(user_id) return do_not_send unless @seller.account_active? @subject = "[Action Required] Document Verification Failed" @error_message = error_message end def stripe_identity_verification_failed(user_id, error_message) @seller = User.find(user_id) return do_not_send unless @seller.account_active? @subject = "[Action Required] Identity Verification Failed" @error_message = error_message end def singapore_identity_verification_reminder(user_id, deadline) @seller = User.find(user_id) return do_not_send unless @seller.account_active? @deadline = deadline.to_fs(:formatted_date_full_month) @subject = "[Action Required] Complete the identity verification to avoid account closure" end def stripe_remediation(user_id) @seller = User.find(user_id) return do_not_send unless @seller.account_active? @subject = "We need more information from you." end def suspended_due_to_stripe_risk(user_id) @seller = User.find(user_id) @subject = "Your account has been suspended for being high risk" end def user_sales_data(user_id, sales_csv_tempfile) @seller = User.find(user_id) @subject = "Here's your customer data!" file_or_url = MailerAttachmentOrLinkService.new( file: sales_csv_tempfile, extension: "csv", filename: "user-sales-data/Sales_#{user_id}_#{Time.current.strftime("%s")}_#{SecureRandom.hex}.csv" ).perform file = file_or_url[:file] if file file.rewind attachments["sales_data.csv"] = { data: file.read } else @sales_csv_url = file_or_url[:url] end end def payout_data(attachment_name, extension, tempfile, recipient_user_id) @recipient = User.find(recipient_user_id) @subject = "Here's your payout data!" file_or_url = MailerAttachmentOrLinkService.new( file: tempfile, filename: attachment_name, extension: ).perform if file = file_or_url[:file] file.rewind attachments[attachment_name] = file.read else @payout_data_url = file_or_url[:url] end end def annual_payout_summary(user_id, year, total_amount) @year = year @next_year = Date.new(year).next_year.year @formatted_total_amount = formatted_dollar_amount((total_amount * 100).floor) @seller = User.find(user_id) @subject = "Here's your financial report for #{year}!" @link = @seller.financial_annual_report_url_for(year:) do_not_send unless @link.present? end def tax_form_1099k(user_id, year, form_download_url) @seller = User.find(user_id) @year = year @tax_form_download_url = form_download_url @subject = "Get your 1099-K form for #{@year}" end def tax_form_1099misc(user_id, year, form_download_url) @seller = User.find(user_id) @year = year @tax_form_download_url = form_download_url @subject = "Get your 1099-MISC form for #{@year}" end def video_transcode_failed(product_file_id) @subject = "A video failed to transcode." product_file = ProductFile.find(product_file_id) @video_transcode_error = "We attempted to transcode a video (#{product_file.s3_filename}) from your product #{product_file.link.name}, but were unable to do so." @seller = product_file.user end def affiliates_data(recipient:, tempfile:, filename:) @subject = "Here is your affiliates data!" @recipient = recipient file_or_url = MailerAttachmentOrLinkService.new( file: tempfile, filename:, ).perform if file_or_url[:file] file_or_url[:file].rewind attachments[filename] = { data: file_or_url[:file].read } else @affiliates_file_url = file_or_url[:url] end end def subscribers_data(recipient:, tempfile:, filename:) @subject = "Here is your subscribers data!" @recipient = recipient file_or_url = MailerAttachmentOrLinkService.new( file: tempfile, filename:, ).perform if file_or_url[:file] file_or_url[:file].rewind attachments[filename] = { data: file_or_url[:file].read } else @subscribers_file_url = file_or_url[:url] end end def review_submitted(review_id) @review = ProductReview.includes(:purchase, link: :user).find(review_id) @product = @review.link @seller = @product.user full_name = @review.purchase.full_name email = @review.purchase.email @buyer = full_name.present? ? "#{full_name} (#{email})" : email @subject = "#{@buyer} reviewed #{@product.name}" end def upcoming_call_reminder(call_id) call = Call.find(call_id) return do_not_send unless call.eligible_for_reminder? purchase = call.purchase @seller = purchase.seller buyer_email = purchase.purchaser_email_or_email @subject = "Your scheduled call with #{buyer_email} is tomorrow!" @post_purchase_custom_fields_attributes = purchase.purchase_custom_fields .where.not(field_type: CustomField::TYPE_FILE) .map { { label: _1.name, value: _1.value } } @customer_information_attributes = [ { label: "Customer email", value: buyer_email }, { label: "Call schedule", value: [call.formatted_time_range, call.formatted_date_range] }, { label: "Duration", value: purchase.variant_names.first }, call.call_url ? { label: "Call link", value: call.call_url } : nil, { label: "Product", value: purchase.link.name } ].compact end def refund_policy_enabled_email(seller_id) @seller = User.find(seller_id) @subject = "Important: Refund policy changes to your account" @postponed_date = User::LAST_ALLOWED_TIME_FOR_PRODUCT_LEVEL_REFUND_POLICY + 1.second if @seller.account_level_refund_policy_delayed? @subject += " (effective #{@postponed_date.to_fs(:formatted_date_full_month)})" if @postponed_date.present? end def product_level_refund_policies_reverted(seller_id) @seller = User.find(seller_id) @subject = "Important: Refund policy changes effective immediately" end def upcoming_refund_policy_change(user_id) @seller = User.find(user_id) @subject = "Important: Upcoming refund policy changes effective January 1, 2025" end def paypal_suspension_notification(user_id) @seller = User.find(user_id) @subject = "Important: Update Your Payout Method on Gumroad" end def ping_endpoint_failure(user_id, ping_url, response_code) @seller = User.find(user_id) @ping_url = redact_ping_url(ping_url) @response_code = response_code @subject = "Webhook ping endpoint delivery failed" end private def do_not_send @do_not_send = true end def should_send_email? return true unless @purchase if @purchase.price_cents == 0 @seller.enable_free_downloads_email? elsif @purchase.is_recurring_subscription_charge && !@purchase.is_upgrade_purchase? @seller.enable_recurring_subscription_charge_email? else @seller.enable_payment_email? end end def push_notification_enabled? return true unless @purchase if @purchase.price_cents == 0 @seller.enable_free_downloads_push_notification? elsif @purchase.is_recurring_subscription_charge && !@purchase.is_upgrade_purchase? @seller.enable_recurring_subscription_charge_push_notification? else @seller.enable_payment_push_notification? end end def deliver_email return if @do_not_send recipient = @recipient || @seller email = recipient.form_email return unless EmailFormatValidator.valid?(email) mailer_args = { to: email, subject: @subject } mailer_args[:reply_to] = @reply_to if @reply_to.present? mailer_args[:from] = @from if @from.present? mail(mailer_args) end def send_push_notification! return unless push_notification_enabled? if Feature.active?(:send_sales_notifications_to_creator_app) PushNotificationWorker.perform_async(@seller.id, Device::APP_TYPES[:creator], @subject, nil, {}, Device::NOTIFICATION_SOUNDS[:sale]) end if Feature.active?(:send_sales_notifications_to_consumer_app) PushNotificationWorker.perform_async(@seller.id, Device::APP_TYPES[:consumer], @subject, nil, {}, Device::NOTIFICATION_SOUNDS[:sale]) end end def redact_ping_url(url) uri = URI.parse(url) # --- build the host portion (scheme + host + optional port) ---------- host_part = "#{uri.scheme}://#{uri.host}" host_part += ":#{uri.port}" if uri.port && uri.port != uri.default_port # --- collect the part we want to redact ------------------------------ path = uri.path.to_s # always starts with "/" (may be "") query_frag = +"" # Use unary plus to create unfrozen string query_frag << "?#{uri.query}" if uri.query query_frag << "##{uri.fragment}" if uri.fragment body = path.delete_prefix("/") + query_frag # strip leading "/" before counting return host_part + "/" if body.empty? # nothing to redact n = body.length redacted = if n <= 4 # 1-4 → replace completely with stars "*" * n elsif n <= 8 # 5-8 → exactly 4 stars + tail (n-4) "****" + body[-(n - 4)..] else # ≥9 → (n-4) stars + last 4 chars "*" * (n - 4) + body[-4..] end "#{host_part}/#{redacted}" rescue URI::InvalidURIError url end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/follower_mailer.rb
app/mailers/follower_mailer.rb
# frozen_string_literal: true class FollowerMailer < ApplicationMailer layout "layouts/email" default from: "Gumroad <noreply@#{FOLLOWER_CONFIRMATION_MAIL_DOMAIN}>" def confirm_follower(followed_user_id, follower_id) @follower = Follower.find(follower_id) @followed_username = User.find(followed_user_id).name_or_username @confirm_follow_url = confirm_follow_url(@follower.external_id) mail to: @follower.email, subject: "Please confirm your follow request.", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :followers) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/user_signup_mailer.rb
app/mailers/user_signup_mailer.rb
# frozen_string_literal: true class UserSignupMailer < Devise::Mailer include RescueSmtpErrors helper MailerHelper layout "layouts/email" def email_changed(record, opts = {}) opts[:from] = ApplicationMailer::NOREPLY_EMAIL_WITH_NAME opts[:reply_to] = ApplicationMailer::NOREPLY_EMAIL_WITH_NAME super end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/two_factor_authentication_mailer.rb
app/mailers/two_factor_authentication_mailer.rb
# frozen_string_literal: true class TwoFactorAuthenticationMailer < ApplicationMailer after_action :deliver_email layout "layouts/email" # TODO(ershad): Remove this once the issue with Resend is resolved default delivery_method_options: -> { MailerInfo.default_delivery_method_options(domain: :gumroad) } def authentication_token(user_id) @user = User.find(user_id) @authentication_token = @user.otp_code @subject = "Your authentication token is #{@authentication_token}" end private def deliver_email email = @user.email return unless EmailFormatValidator.valid?(email) mailer_args = { to: email, subject: @subject } mailer_args[:from] = @from if @from.present? mail(mailer_args) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/admin_mailer.rb
app/mailers/admin_mailer.rb
# frozen_string_literal: true class AdminMailer < ApplicationMailer SUBJECT_PREFIX = ("[#{Rails.env}] " unless Rails.env.production?) default from: ADMIN_EMAIL default to: DEVELOPERS_EMAIL layout "layouts/email" def chargeback_notify(dispute_id) dispute = Dispute.find(dispute_id) @disputable = dispute.disputable @user = @disputable.seller subject = "#{SUBJECT_PREFIX}Chargeback for #{@disputable.formatted_disputed_amount} on #{@disputable.purchase_for_dispute_evidence.link.name}" subject += " and #{@disputable.disputed_purchases.count - 1} other products" if @disputable.multiple_purchases? mail subject:, to: RISK_EMAIL end def low_balance_notify(user_id, last_refunded_purchase_id) @user = User.find(user_id) @purchase = Purchase.find(last_refunded_purchase_id) @product = @purchase.link mail subject: "#{SUBJECT_PREFIX}Low balance for creator - #{@user.name} (#{@user.balance_formatted(via: :elasticsearch)})", to: RISK_EMAIL end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/application_mailer.rb
app/mailers/application_mailer.rb
# frozen_string_literal: true class ApplicationMailer < ActionMailer::Base include RescueSmtpErrors, MailerHelper helper MailerHelper # Constants for Gumroad emails { ADMIN_EMAIL: "hi@#{DEFAULT_EMAIL_DOMAIN}", DEVELOPERS_EMAIL: "developers@#{DEFAULT_EMAIL_DOMAIN}", NOREPLY_EMAIL: "noreply@#{DEFAULT_EMAIL_DOMAIN}", PAYMENTS_EMAIL: "payments@#{DEFAULT_EMAIL_DOMAIN}", RISK_EMAIL: "risk@#{DEFAULT_EMAIL_DOMAIN}", SUPPORT_EMAIL: "support@#{DEFAULT_EMAIL_DOMAIN}" }.each do |key, email| const_set(key, email) const_set("#{key}_WITH_NAME", email_address_with_name(email, "Gumroad")) end default from: NOREPLY_EMAIL_WITH_NAME, delivery_method_options: -> { MailerInfo.random_delivery_method_options(domain: :gumroad) } after_action :validate_from_email_domain! ruby2_keywords def process(name, *args) super set_custom_headers(name, args) end private def from_email_address_with_name(name = "", email = NOREPLY_EMAIL) name = from_email_address_name(name) email_address_with_name(email, name) end def set_custom_headers(mailer_action, mailer_args) return if self.message.class == ActionMailer::Base::NullMail # Ensure the correct email provider for building the headers is used email_provider = self.message.delivery_method.settings[:address] == RESEND_SMTP_ADDRESS ? MailerInfo::EMAIL_PROVIDER_RESEND : MailerInfo::EMAIL_PROVIDER_SENDGRID custom_headers = MailerInfo.build_headers(mailer_class: self.class.name, mailer_method: mailer_action.to_s, mailer_args:, email_provider:) custom_headers.each do |name, value| headers[name] = value end end # From email domain must match the domain associated with the API key on Resend def validate_from_email_domain! return if message.subject.nil? expected_domain = message.delivery_method.settings[:domain] message.from.each do |from| next if from.split("@").last == expected_domain raise "From email `#{from}` domain does not match expected delivery domain `#{expected_domain}`" end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/creator_mailer.rb
app/mailers/creator_mailer.rb
# frozen_string_literal: true class CreatorMailer < ApplicationMailer helper MailerHelper helper ApplicationHelper helper CurrencyHelper layout "layouts/email" def gumroad_day_fee_saved(seller_id:, to_email: nil) @announcement = true seller = User.find(seller_id) email = to_email.presence || seller.email @fee_saved_amount = seller.gumroad_day_saved_fee_amount return unless @fee_saved_amount.present? mail to: email, subject: "You saved #{@fee_saved_amount} in fees on Gumroad Day!" end def year_in_review(seller:, year:, analytics_data:, payout_csv_url: nil, recipient: nil) @seller = seller @year = year @analytics_data = analytics_data @payout_csv_url = payout_csv_url email = recipient.presence || seller.email mail to: email, subject: "Your #{year} in review" end def bundles_marketing(seller_id:, bundles: []) seller = User.find(seller_id) @currency_type = seller.currency_type @bundles = bundles mail to: seller.form_email, subject: "Join top creators who have sold over $300,000 of bundles" end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/merchant_registration_mailer.rb
app/mailers/merchant_registration_mailer.rb
# frozen_string_literal: true class MerchantRegistrationMailer < ApplicationMailer default from: ADMIN_EMAIL layout "layouts/email" def account_deauthorized_to_user(user_id, charge_processor_id) @user = User.find(user_id) @charge_processor_display_name = ChargeProcessor::DISPLAY_NAME_MAP[charge_processor_id] subject = "Payments account disconnected - #{@user.external_id}" mail(subject:, from: NOREPLY_EMAIL_WITH_NAME, to: @user.email) end def account_needs_registration_to_user(affiliate_id, charge_processor_id) @affiliate = Affiliate.find(affiliate_id) @user = @affiliate.affiliate_user @charge_processor_id = charge_processor_id subject = "#{@charge_processor_id.capitalize} account required" mail(subject:, from: NOREPLY_EMAIL_WITH_NAME, to: @user.email) end def confirm_email_on_paypal(user_id, email) @user = User.find(user_id) @subject = "Please confirm your email address with PayPal" @body = "You need to confirm the email address (#{email}) attached to your PayPal account before you can start using it with Gumroad." mail(subject: @subject, from: NOREPLY_EMAIL_WITH_NAME, to: @user.email) end def paypal_account_updated(user_id) @user = User.find(user_id) @subject = "Your Paypal Connect account was updated." @body = "Your Paypal Connect account was updated.\n\nPlease verify the new payout address to confirm the changes for your <a href=\"#{settings_payments_url}\">payment settings</a>" mail(subject: @subject, from: NOREPLY_EMAIL_WITH_NAME, to: @user.email) end def stripe_charges_disabled(user_id) user = User.find(user_id) mail(subject: "Action required: Your sales have stopped", from: NOREPLY_EMAIL_WITH_NAME, to: user.email) end def stripe_payouts_disabled(user_id) user = User.find(user_id) mail(subject: "Action required: Your payouts are paused", from: NOREPLY_EMAIL_WITH_NAME, to: user.email) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/customer_low_priority_mailer.rb
app/mailers/customer_low_priority_mailer.rb
# frozen_string_literal: true class CustomerLowPriorityMailer < ApplicationMailer include CurrencyHelper helper PreorderHelper helper ProductsHelper include ActionView::Helpers::TextHelper default from: "Gumroad <noreply@#{CUSTOMERS_MAIL_DOMAIN}>" after_action :deliver_subscription_email, only: %i[subscription_autocancelled subscription_cancelled subscription_cancelled_by_seller subscription_card_declined subscription_card_declined_warning subscription_charge_failed subscription_product_deleted subscription_renewal_reminder subscription_price_change_notification subscription_ended free_trial_expiring_soon credit_card_expiring_membership subscription_early_fraud_warning_notification subscription_giftee_added_card] layout "layouts/email" def deposit(payment_id) @payment = Payment.find(payment_id) @user = @payment.user email = @user.form_email return unless EmailFormatValidator.valid?(email) @payment_currency = @payment.currency @payment_display_amount = @payment.displayed_amount @credit_amount_cents = @payment.credit_amount_cents.to_i @paid_date = @payment.payout_period_end_date.strftime("%B %e, %Y") payment_revenue_by_link = @payment.revenue_by_link previous_payout = @user.payments.completed.where("created_at < ?", @payment.created_at).order(:payout_period_end_date).last payout_start_date = previous_payout&.payout_period_end_date.try(:next) payout_end_date = @payment.payout_period_end_date paypal_revenue_by_product = @user.paypal_revenue_by_product_for_duration(start_date: payout_start_date, end_date: payout_end_date) stripe_connect_revenue_by_product = @user.stripe_connect_revenue_by_product_for_duration(start_date: payout_start_date, end_date: payout_end_date) @revenue_by_link = if payment_revenue_by_link.present? && paypal_revenue_by_product.present? payment_revenue_by_link.merge!(paypal_revenue_by_product) { |_link_id, payment_revenue, paypal_revenue| payment_revenue + paypal_revenue } elsif payment_revenue_by_link.present? payment_revenue_by_link elsif paypal_revenue_by_product.present? paypal_revenue_by_product else nil end if stripe_connect_revenue_by_product.present? @revenue_by_link = @revenue_by_link.merge!(stripe_connect_revenue_by_product) { |_link_id, payment_revenue, stripe_connect_revenue| payment_revenue + stripe_connect_revenue } end @revenue_by_link = @revenue_by_link.sort_by { |_link_id, revenue_cents| revenue_cents.to_i }.reverse if @revenue_by_link paypal_sales_data = @user.paypal_sales_data_for_duration(start_date: payout_start_date, end_date: payout_end_date) @paypal_payout_amount_cents = @user.paypal_payout_net_cents(paypal_sales_data) stripe_connect_sales_data = @user.stripe_connect_sales_data_for_duration(start_date: payout_start_date, end_date: payout_end_date) @stripe_connect_payout_amount_cents = @user.stripe_connect_payout_net_cents(stripe_connect_sales_data) @affiliate_credit_cents = @user.affiliate_credit_cents_for_balances(@payment.balances.pluck(:id)) mail( from: from_email_address_with_name(@user.name, "noreply@#{CUSTOMERS_MAIL_DOMAIN}"), to: email, subject: "It's pay day!", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @user) ) end def subscription_autocancelled(subscription_id) @subscription = Subscription.find(subscription_id) @subject = if @subscription.is_installment_plan? "Your installment plan has been paused." else "Your subscription has been canceled." end end def subscription_cancelled(subscription_id) @subscription = Subscription.find(subscription_id) @subject = "Your subscription has been canceled." end def subscription_cancelled_by_seller(subscription_id) @subscription = Subscription.find(subscription_id) @subject = if @subscription.is_installment_plan? "Your installment plan has been canceled." else "Your subscription has been canceled." end end def subscription_card_declined(subscription_id) @subscription = Subscription.find(subscription_id) @declined = true @subject = "Your card was declined." end def subscription_card_declined_warning(subscription_id) @subscription = Subscription.find(subscription_id) @declined = true @subject = "Your card was declined." end def subscription_charge_failed(subscription_id) @subscription = Subscription.find(subscription_id) @subject = if @subscription.is_installment_plan? "Your installment payment failed." else "Your recurring charge failed." end end def subscription_product_deleted(subscription_id) @subscription = Subscription.find(subscription_id) @subject = if @subscription.is_installment_plan? "Your installment plan has been canceled." else "Your subscription has been canceled." end end def subscription_ended(subscription_id) @subscription = Subscription.find(subscription_id) @subject = if @subscription.is_installment_plan? "Your installment plan has been paid in full." else "Your subscription has ended." end end def subscription_renewal_reminder(subscription_id) @subscription = Subscription.find(subscription_id) @subject = if @subscription.is_installment_plan? "Upcoming installment payment reminder" else "Upcoming automatic membership renewal" end @date = @subscription.end_time_of_subscription.strftime("%B %e, %Y") @price = @subscription.original_purchase.formatted_total_price @delivery_options = { reply_to: @subscription.seller.support_or_form_email } end def subscription_price_change_notification(subscription_id:, email: nil, new_price:) @subscription = Subscription.find(subscription_id) @email = email @subject = "Important changes to your membership" effective_date = @subscription.tier.subscription_price_change_effective_date @effective_date = effective_date.strftime("%B %e, %Y") @product = @subscription.link @message = @subscription.tier.subscription_price_change_message || "The price of your membership to \"#{@product.name}\" " + (effective_date < Time.current.to_date ? "changed on #{@effective_date}.<br /><br />You will be charged the new price starting with your next billing period." : "is changing on #{@effective_date}.<br /><br />" ) + "You can modify or cancel your membership at any time." @next_payment_date = @subscription.end_time_of_subscription.strftime("%B %e, %Y") original_purchase = @subscription.original_purchase @previous_price = original_purchase.format_price_in_currency(original_purchase.displayed_price_cents) @new_price = original_purchase.format_price_in_currency(new_price) if original_purchase.has_tax_label? @previous_price += " (plus taxes)" @new_price += " (plus taxes)" end @payment_method = original_purchase.card_type.present? && original_purchase.card_visual.present? ? "#{original_purchase.card_type.upcase} *#{original_purchase.card_visual.delete("*").delete(" ")}" : nil @seller_name = original_purchase.seller.display_name @delivery_options = { reply_to: @subscription.seller.support_or_form_email } end def sample_subscription_price_change_notification(user:, tier:, effective_date:, recurrence:, new_price:, custom_message: nil) @effective_date = effective_date.strftime("%B %e, %Y") @product = tier.link @message = custom_message || tier.subscription_price_change_message || "The price of your membership to \"#{@product.name}\" " + (effective_date < Time.current.to_date ? "changed on #{@effective_date}.<br /><br />You will be charged the new price starting with your next billing period." : "is changing on #{@effective_date}.<br /><br />" ) + "You can modify or cancel your membership at any time." @next_payment_date = (effective_date + 4.days).to_date.strftime("%B %e, %Y") charge_occurrence_count = tier.link.duration_in_months.present? ? tier.link.duration_in_months / BasePrice::Recurrence.number_of_months_in_recurrence(recurrence) : nil @previous_price = formatted_price_in_currency_with_recurrence(new_price * 0.8, tier.link.price_currency_type, recurrence, charge_occurrence_count) @new_price = formatted_price_in_currency_with_recurrence(new_price, tier.link.price_currency_type, recurrence, charge_occurrence_count) @payment_method = "VISA *1234" seller = tier.link.user @seller_name = seller.display_name @edit_card_url = "#" mail to: user.email, subject: "Important changes to your membership", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller:), reply_to: seller.support_or_form_email, template_name: "subscription_price_change_notification" end def subscription_early_fraud_warning_notification(purchase_id) @purchase = Purchase.find(purchase_id) @subscription = @purchase.subscription @product = @subscription.link @price = @subscription.original_purchase.formatted_total_price @purchase_date = @purchase.created_at.to_fs(:formatted_date_abbrev_month) @subject = "Regarding your recent purchase reported as fraud" @delivery_options = { reply_to: @subscription.seller.support_or_form_email } end def subscription_giftee_added_card(subscription_id) @subscription = Subscription.find(subscription_id) chargeable = @subscription.purchases.is_gift_receiver_purchase.first original_purchase = @subscription.original_purchase credit_card = @subscription.credit_card card_visual = "#{credit_card.card_type.upcase} *#{credit_card.visual.delete("*").delete(" ")}" @receipt_presenter = ReceiptPresenter.new(chargeable, for_email: true) @attributes = [ { label: "Membership", value: original_purchase.formatted_total_price }, { label: "First payment", value: @subscription.formatted_end_time_of_subscription }, { label: "Payment method", value: card_visual } ] @subject = "You've added a payment method to your membership" @delivery_options = { reply_to: @subscription.seller.support_or_form_email } end def rental_expiring_soon(purchase_id, time_till_rental_expiration_in_seconds) purchase = Purchase.find(purchase_id) return unless EmailFormatValidator.valid?(purchase.email) url_redirect = purchase.url_redirect if time_till_rental_expiration_in_seconds > 1.day expires_in = pluralize(time_till_rental_expiration_in_seconds / 1.day, "day") else expires_in = pluralize(time_till_rental_expiration_in_seconds / 1.hour, "hour") end @subject = "Your rental will expire in #{expires_in}" @content = "<p>Hey there,</p><p>Your rental of #{purchase.link.name} will expire in #{expires_in}. After that, you'll have to rent the title again to watch it. Don't miss out!</p>".html_safe @watch_url = url_redirect.download_page_url mail( to: purchase.email, reply_to: "noreply@#{CUSTOMERS_MAIL_DOMAIN}", subject: @subject, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: purchase.seller) ) end def preorder_card_declined(preorder_id) @preorder = Preorder.find_by(id: preorder_id) @preorder_link = @preorder.preorder_link @product = @preorder_link.link authorization_purchase = @preorder.authorization_purchase return unless EmailFormatValidator.valid?(authorization_purchase.email) mail( to: authorization_purchase.email, from: "Gumroad <noreply@#{CUSTOMERS_MAIL_DOMAIN}>", reply_to: [@product.user.email, "Gumroad <noreply@#{CUSTOMERS_MAIL_DOMAIN}>"], subject: "Could not charge your credit card for #{@product.name}", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @product.user) ) end def preorder_cancelled(preorder_id) @preorder = Preorder.find_by(id: preorder_id) authorization_purchase = @preorder.authorization_purchase return unless EmailFormatValidator.valid?(authorization_purchase.email) mail( to: authorization_purchase.email, subject: "Your pre-order has been canceled.", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @preorder.preorder_link.link.user) ) end def order_shipped(shipment_id) @shipment = Shipment.find(shipment_id) purchase = @shipment.purchase return unless EmailFormatValidator.valid?(purchase.email) @product = purchase.link @tracking_url = @shipment.calculated_tracking_url mail( to: purchase.email, reply_to: @product.user.support_or_form_email, subject: "Your order has shipped!", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @product.user) ) end def chargeback_notice_to_customer(dispute_id) dispute = Dispute.find(dispute_id) @disputable = dispute.disputable mail( to: @disputable.purchase_for_dispute_evidence.email, subject: "Regarding your recent dispute.", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @disputable.purchase_for_dispute_evidence.seller) ) end # Specific email that is sent in case this credit card is tied to a membership. # @param subscription_id [Integer] def credit_card_expiring_membership(subscription_id) @subscription = Subscription.find(subscription_id) credit_card = @subscription.credit_card @last_4_digits_of_credit_card = credit_card.last_four_digits @expiry_month_name = Date::MONTHNAMES[credit_card.expiry_month] @product = @subscription.link @subject = "Payment method for #{@product.name} is about to expire" end def free_trial_expiring_soon(subscription_id) @subscription = Subscription.find(subscription_id) @subject = "Your free trial is ending soon" end def bundle_content_updated(purchase_id) @purchase = Purchase.find(purchase_id) @product_name = @purchase.link.name @seller_name = @purchase.seller.name_or_username @title = "#{@seller_name} just added content to #{@product_name}" mail( to: @purchase.email, subject: @title, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @purchase.seller) ) end def purchase_review_reminder(purchase_id) @purchase = Purchase.find(purchase_id) return if @purchase.product_review.present? || @purchase.purchaser&.opted_out_of_review_reminders? @product_name = @purchase.link.name @title = "Liked #{@product_name}? Give it a review!" @unsub_link = user_unsubscribe_review_reminders_url if @purchase.purchaser @purchaser_name = @purchase.full_name.presence || @purchase.purchaser&.name&.presence @review_url = if @purchase.is_bundle_purchase? library_url(bundles: @purchase.link.external_id) else @purchase.url_redirect&.download_page_url || @purchase.link.long_url end mail( to: @purchase.email, subject: @title, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @purchase.seller) ) end def order_review_reminder(order_id) order = Order.find(order_id) purchaser = order.purchaser return if purchaser&.opted_out_of_review_reminders? first_purchase = order.purchases.first @title = "Liked your order? Leave some reviews!" @unsub_link = user_unsubscribe_review_reminders_url if purchaser @purchaser_name = first_purchase.full_name.presence || purchaser&.name&.presence @review_url = reviews_url email = purchaser&.email || first_purchase.email mail( to: email, subject: @title, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: first_purchase.seller) ) end def wishlist_updated(wishlist_follower_id, product_count) @wishlist_follower = WishlistFollower.find(wishlist_follower_id) return if @wishlist_follower.deleted? @title = "#{@wishlist_follower.wishlist.user.name_or_username} recently added #{product_count == 1 ? "a new product" : "#{product_count} new products"} to their wishlist!" @footer_template = "customer_low_priority_mailer/wishlist_updated_footer" @wishlist_url = wishlist_url(@wishlist_follower.wishlist.url_slug, host: @wishlist_follower.wishlist.user.subdomain_with_protocol) @thumbnail_products = @wishlist_follower.wishlist.wishlist_products.alive.order(created_at: :desc).first(4).map(&:product) mail( to: @wishlist_follower.follower_user.email, subject: @title, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @wishlist_follower.wishlist.user) ) end private def deliver_subscription_email query_params = { token: @subscription.refresh_token } query_params[:declined] = true if @declined @edit_card_url = manage_subscription_url(@subscription.external_id, query_params) options = { to: @subscription.email, subject: @subject, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @subscription.original_purchase.seller) }.merge(@delivery_options || {}) mail options end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/accounting_mailer.rb
app/mailers/accounting_mailer.rb
# frozen_string_literal: true require "csv" class AccountingMailer < ApplicationMailer SUBJECT_PREFIX = ("[#{Rails.env}] " unless Rails.env.production?) default from: ADMIN_EMAIL_WITH_NAME layout "layouts/email" def funds_received_report(month, year) WithMaxExecutionTime.timeout_queries(seconds: 1.hour) do @report = FundsReceivedReports.funds_received_report(month, year) end report_csv = AdminFundsCsvReportService.new(@report).generate attachments["funds-received-report-#{month}-#{year}.csv"] = { data: report_csv } mail subject: "#{SUBJECT_PREFIX}Funds Received Report – #{month}/#{year}", to: PAYMENTS_EMAIL, cc: %w[solson@earlygrowthfinancialservices.com ndelgado@earlygrowthfinancialservices.com chhabra.harbaksh@gmail.com] end def deferred_refunds_report(month, year) @report = DeferredRefundsReports.deferred_refunds_report(month, year) report_csv = AdminFundsCsvReportService.new(@report).generate attachments["deferred-refunds-report-#{month}-#{year}.csv"] = { data: report_csv } mail subject: "#{SUBJECT_PREFIX}Deferred Refunds Report – #{month}/#{year}", to: PAYMENTS_EMAIL, cc: %w[solson@earlygrowthfinancialservices.com ndelgado@earlygrowthfinancialservices.com chhabra.harbaksh@gmail.com] end def stripe_currency_balances_report(balances_csv) last_month = Time.current.last_month month = last_month.month year = last_month.year attachments["stripe_currency_balances_#{month}_#{year}.csv"] = { data: ::Base64.encode64(balances_csv), encoding: "base64" } mail to: PAYMENTS_EMAIL, cc: %w[solson@earlygrowthfinancialservices.com chhabra.harbaksh@gmail.com], subject: "Stripe currency balances report for #{month}/#{year}" end def vat_report(vat_quarter, vat_year, s3_read_url) @subject_and_title = "VAT report for Q#{vat_quarter} #{vat_year}" @s3_url = s3_read_url mail subject: @subject_and_title, to: PAYMENTS_EMAIL, cc: %w[solson@earlygrowthfinancialservices.com chhabra.harbaksh@gmail.com] end def gst_report(country_code, quarter, year, s3_read_url) @country_name = ISO3166::Country[country_code].common_name @subject_and_title = "#{@country_name} GST report for Q#{quarter} #{year}" @s3_url = s3_read_url mail subject: @subject_and_title, to: PAYMENTS_EMAIL, cc: %w[solson@earlygrowthfinancialservices.com chhabra.harbaksh@gmail.com] end def payable_report(csv_url, year) @subject_and_title = "Payable report for year #{year} is ready to download" @csv_url = csv_url mail subject: @subject_and_title, to: %w[payments@gumroad.com chhabra.harbaksh@gmail.com] end def email_outstanding_balances_csv @balance_stats = { stripe: { held_by_gumroad: { active: 0, suspended: 0 }, held_by_stripe: { active: 0, suspended: 0 } }, paypal: { active: 0, suspended: 0 } } balances_csv = CSV.generate do |csv| csv << ["user id", "paypal balance (in dollars)", "stripe balance (in dollars)", "is_suspended", "user_risk_state", "tos_violation_reason"] User.holding_non_zero_balance.each do |user| stat_key = user.suspended? ? :suspended : :active if (user.payment_address.present? || user.has_paypal_account_connected?) && user.active_bank_account.nil? @balance_stats[:paypal][stat_key] += user.unpaid_balance_cents csv << [user.id, user.unpaid_balance_cents / 100.0, 0, user.suspended?, user.user_risk_state, user.tos_violation_reason] else balances = user.unpaid_balances balances_by_holder_of_funds = balances.group_by { |balance| balance.merchant_account.holder_of_funds } balances_held_by_gumroad = balances_by_holder_of_funds[HolderOfFunds::GUMROAD] || [] balances_held_by_stripe = balances_by_holder_of_funds[HolderOfFunds::STRIPE] || [] @balance_stats[:stripe][:held_by_gumroad][stat_key] += balances_held_by_gumroad.sum(&:amount_cents) @balance_stats[:stripe][:held_by_stripe][stat_key] += balances_held_by_stripe.sum(&:amount_cents) csv << [user.id, 0, user.unpaid_balance_cents / 100.0, user.suspended?, user.user_risk_state, user.tos_violation_reason] end end end attachments["outstanding_balances.csv"] = { data: ::Base64.encode64(balances_csv), encoding: "base64" } mail to: PAYMENTS_EMAIL, cc: %w[solson@earlygrowthfinancialservices.com ndelgado@earlygrowthfinancialservices.com], subject: "Outstanding balances" end def ytd_sales_report(csv_data, recipient_email) attachments["ytd_sales_by_country_state.csv"] = { data: ::Base64.encode64(csv_data), encoding: "base64" } mail(to: recipient_email, subject: "Year-to-Date Sales Report by Country/State") end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/community_chat_recap_mailer.rb
app/mailers/community_chat_recap_mailer.rb
# frozen_string_literal: true class CommunityChatRecapMailer < ApplicationMailer include ActionView::Helpers::TextHelper layout "layouts/email" default from: "noreply@#{CREATOR_CONTACTING_CUSTOMERS_MAIL_DOMAIN}" def community_chat_recap_notification(user_id, seller_id, community_chat_recap_ids) user = User.find(user_id) @seller = User.find(seller_id) @recaps = CommunityChatRecap.includes(community: :resource).where(id: community_chat_recap_ids) recap_run = @recaps.first.community_chat_recap_run @recap_frequency = recap_run.recap_frequency subject = "Your #{@recap_frequency} #{@seller.name.truncate(20)} community recap: #{humanized_duration(@recap_frequency, recap_run)}" mail( to: user.form_email, subject:, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :creators) ) end private def humanized_duration(recap_frequency, recap_run) if recap_frequency == "daily" recap_run.from_date.strftime("%B %-d, %Y") else # Example: "March 23-29, 2025" if recap_run.from_date.month == recap_run.to_date.month && recap_run.from_date.year == recap_run.to_date.year "#{recap_run.from_date.strftime("%B %-d")}-#{recap_run.to_date.strftime("%-d, %Y")}" # Example: "March 30-April 5, 2025" elsif recap_run.from_date.year == recap_run.to_date.year "#{recap_run.from_date.strftime("%B %-d")}-#{recap_run.to_date.strftime("%B %-d, %Y")}" # Example: "December 28, 2025-January 3, 2026" else "#{recap_run.from_date.strftime("%B %-d, %Y")}-#{recap_run.to_date.strftime("%B %-d, %Y")}" end end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/customer_mailer.rb
app/mailers/customer_mailer.rb
# frozen_string_literal: true class CustomerMailer < ApplicationMailer include CurrencyHelper helper CurrencyHelper helper PreorderHelper helper ProductsHelper helper ApplicationHelper layout "layouts/email", except: :send_to_kindle def grouped_receipt(purchase_ids) @chargeables = Purchase.where(id: purchase_ids).map { Charge::Chargeable.find_by_purchase_or_charge!(purchase: _1) }.uniq last_chargeable = @chargeables.last mail( to: last_chargeable.orderable.email, from: from_email_address_with_name(last_chargeable.seller.name, "noreply@#{CUSTOMERS_MAIL_DOMAIN}"), subject: "Receipts for Purchases", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers) ) end # Note that the first argument is purchase_id, while the 2nd is charge_id # charge_id needs to be passed to the mailer only when the initial customer order is placed (via SendChargeReceiptJob) # For duplicate receipts (post-purchase), the purchase_id is passed, and the mailer will determine if it should use the # purchase, or the charge associated (via Charge::Chargeable.find_by_purchase_or_charge!) # def receipt(purchase_id = nil, charge_id = nil, for_email: true) @chargeable = Charge::Chargeable.find_by_purchase_or_charge!( purchase: Purchase.find_by(id: purchase_id), charge: Charge.find_by(id: charge_id) ) @email_name = __method__ @receipt_presenter = ReceiptPresenter.new(@chargeable, for_email:) is_receipt_for_gift_receiver = receipt_for_gift_receiver?(@chargeable) @footer_template = "layouts/mailers/receipt_footer" unless is_receipt_for_gift_receiver mail( to: @chargeable.orderable.email, from: from_email_address_with_name(@chargeable.seller.name, "noreply@#{CUSTOMERS_MAIL_DOMAIN}"), reply_to: @chargeable.support_email, subject: @receipt_presenter.mail_subject, template_name: is_receipt_for_gift_receiver ? "gift_receiver_receipt" : "receipt", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @chargeable.seller) ) end def preorder_receipt(preorder_id, link_id = nil, email = nil) @email_name = __method__ if preorder_id.present? @preorder = Preorder.find_by(id: preorder_id) authorization_purchase = @preorder.authorization_purchase @product = @preorder.link email = authorization_purchase.email if @product.is_physical purchase = @preorder.authorization_purchase @shipping_info = { "full_name" => purchase.full_name, "street_address" => purchase.street_address, "city" => purchase.city, "zip_code" => purchase.zip_code, "state" => purchase.state, "country" => purchase.country } end else @product = Link.find(link_id) end mail( to: email, from: from_email_address_with_name(@product.user.name, "noreply@#{CUSTOMERS_MAIL_DOMAIN}"), reply_to: @product.support_email_or_default, subject: "You pre-ordered #{@product.name}!", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @product.user) ) end def refund(email, link_id, purchase_id) @product = Link.find(link_id) @purchase = purchase_id ? Purchase.find(purchase_id) : nil mail( to: email, from: from_email_address_with_name(@product.user.name, "noreply@#{CUSTOMERS_MAIL_DOMAIN}"), reply_to: @product.user.support_or_form_email, subject: "You have been refunded.", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @product.user) ) end def partial_refund(email, link_id, purchase_id, refund_amount_cents_usd, refund_type) @product = Link.find(link_id) @purchase = purchase_id ? Purchase.find(purchase_id) : nil amount_cents = usd_cents_to_currency(@product.price_currency_type, refund_amount_cents_usd, @purchase.rate_converted_to_usd) @formatted_refund_amount = formatted_price(@product.price_currency_type, amount_cents) @refund_type = refund_type mail( to: email, from: from_email_address_with_name(@product.user.name, "noreply@#{CUSTOMERS_MAIL_DOMAIN}"), reply_to: from_email_address_with_name(@product.user.name, @product.user.email), subject: "You have been #{@refund_type} refunded.", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @product.user) ) end def send_to_kindle(kindle_email, product_file_id) product_file = ProductFile.find(product_file_id) temp_file = Tempfile.new product_file.s3_object.download_file(temp_file.path) temp_file.rewind attachments[product_file.s3_filename] = temp_file.read # tell amazon to convert the pdf to kindle-readable format mail( to: kindle_email, from: "noreply@#{CUSTOMERS_MAIL_DOMAIN}", subject: "convert", delivery_method_options: MailerInfo.default_delivery_method_options(domain: :customers) ) end def paypal_purchase_failed(purchase_id) purchase = Purchase.find(purchase_id) @product = purchase.link mail( to: purchase.email, from: "noreply@#{CUSTOMERS_MAIL_DOMAIN}", subject: "Your purchase with PayPal failed.", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @product.user) ) end def subscription_restarted(subscription_id, reason = nil) @reason = reason @subscription = Subscription.find(subscription_id) @edit_card_url = manage_subscription_url(@subscription.external_id, token: @subscription.refresh_token) @purchase = @subscription.original_purchase @footer_template = "layouts/mailers/subscription_restarted_footer" seller = @subscription.link.user mail( to: @subscription.email, from: from_email_address_with_name(seller.name, "noreply@#{CUSTOMERS_MAIL_DOMAIN}"), reply_to: seller.support_or_form_email, subject: @subscription.is_installment_plan? ? "Your installment plan has been restarted." : "Your subscription has been restarted.", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @purchase.seller) ) end def subscription_magic_link(subscription_id, email) @subscription = Subscription.find(subscription_id) return unless EmailFormatValidator.valid?(email) mail( to: email, subject: "Magic Link" ) end def abandoned_cart_preview(recipient_id, installment_id) user = User.find(recipient_id) installment = Installment.find(installment_id) @installments = [{ subject: installment.subject, message: installment.message_with_inline_abandoned_cart_products(products: installment.workflow.abandoned_cart_products) }] mail(to: user.email, subject: installment.subject) do |format| format.html { render :abandoned_cart } end end # `workflow_ids_with_product_ids` is a hash of { workflow_id.to_s => product_ids } def abandoned_cart(cart_id, workflow_ids_with_product_ids, is_preview = false) cart = Cart.find(cart_id) return if !cart.abandoned? return if cart.email.blank? && cart.user&.email.blank? workflows = Workflow.where(id: workflow_ids_with_product_ids.keys).abandoned_cart_type.published.includes(:alive_installments) @installments = workflows.filter_map do |workflow| installment = workflow.alive_installments.sole products = workflow.abandoned_cart_products.select do |product| workflow_ids_with_product_ids[workflow.id.to_s].include?(ObfuscateIds.decrypt(product[:external_id])) end next if products.empty? { id: installment.id, subject: installment.subject, message: installment.message_with_inline_abandoned_cart_products(products:, checkout_url: checkout_index_url(host: UrlService.domain_with_protocol, cart_id: cart.external_id)) } end return if @installments.empty? @installments.each do |installment| SentAbandonedCartEmail.create!(cart_id: cart.id, installment_id: installment[:id]) rescue ActiveRecord::RecordNotUnique # NoOp end unless is_preview subject = @installments.one? ? @installments.first[:subject] : "You left something in your cart" mail( to: cart.user&.email.presence || cart.email, subject:, from: "Gumroad <noreply@#{CUSTOMERS_MAIL_DOMAIN}>", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers) ) end def review_response(review_response) review = review_response.product_review @review_presenter = ProductReviewPresenter.new(review).product_review_props @product = review.link seller = @product.user @seller_presenter = UserPresenter.new(user: seller).author_byline_props mail( to: review.purchase.email, subject: "#{@seller_presenter[:name]} responded to your review", from: from_email_address_with_name(seller.name, "noreply@#{CUSTOMERS_MAIL_DOMAIN}"), reply_to: seller.support_or_form_email, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers) ) end def upcoming_call_reminder(call_id) @purchase = Call.find(call_id).purchase @subject = "Your scheduled call with #{@purchase.seller.display_name} is tomorrow!" @item_info = ReceiptPresenter::ItemInfo.new(@purchase) mail(to: @purchase.email, subject: @subject) end def files_ready_for_download(purchase_id) @purchase = Purchase.find(purchase_id) @product = @purchase.link @url_redirect = @purchase.url_redirect mail( to: @purchase.email, from: from_email_address_with_name(@product.user.name, "noreply@#{CUSTOMERS_MAIL_DOMAIN}"), reply_to: @product.support_email_or_default, subject: "Your files are ready for download!", delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @product.user) ) end private def receipt_for_gift_receiver?(chargeable) chargeable.orderable.receipt_for_gift_receiver? rescue NotImplementedError false end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/affiliate_request_mailer.rb
app/mailers/affiliate_request_mailer.rb
# frozen_string_literal: true class AffiliateRequestMailer < ApplicationMailer layout "layouts/email" default from: "noreply@#{CUSTOMERS_MAIL_DOMAIN}" def notify_requester_of_request_submission(affiliate_request_id) @affiliate_request = AffiliateRequest.find(affiliate_request_id) @subject = "Your application request to #{@affiliate_request.seller.display_name} was submitted!" @requester_has_existing_account = User.exists?(email: @affiliate_request.email) mail to: @affiliate_request.email, subject: @subject, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @affiliate_request.seller) end def notify_requester_of_request_approval(affiliate_request_id) @affiliate_request = AffiliateRequest.find(affiliate_request_id) requester = User.find_by!(email: @affiliate_request.email) @affiliated_products = requester .directly_affiliated_products .select("name, custom_permalink, unique_permalink, affiliates.id AS affiliate_id, COALESCE(affiliates_links.affiliate_basis_points, affiliates.affiliate_basis_points) AS basis_points") .where(affiliates: { seller_id: @affiliate_request.seller.id }) .map do |affiliated_product| direct_affiliate = DirectAffiliate.new(id: affiliated_product.affiliate_id, affiliate_basis_points: affiliated_product.basis_points) { name: affiliated_product.name, url: direct_affiliate.referral_url_for_product(affiliated_product), commission: "#{direct_affiliate.affiliate_percentage}%" } end @subject = "Your affiliate request to #{@affiliate_request.seller.display_name} was approved!" mail to: @affiliate_request.email, subject: @subject, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @affiliate_request.seller) end def notify_requester_of_ignored_request(affiliate_request_id) @affiliate_request = AffiliateRequest.find(affiliate_request_id) @subject = "Your affiliate request to #{@affiliate_request.seller.display_name} was not approved" mail to: @affiliate_request.email, subject: @subject, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @affiliate_request.seller) end def notify_unregistered_requester_of_request_approval(affiliate_request_id) @affiliate_request = AffiliateRequest.find(affiliate_request_id) @subject = "Your affiliate request to #{@affiliate_request.seller.display_name} was approved!" mail to: @affiliate_request.email, subject: @subject, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @affiliate_request.seller) end def notify_seller_of_new_request(affiliate_request_id) @affiliate_request = AffiliateRequest.find(affiliate_request_id) @subject = "#{@affiliate_request.name} has applied to be an affiliate" mail to: @affiliate_request.seller.email, subject: @subject, delivery_method_options: MailerInfo.random_delivery_method_options(domain: :customers, seller: @affiliate_request.seller) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/invite_mailer.rb
app/mailers/invite_mailer.rb
# frozen_string_literal: true class InviteMailer < ApplicationMailer layout "layouts/email" def receiver_signed_up(invite_id) @invite = Invite.find(invite_id) @sender = User.find(@invite.sender_id) @receiver = User.find(@invite.receiver_id) @subject = if @receiver.name.present? "#{@receiver.name} has joined Gumroad, thanks to you." else "A creator you invited has joined Gumroad." end deliver_email(to: @sender.form_email) end private def deliver_email(to:) return if to.blank? mail to:, subject: @subject end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/affiliate_mailer.rb
app/mailers/affiliate_mailer.rb
# frozen_string_literal: true class AffiliateMailer < ApplicationMailer include NotifyOfSaleHeaders include ActionView::Helpers::TextHelper include BasePrice::Recurrence layout "layouts/email" COLLABORATOR_MAX_PRODUCTS = 5 def direct_affiliate_invitation(affiliate_id, prevent_sending_invitation_email_to_seller = false) @direct_affiliate = DirectAffiliate.find_by(id: affiliate_id) @seller = @direct_affiliate.seller @seller_name = @direct_affiliate.seller.name_or_username @products = @direct_affiliate.enabled_products .sort_by { -_1[:fee_percent] } product = @products.first @product_name = @products.one? ? product[:name] : pluralize(@direct_affiliate.products.count, "product") @affiliate_percentage_text = if @products.many? && @products.first[:fee_percent] != @products.last[:fee_percent] "#{@products.last[:fee_percent]} - #{product[:fee_percent]}%" else "#{product[:fee_percent]}%" end @affiliate_referral_url = affiliate_referral_url @final_destination_url = @products.one? ? product[:destination_url] : @direct_affiliate.final_destination_url @subject = "#{@seller_name} has added you as an affiliate." params = { to: @direct_affiliate.affiliate_user.form_email, subject: @subject } params[:cc] = @seller.form_email unless prevent_sending_invitation_email_to_seller mail params end def notify_affiliate_of_sale(purchase_id) @purchase = Purchase.find(purchase_id) @affiliate = @purchase.affiliate if @affiliate.collaborator? notify_collaborator_of_sale else @affiliate_percentage_text = "#{@affiliate.basis_points(product_id: @purchase.link_id) / 100}%" @purchase_price_formatted = MoneyFormatter.format(@purchase.price_cents, :usd, no_cents_if_whole: true, symbol: true) @affiliate_amount_formatted = MoneyFormatter.format(@purchase.affiliate_credit_cents, :usd, no_cents_if_whole: true, symbol: true) @free_trial_end_date = @purchase.link.is_tiered_membership? ? @purchase.subscription.free_trial_end_date_formatted : nil @recurring_commission_text = @purchase.is_original_subscription_purchase? ? "You'll continue to receive a commission once #{recurrence_long_indicator(@purchase.subscription.recurrence)} as long as the subscription is active." : nil if @affiliate.global? notify_global_affiliate_of_sale else notify_direct_affiliate_of_sale end end end def notify_direct_affiliate_of_updated_products(affiliate_id) @direct_affiliate = DirectAffiliate.find(affiliate_id) @products = @direct_affiliate.enabled_products .sort_by { -_1[:fee_percent] } seller_name = @direct_affiliate.seller.name_or_username @subject = "#{seller_name} just updated your affiliated products" mail to: @direct_affiliate.affiliate_user.form_email, subject: @subject end def notify_direct_affiliate_of_new_product(affiliate_id, product_id) @direct_affiliate = DirectAffiliate.find(affiliate_id) @seller_name = @direct_affiliate.seller.name_or_username product = Link.find(product_id) @product_name = product.name @affiliate_percentage_text = "#{@direct_affiliate.basis_points(product_id:) / 100}%" @affiliate_referral_url = @direct_affiliate.referral_url_for_product(product) @subject = "#{@seller_name} has added you as an affiliate to #{@product_name}." mail to: @direct_affiliate.affiliate_user.form_email, subject: @subject end def direct_affiliate_removal(affiliate_id) @direct_affiliate = DirectAffiliate.find_by(id: affiliate_id) @seller = @direct_affiliate.seller @seller_name = @direct_affiliate.seller.name_or_username @subject = "#{@seller_name} just updated your affiliate status" mail to: @direct_affiliate.affiliate_user.form_email, cc: @seller.form_email, subject: @subject end def collaborator_creation(collaborator_id) @collaborator = Collaborator.find(collaborator_id) @seller = @collaborator.seller @subject = "#{@collaborator.seller.name_or_username} has added you as a collaborator on Gumroad" @max_products = COLLABORATOR_MAX_PRODUCTS mail to: @collaborator.affiliate_user.form_email, cc: @seller.form_email, subject: @subject end def collaborator_update(collaborator_id) @collaborator = Collaborator.find(collaborator_id) @seller = @collaborator.seller @subject = "#{@collaborator.seller.name_or_username} has updated your collaborator status on Gumroad" @max_products = COLLABORATOR_MAX_PRODUCTS mail to: @collaborator.affiliate_user.form_email, cc: @seller.form_email, subject: @subject end def collaboration_ended_by_seller(collaborator_id) @collaborator = Collaborator.find(collaborator_id) @seller = @collaborator.seller @seller_name = @collaborator.seller.name_or_username @subject = "#{@seller_name} just updated your collaborator status" mail to: @collaborator.affiliate_user.form_email, cc: @seller.form_email, subject: @subject end alias_method :collaborator_removal, :collaboration_ended_by_seller def collaboration_ended_by_affiliate_user(collaborator_id) @collaborator = Collaborator.find(collaborator_id) @affiliate_user = @collaborator.affiliate_user @affiliate_user_name = @affiliate_user.name_or_username @seller = @collaborator.seller @subject = "#{@affiliate_user_name} has ended your collaboration" mail to: @seller.form_email, cc: @affiliate_user.form_email, subject: @subject end def collaborator_invited(collaborator_id) @collaborator = Collaborator.find(collaborator_id) @inviter = @collaborator.seller inviter_name = @inviter.name_or_username invitee = @collaborator.affiliate_user @max_products = COLLABORATOR_MAX_PRODUCTS @subject = "#{inviter_name} has invited you to collaborate on Gumroad" mail to: invitee.form_email, cc: @inviter.form_email, subject: @subject end def collaborator_invitation_accepted(collaborator_id) collaborator = Collaborator.find(collaborator_id) inviter = collaborator.seller @invitee = collaborator.affiliate_user invitee_name = @invitee.name_or_username @subject = "#{invitee_name} has accepted your invitation to collaborate on Gumroad" mail to: inviter.form_email, subject: @subject end def collaborator_invitation_declined(collaborator_id) collaborator = Collaborator.find(collaborator_id) inviter = collaborator.seller @invitee = collaborator.affiliate_user invitee_name = @invitee.name_or_username @subject = "#{invitee_name} has declined your invitation to collaborate on Gumroad" mail to: inviter.form_email, subject: @subject end private def notify_direct_affiliate_of_sale @seller = @purchase.seller @seller_name = @seller.name_or_username @product_name = @purchase.link.name @customer_email = @purchase.email @subject = "You helped #{@seller_name} make a sale." mail to: @affiliate.affiliate_user.form_email, subject: @subject, template_name: "notify_direct_affiliate_of_sale" end def notify_global_affiliate_of_sale @subject = "🎉 You earned a commission!" @seller_name = @purchase.seller.name_or_username @product_name = @purchase.link.name mail to: @affiliate.affiliate_user.form_email, subject: @subject, template_name: "notify_global_affiliate_of_sale" end def notify_collaborator_of_sale @product = @purchase.link @is_preorder = @purchase.is_preorder_authorization @quantity = @purchase.quantity @variants = @purchase.variants_list @variants_count = @purchase.variant_names&.count || 0 @cut = MoneyFormatter.format(@purchase.affiliate_credit_cents + @purchase.affiliate_credit.fee_cents, :usd, no_cents_if_whole: true, symbol: true) @subject = "You made a sale!" set_notify_of_sale_headers(is_preorder: @is_preorder) mail to: @affiliate.affiliate_user.form_email, subject: @subject, template_name: "notify_collaborator_of_sale" end def affiliate_referral_url @direct_affiliate.products.count == 1 && @direct_affiliate.destination_url.blank? ? @direct_affiliate.referral_url_for_product(@direct_affiliate.products.first) : @direct_affiliate.referral_url end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/team_mailer.rb
app/mailers/team_mailer.rb
# frozen_string_literal: true class TeamMailer < ApplicationMailer include ActionView::Helpers::SanitizeHelper layout "layouts/email" def invite(team_invitation) @team_invitation = team_invitation @seller = team_invitation.seller @seller_name = sanitize(team_invitation.seller.display_name) @seller_email = team_invitation.seller.email @seller_username = team_invitation.seller.username @subject = "#{@seller_name} has invited you to join #{@seller_username}" mail( from: NOREPLY_EMAIL_WITH_NAME, to: @team_invitation.email, reply_to: @seller.email, subject: @subject ) end def invitation_accepted(team_membership) @team_membership = team_membership @user = team_membership.user @seller = team_membership.seller @user_name = sanitize(@user.display_name(prefer_email_over_default_username: true)) @subject = "#{@user_name} has accepted your invitation" mail( from: NOREPLY_EMAIL_WITH_NAME, to: @seller.email, reply_to: @user.email, subject: @subject ) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/concerns/custom_mailer_route_builder.rb
app/mailers/concerns/custom_mailer_route_builder.rb
# frozen_string_literal: true module CustomMailerRouteBuilder extend ActiveSupport::Concern def build_mailer_post_route(post:, purchase: nil) return unless post.shown_on_profile? && post.slug.present? user = post.user if user.custom_domain.present? custom_domain_view_post_url( slug: post.slug, purchase_id: purchase&.external_id, host: user.custom_domain.domain ) else view_post_url( username: user.username.presence || user.external_id, slug: post.slug, purchase_id: purchase&.external_id, host: UrlService.domain_with_protocol ) end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/concerns/notify_of_sale_headers.rb
app/mailers/concerns/notify_of_sale_headers.rb
# frozen_string_literal: true module NotifyOfSaleHeaders extend ActiveSupport::Concern def set_notify_of_sale_headers(is_preorder:) formatted_price = @price || @purchase.try(:formatted_total_price) if @product.is_recurring_billing if @purchase.try(:is_upgrade_purchase) @mail_heading = @subject = "A subscriber has upgraded their subscription for #{@product.name} and was charged #{formatted_price}" elsif @purchase.try(:is_recurring_subscription_charge) @mail_heading = @subject = "New recurring charge for #{@product.name} of #{formatted_price}" else @mail_heading = @subject = "You have a new subscriber for #{@product.name} of #{formatted_price}" end elsif is_preorder @mail_heading = @subject = "New pre-order of #{@product.name} for #{formatted_price}" elsif @purchase.present? && @purchase.price_cents == 0 && !@product.is_physical @mail_heading = @subject = "New download of #{@product.name}" else @mail_heading = "You made a sale!" if formatted_price.present? @subject = "New sale of #{@product.name} for #{formatted_price}" else @subject = "New sale of #{@product.name}" end end @mail_subheading = \ if @purchase&.recommended_by == RecommendationType::GUMROAD_STAFF_PICKS_RECOMMENDATION "via Staff picks in <a href=\"#{UrlService.discover_domain_with_protocol}\" target=\"_blank\">Discover</a>".html_safe elsif @purchase&.recommended_by == RecommendationType::GUMROAD_MORE_LIKE_THIS_RECOMMENDATION "via More like this recommendations" elsif @purchase.try(:was_discover_fee_charged) "via <a href=\"#{UrlService.discover_domain_with_protocol}\" target=\"_blank\">Discover</a>".html_safe end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/mailers/concerns/rescue_smtp_errors.rb
app/mailers/concerns/rescue_smtp_errors.rb
# frozen_string_literal: true module RescueSmtpErrors extend ActiveSupport::Concern included do rescue_from ArgumentError do |exception| if exception.message.include? "SMTP To address may not be blank" Rails.logger.error "Mailer Error: #{exception.inspect}" else raise exception end end rescue_from Net::SMTPAuthenticationError, Net::SMTPSyntaxError do |exception| Rails.logger.error "Mailer Error: #{exception.inspect}" end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/channels/community_channel.rb
app/channels/community_channel.rb
# frozen_string_literal: true class CommunityChannel < ApplicationCable::Channel CREATE_CHAT_MESSAGE_TYPE = "create_chat_message" UPDATE_CHAT_MESSAGE_TYPE = "update_chat_message" DELETE_CHAT_MESSAGE_TYPE = "delete_chat_message" def subscribed return reject unless params[:community_id].present? return reject unless current_user.present? community = Community.find_by_external_id(params[:community_id]) return reject unless community.present? return reject unless CommunityPolicy.new(SellerContext.new(user: current_user, seller: current_user), community).show? stream_for "community_#{params[:community_id]}" end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/channels/user_channel.rb
app/channels/user_channel.rb
# frozen_string_literal: true class UserChannel < ApplicationCable::Channel LATEST_COMMUNITY_INFO_TYPE = "latest_community_info" def subscribed return reject unless current_user.present? stream_for "user_#{current_user.external_id}" end def receive(data) case data["type"] when LATEST_COMMUNITY_INFO_TYPE return reject unless data["community_id"].present? community = Community.find_by_external_id(data["community_id"]) return reject unless community.present? return reject unless CommunityPolicy.new(SellerContext.new(user: current_user, seller: current_user), community).show? broadcast_to( "user_#{current_user.external_id}", { type: LATEST_COMMUNITY_INFO_TYPE, data: CommunityPresenter.new(community:, current_user:).props }, ) end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/channels/application_cable/channel.rb
app/channels/application_cable/channel.rb
# frozen_string_literal: true module ApplicationCable class Channel < ActionCable::Channel::Base end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/app/channels/application_cable/connection.rb
app/channels/application_cable/connection.rb
# frozen_string_literal: true module ApplicationCable class Connection < ActionCable::Connection::Base rescue_from StandardError, with: :report_error delegate :session, to: :request identified_by :current_user def connect self.current_user = impersonated_user end private def impersonated_user user = find_verified_user return user unless user&.is_team_member? impersonated_user_id = $redis.get(RedisKey.impersonated_user(user.id)) return user unless impersonated_user_id.present? impersonated_user = User.alive.find_by(id: impersonated_user_id) return user unless impersonated_user&.account_active? impersonated_user end def find_verified_user user_key = session["warden.user.user.key"] user_id = user_key.is_a?(Array) ? user_key.first&.first : nil if user_id User.find_by(id: user_id) || reject_unauthorized_connection else reject_unauthorized_connection end end def report_error(e) Rails.logger.error("Error in ActionCable connection: #{e.message}") reject_unauthorized_connection end end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/docker/base/irbrc.rb
docker/base/irbrc.rb
# frozen_string_literal: true if ENV["RAILS_ENV"] == "production" original_prompt = IRB.conf[:PROMPT][:DEFAULT][:PROMPT_I] new_prompt = "\033[33mPRODUCTION \033[m" + original_prompt IRB.conf[:PROMPT][:DEFAULT][:PROMPT_I] = new_prompt end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds.rb
db/seeds.rb
# frozen_string_literal: true def seed_log(msg) puts msg unless Rails.env.test? end def load_seeds(file) seed_log "Applying seeds in: #{file}" load(file, true) end seed_log "Applying seeds for environment: #{Rails.env}" # Load common seeds. common_directory = __dir__ + "/seeds" Dir[File.join(common_directory, "*.rb")].sort.each { |file| load_seeds(file) } # Load environment specific seeds. # Each subdirectory can contain seeds for one or more environments. # The subdirectory name is an underscore delimited list of environment names it applies to. environment_dirs = Dir["#{common_directory}/*/"].sort environment_dirs.each do |environment_dir| environment_dir_name = File.basename(environment_dir) # If the directory name contains the environment, load seeds in that directory. Dir[File.join(environment_dir, "*.rb")].each { |file| load_seeds(file) } if /(^|_)#{Regexp.escape(Rails.env)}(_|$)/.match?(environment_dir_name) end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/schema.rb
db/schema.rb
# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # This file is the source Rails uses to define your schema when running `bin/rails # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to # be faster and is potentially less error prone than running all of your # migrations from scratch. Old migrations may fail to apply correctly if those # migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema[7.1].define(version: 2025_11_24_133549) do create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "name", limit: 191, null: false t.string "record_type", limit: 191, null: false t.bigint "record_id", null: false t.bigint "blob_id", null: false t.datetime "created_at", precision: nil, null: false t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end create_table "active_storage_blobs", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "key", limit: 191, null: false t.string "filename", limit: 191, null: false t.string "content_type", limit: 191 t.text "metadata" t.bigint "byte_size", null: false t.string "checksum", limit: 191 t.datetime "created_at", precision: nil, null: false t.string "service_name", null: false t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true end create_table "active_storage_variant_records", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "blob_id", null: false t.string "variation_digest", null: false t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true end create_table "admin_action_call_infos", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "controller_name", null: false t.string "action_name", null: false t.integer "call_count", default: 0, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["controller_name", "action_name"], name: "index_admin_action_call_infos_on_controller_name_and_action_name", unique: true end create_table "affiliate_credits", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "oauth_application_id" t.integer "basis_points" t.integer "amount_cents" t.integer "affiliate_user_id" t.integer "seller_id" t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.integer "purchase_id" t.integer "link_id" t.integer "affiliate_credit_success_balance_id" t.integer "affiliate_credit_chargeback_balance_id" t.integer "affiliate_credit_refund_balance_id" t.integer "affiliate_id" t.bigint "fee_cents", default: 0, null: false t.index ["affiliate_credit_chargeback_balance_id"], name: "idx_affiliate_credits_on_affiliate_credit_chargeback_balance_id" t.index ["affiliate_credit_refund_balance_id"], name: "index_affiliate_credits_on_affiliate_credit_refund_balance_id" t.index ["affiliate_credit_success_balance_id"], name: "index_affiliate_credits_on_affiliate_credit_success_balance_id" t.index ["affiliate_id"], name: "index_affiliate_credits_on_affiliate_id" t.index ["affiliate_user_id"], name: "index_affiliate_credits_on_affiliate_user_id" t.index ["link_id"], name: "index_affiliate_credits_on_link_id" t.index ["oauth_application_id"], name: "index_affiliate_credits_on_oauth_application_id" t.index ["purchase_id"], name: "index_affiliate_credits_on_purchase_id" t.index ["seller_id"], name: "index_affiliate_credits_on_seller_id" end create_table "affiliate_partial_refunds", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "amount_cents", default: 0 t.integer "purchase_id", null: false t.integer "total_credit_cents", default: 0 t.integer "affiliate_user_id" t.integer "seller_id" t.integer "affiliate_id" t.integer "balance_id" t.integer "affiliate_credit_id" t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil t.bigint "fee_cents", default: 0 t.index ["affiliate_credit_id"], name: "index_affiliate_partial_refunds_on_affiliate_credit_id" t.index ["affiliate_id"], name: "index_affiliate_partial_refunds_on_affiliate_id" t.index ["affiliate_user_id"], name: "index_affiliate_partial_refunds_on_affiliate_user_id" t.index ["balance_id"], name: "index_affiliate_partial_refunds_on_balance_id" t.index ["purchase_id"], name: "index_affiliate_partial_refunds_on_purchase_id" t.index ["seller_id"], name: "index_affiliate_partial_refunds_on_seller_id" end create_table "affiliate_requests", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "seller_id", null: false t.string "name", limit: 100, null: false t.string "email", null: false t.text "promotion_text", size: :medium, null: false t.string "locale", default: "en", null: false t.string "state" t.datetime "state_transitioned_at", precision: nil t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["seller_id"], name: "index_affiliate_requests_on_seller_id" end create_table "affiliates", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "seller_id" t.integer "affiliate_user_id" t.integer "affiliate_basis_points" t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil t.datetime "deleted_at", precision: nil t.integer "flags", default: 0, null: false t.string "destination_url", limit: 2083 t.string "type", null: false t.index ["affiliate_user_id"], name: "index_affiliates_on_affiliate_user_id" t.index ["seller_id"], name: "index_affiliates_on_seller_id" end create_table "affiliates_links", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "affiliate_id" t.integer "link_id" t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil t.integer "affiliate_basis_points" t.string "destination_url" t.bigint "flags", default: 0, null: false t.index ["affiliate_id"], name: "index_affiliates_links_on_affiliate_id" t.index ["link_id"], name: "index_affiliates_links_on_link_id" end create_table "asset_previews", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "link_id" t.string "guid" t.text "oembed" t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil t.datetime "deleted_at", precision: nil t.integer "position" t.string "unsplash_url" t.index ["deleted_at"], name: "index_asset_previews_on_deleted_at" t.index ["link_id"], name: "index_asset_previews_on_link_id" end create_table "audience_members", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "seller_id", null: false t.string "email", null: false t.json "details" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "customer", default: false, null: false t.boolean "follower", default: false, null: false t.boolean "affiliate", default: false, null: false t.integer "min_paid_cents" t.integer "max_paid_cents" t.datetime "min_created_at", precision: nil t.datetime "max_created_at", precision: nil t.datetime "min_purchase_created_at", precision: nil t.datetime "max_purchase_created_at", precision: nil t.datetime "follower_created_at", precision: nil t.datetime "min_affiliate_created_at", precision: nil t.datetime "max_affiliate_created_at", precision: nil t.index ["seller_id", "customer", "follower", "affiliate"], name: "idx_audience_on_seller_and_types" t.index ["seller_id", "email"], name: "index_audience_members_on_seller_id_and_email", unique: true t.index ["seller_id", "follower_created_at"], name: "idx_audience_on_seller_and_follower_created_at" t.index ["seller_id", "min_affiliate_created_at", "max_affiliate_created_at"], name: "idx_audience_on_seller_and_minmax_affiliate_created_at" t.index ["seller_id", "min_created_at", "max_created_at"], name: "idx_audience_on_seller_and_minmax_created_at" t.index ["seller_id", "min_paid_cents", "max_paid_cents"], name: "idx_audience_on_seller_and_minmax_paid_cents" t.index ["seller_id", "min_purchase_created_at", "max_purchase_created_at"], name: "idx_audience_on_seller_and_minmax_purchase_created_at" end create_table "australia_backtax_email_infos", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "user_id" t.string "email_name" t.datetime "sent_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["user_id"], name: "index_australia_backtax_email_infos_on_user_id" end create_table "backtax_agreements", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "user_id", null: false t.string "jurisdiction" t.string "signature" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.bigint "flags", default: 0, null: false t.index ["user_id"], name: "index_backtax_agreements_on_user_id" end create_table "backtax_collections", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "user_id", null: false t.bigint "backtax_agreement_id", null: false t.integer "amount_cents" t.integer "amount_cents_usd" t.string "currency" t.string "stripe_transfer_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["backtax_agreement_id"], name: "index_backtax_collections_on_backtax_agreement_id" t.index ["user_id"], name: "index_backtax_collections_on_user_id" end create_table "balance_transactions", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil t.integer "user_id" t.integer "merchant_account_id" t.integer "balance_id" t.integer "purchase_id" t.integer "dispute_id" t.integer "refund_id" t.integer "credit_id" t.datetime "occurred_at", precision: nil t.string "issued_amount_currency" t.integer "issued_amount_gross_cents" t.integer "issued_amount_net_cents" t.string "holding_amount_currency" t.integer "holding_amount_gross_cents" t.integer "holding_amount_net_cents" t.index ["balance_id"], name: "index_balance_transactions_on_balance_id" t.index ["credit_id"], name: "index_balance_transactions_on_credit_id" t.index ["dispute_id"], name: "index_balance_transactions_on_dispute_id" t.index ["merchant_account_id"], name: "index_balance_transactions_on_merchant_account_id" t.index ["purchase_id"], name: "index_balance_transactions_on_purchase_id" t.index ["refund_id"], name: "index_balance_transactions_on_refund_id" t.index ["user_id"], name: "index_balance_transactions_on_user_id" end create_table "balances", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "user_id" t.date "date" t.integer "amount_cents", default: 0 t.string "state" t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.integer "merchant_account_id", default: 1 t.string "currency", default: "usd" t.string "holding_currency", default: "usd" t.integer "holding_amount_cents", default: 0 t.index ["user_id", "merchant_account_id", "date"], name: "index_on_user_merchant_account_date" end create_table "bank_accounts", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "user_id" t.string "bank_number" t.binary "account_number" t.string "state" t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.string "account_number_last_four" t.string "account_holder_full_name" t.datetime "deleted_at", precision: nil t.string "type", default: "AchAccount" t.string "branch_code" t.string "account_type" t.string "stripe_bank_account_id" t.string "stripe_fingerprint" t.string "stripe_connect_account_id" t.string "country", limit: 191 t.integer "credit_card_id" t.index ["user_id"], name: "index_ach_accounts_on_user_id" end create_table "banks", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "routing_number" t.string "name" t.index ["routing_number"], name: "index_banks_on_routing_number" end create_table "base_variant_integrations", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "base_variant_id", null: false t.bigint "integration_id", null: false t.datetime "deleted_at", precision: nil t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["base_variant_id"], name: "index_base_variant_integrations_on_base_variant_id" t.index ["integration_id"], name: "index_base_variant_integrations_on_integration_id" end create_table "base_variants", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "variant_category_id" t.integer "price_difference_cents" t.string "name" t.integer "max_purchase_count" t.datetime "deleted_at", precision: nil t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil t.string "type", default: "Variant" t.integer "link_id" t.string "custom_sku" t.integer "flags", default: 0, null: false t.string "description" t.integer "position_in_category" t.boolean "customizable_price" t.date "subscription_price_change_effective_date" t.text "subscription_price_change_message", size: :long t.integer "duration_in_minutes" t.index ["link_id"], name: "index_base_variants_on_link_id" t.index ["variant_category_id"], name: "index_variants_on_variant_category_id" end create_table "base_variants_product_files", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "base_variant_id" t.integer "product_file_id" t.index ["base_variant_id"], name: "index_base_variants_product_files_on_base_variant_id" t.index ["product_file_id"], name: "index_base_variants_product_files_on_product_file_id" end create_table "base_variants_purchases", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "purchase_id" t.integer "base_variant_id" t.index ["base_variant_id"], name: "index_purchases_variants_on_variant_id" t.index ["purchase_id"], name: "index_purchases_variants_on_purchase_id" end create_table "blocked_customer_objects", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "seller_id", null: false t.string "object_type", null: false t.string "object_value", null: false t.string "buyer_email" t.datetime "blocked_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["buyer_email"], name: "index_blocked_customer_objects_on_buyer_email" t.index ["seller_id", "object_type", "object_value"], name: "idx_blocked_customer_objects_on_seller_and_object_type_and_value", unique: true t.index ["seller_id"], name: "index_blocked_customer_objects_on_seller_id" end create_table "bundle_product_purchases", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "bundle_purchase_id", null: false t.bigint "product_purchase_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["bundle_purchase_id"], name: "index_bundle_product_purchases_on_bundle_purchase_id" t.index ["product_purchase_id"], name: "index_bundle_product_purchases_on_product_purchase_id" end create_table "bundle_products", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "bundle_id", null: false t.bigint "product_id", null: false t.bigint "variant_id" t.integer "quantity", null: false t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "position" t.index ["bundle_id"], name: "index_bundle_products_on_bundle_id" t.index ["product_id"], name: "index_bundle_products_on_product_id" t.index ["variant_id"], name: "index_bundle_products_on_variant_id" end create_table "cached_sales_related_products_infos", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "product_id", null: false t.json "counts" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["product_id"], name: "index_cached_sales_related_products_infos_on_product_id", unique: true end create_table "call_availabilities", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "call_id", null: false t.datetime "start_time" t.datetime "end_time" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["call_id"], name: "index_call_availabilities_on_call_id" end create_table "call_limitation_infos", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "call_id", null: false t.integer "minimum_notice_in_minutes" t.integer "maximum_calls_per_day" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["call_id"], name: "index_call_limitation_infos_on_call_id" end create_table "calls", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "purchase_id" t.string "call_url", limit: 1024 t.datetime "start_time" t.datetime "end_time" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "google_calendar_event_id" t.index ["purchase_id"], name: "index_calls_on_purchase_id" end create_table "cart_products", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "cart_id", null: false t.bigint "product_id", null: false t.bigint "option_id" t.bigint "affiliate_id" t.bigint "accepted_offer_id" t.bigint "price", null: false t.integer "quantity", null: false t.string "recurrence" t.string "recommended_by" t.boolean "rent", default: false, null: false t.json "url_parameters" t.text "referrer", size: :long, null: false t.string "recommender_model_name" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.datetime "deleted_at" t.datetime "call_start_time" t.json "accepted_offer_details" t.boolean "pay_in_installments", default: false, null: false t.index ["cart_id", "product_id", "deleted_at"], name: "index_cart_products_on_cart_id_and_product_id_and_deleted_at", unique: true t.index ["cart_id"], name: "index_cart_products_on_cart_id" t.index ["deleted_at", "cart_id"], name: "index_cart_products_on_deleted_at_and_cart_id" t.index ["product_id"], name: "index_cart_products_on_product_id" end create_table "carts", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "user_id" t.bigint "order_id" t.text "return_url", size: :long t.json "discount_codes" t.boolean "reject_ppp_discount", default: false, null: false t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "email" t.string "browser_guid" t.string "ip_address" t.index ["browser_guid"], name: "index_carts_on_browser_guid" t.index ["created_at"], name: "index_carts_on_created_at" t.index ["deleted_at", "updated_at"], name: "index_carts_on_deleted_at_and_updated_at" t.index ["email"], name: "index_carts_on_email" t.index ["order_id"], name: "index_carts_on_order_id" t.index ["updated_at"], name: "index_carts_on_updated_at" t.index ["user_id"], name: "index_carts_on_user_id" end create_table "charge_purchases", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "charge_id", null: false t.bigint "purchase_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["charge_id"], name: "index_charge_purchases_on_charge_id" t.index ["purchase_id"], name: "index_charge_purchases_on_purchase_id" end create_table "charges", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "order_id", null: false t.bigint "seller_id", null: false t.string "processor" t.string "processor_transaction_id" t.string "payment_method_fingerprint" t.bigint "credit_card_id" t.bigint "merchant_account_id" t.bigint "amount_cents" t.bigint "gumroad_amount_cents" t.bigint "processor_fee_cents" t.string "processor_fee_currency" t.string "paypal_order_id" t.string "stripe_payment_intent_id" t.string "stripe_setup_intent_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.datetime "disputed_at" t.datetime "dispute_reversed_at" t.bigint "flags", default: 0, null: false t.index ["credit_card_id"], name: "index_charges_on_credit_card_id" t.index ["merchant_account_id"], name: "index_charges_on_merchant_account_id" t.index ["order_id"], name: "index_charges_on_order_id" t.index ["paypal_order_id"], name: "index_charges_on_paypal_order_id", unique: true t.index ["processor_transaction_id"], name: "index_charges_on_processor_transaction_id", unique: true t.index ["seller_id"], name: "index_charges_on_seller_id" end create_table "collaborator_invitations", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "collaborator_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["collaborator_id"], name: "index_collaborator_invitations_on_collaborator_id", unique: true end create_table "comments", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "commentable_id" t.string "commentable_type" t.bigint "author_id" t.string "author_name" t.text "content", size: :medium t.string "comment_type" t.text "json_data", size: :medium t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.datetime "deleted_at", precision: nil t.bigint "purchase_id" t.string "ancestry" t.integer "ancestry_depth", default: 0, null: false t.index ["ancestry"], name: "index_comments_on_ancestry" t.index ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type" t.index ["purchase_id"], name: "index_comments_on_purchase_id" end create_table "commission_files", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "url", limit: 1024 t.bigint "commission_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["commission_id"], name: "index_commission_files_on_commission_id" end create_table "commissions", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "status" t.bigint "deposit_purchase_id" t.bigint "completion_purchase_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["completion_purchase_id"], name: "index_commissions_on_completion_purchase_id" t.index ["deposit_purchase_id"], name: "index_commissions_on_deposit_purchase_id" end create_table "communities", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "resource_type", null: false t.bigint "resource_id", null: false t.bigint "seller_id", null: false t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["deleted_at"], name: "index_communities_on_deleted_at" t.index ["resource_type", "resource_id", "seller_id", "deleted_at"], name: "idx_on_resource_type_resource_id_seller_id_deleted__23a67b41cb", unique: true t.index ["resource_type", "resource_id"], name: "index_communities_on_resource" t.index ["seller_id"], name: "index_communities_on_seller_id" end create_table "community_chat_messages", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "community_id", null: false t.bigint "user_id", null: false t.text "content", size: :long, null: false t.datetime "deleted_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["community_id"], name: "index_community_chat_messages_on_community_id" t.index ["deleted_at"], name: "index_community_chat_messages_on_deleted_at" t.index ["user_id"], name: "index_community_chat_messages_on_user_id" end create_table "community_chat_recap_runs", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "recap_frequency", null: false t.datetime "from_date", null: false t.datetime "to_date", null: false t.integer "recaps_count", default: 0, null: false t.datetime "finished_at" t.datetime "notified_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["recap_frequency", "from_date", "to_date"], name: "idx_on_recap_frequency_from_date_to_date_2ed29d569d", unique: true t.index ["recap_frequency"], name: "index_community_chat_recap_runs_on_recap_frequency" end create_table "community_chat_recaps", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "community_chat_recap_run_id", null: false t.bigint "community_id" t.bigint "seller_id" t.integer "summarized_message_count", default: 0, null: false t.text "summary", size: :long t.string "status", default: "pending", null: false t.string "error_message" t.integer "input_token_count", default: 0, null: false t.integer "output_token_count", default: 0, null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["community_chat_recap_run_id"], name: "index_community_chat_recaps_on_community_chat_recap_run_id" t.index ["community_id"], name: "index_community_chat_recaps_on_community_id" t.index ["seller_id"], name: "index_community_chat_recaps_on_seller_id" t.index ["status"], name: "index_community_chat_recaps_on_status" end create_table "community_notification_settings", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "user_id", null: false t.bigint "seller_id", null: false t.string "recap_frequency" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["recap_frequency"], name: "index_community_notification_settings_on_recap_frequency" t.index ["seller_id"], name: "index_community_notification_settings_on_seller_id" t.index ["user_id", "seller_id"], name: "index_community_notification_settings_on_user_id_and_seller_id", unique: true t.index ["user_id"], name: "index_community_notification_settings_on_user_id" end create_table "computed_sales_analytics_days", id: :integer, charset: "latin1", force: :cascade do |t| t.string "key", limit: 191, null: false t.text "data", size: :medium t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.index ["key"], name: "index_computed_sales_analytics_days_on_key", unique: true end create_table "consumption_events", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.bigint "product_file_id" t.bigint "url_redirect_id" t.bigint "purchase_id" t.string "event_type" t.string "platform" t.integer "flags", default: 0, null: false t.text "json_data" t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil t.bigint "link_id" t.datetime "consumed_at", precision: nil t.integer "media_location_basis_points" t.index ["link_id"], name: "index_consumption_events_on_link_id" t.index ["product_file_id"], name: "index_consumption_events_on_product_file_id" t.index ["purchase_id"], name: "index_consumption_events_on_purchase_id" end create_table "credit_cards", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "card_type" t.integer "expiry_month" t.integer "expiry_year" t.string "stripe_customer_id" t.string "visual" t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil t.string "stripe_fingerprint" t.boolean "cvc_check_failed" t.string "card_country" t.string "stripe_card_id" t.string "card_bin" t.integer "preorder_id" t.string "card_data_handling_mode" t.string "charge_processor_id" t.string "braintree_customer_id" t.string "funding_type", limit: 191 t.string "paypal_billing_agreement_id", limit: 191 t.string "processor_payment_method_id" t.json "json_data" t.index ["preorder_id"], name: "index_credit_cards_on_preorder_id" t.index ["stripe_fingerprint"], name: "index_credit_cards_on_stripe_fingerprint" end create_table "credits", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "user_id" t.integer "amount_cents" t.integer "balance_id" t.datetime "created_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false t.integer "crediting_user_id" t.integer "chargebacked_purchase_id" t.integer "merchant_account_id", default: 1 t.integer "dispute_id" t.integer "returned_payment_id" t.integer "refund_id" t.integer "financing_paydown_purchase_id" t.integer "fee_retention_refund_id" t.bigint "backtax_agreement_id" t.text "json_data" t.index ["balance_id"], name: "index_credits_on_balance_id" t.index ["dispute_id"], name: "index_credits_on_dispute_id" end create_table "custom_domains", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.integer "user_id" t.string "domain" t.datetime "created_at", precision: nil t.datetime "updated_at", precision: nil t.datetime "ssl_certificate_issued_at", precision: nil t.datetime "deleted_at", precision: nil t.string "state", default: "unverified", null: false t.integer "failed_verification_attempts_count", default: 0, null: false t.bigint "product_id" t.index ["domain"], name: "index_custom_domains_on_domain" t.index ["product_id"], name: "index_custom_domains_on_product_id" t.index ["ssl_certificate_issued_at"], name: "index_custom_domains_on_ssl_certificate_issued_at" t.index ["user_id"], name: "index_custom_domains_on_user_id" end create_table "custom_fields", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t| t.string "field_type" t.string "name" t.boolean "required", default: false t.boolean "global", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.bigint "seller_id", null: false t.bigint "flags", default: 0, null: false t.index ["seller_id"], name: "index_custom_fields_on_seller_id" end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
true
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_braintree_merchant_account_seeds.rb
db/seeds/020_braintree_merchant_account_seeds.rb
# frozen_string_literal: true # Create the shared Braintree merchant accounts if MerchantAccount.gumroad(BraintreeChargeProcessor.charge_processor_id).nil? merchant_account_braintree = MerchantAccount.new merchant_account_braintree.charge_processor_id = BraintreeChargeProcessor.charge_processor_id merchant_account_braintree.charge_processor_merchant_id = BRAINTREE_MERCHANT_ACCOUNT_ID_FOR_SUPPLIERS merchant_account_braintree.save! end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/010_stripe_merchant_account_seeds.rb
db/seeds/010_stripe_merchant_account_seeds.rb
# frozen_string_literal: true # Create the shared Stripe merchant account if MerchantAccount.gumroad(StripeChargeProcessor.charge_processor_id).nil? merchant_account_stripe = MerchantAccount.new merchant_account_stripe.charge_processor_id = StripeChargeProcessor.charge_processor_id merchant_account_stripe.save! end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/030_paypal_merchant_account_seeds.rb
db/seeds/030_paypal_merchant_account_seeds.rb
# frozen_string_literal: true # Create the shared PayPal merchant accounts if MerchantAccount.gumroad(PaypalChargeProcessor.charge_processor_id).nil? paypal_merchant_account = MerchantAccount.new paypal_merchant_account.charge_processor_id = PaypalChargeProcessor.charge_processor_id paypal_merchant_account.charge_processor_merchant_id = nil paypal_merchant_account.save! end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/010_development_staging_test/taxonomy_create.rb
db/seeds/010_development_staging_test/taxonomy_create.rb
# frozen_string_literal: true return if ENV["SKIP_TAXONOMY_CREATION"] == "1" return if Taxonomy.where(slug: "3d").exists? three_d = Taxonomy.find_or_create_by!(slug: "3d") Taxonomy.find_or_create_by!(slug: "3d-modeling", parent: three_d) Taxonomy.find_or_create_by!(slug: "character-design", parent: three_d) Taxonomy.find_or_create_by!(slug: "rigging", parent: three_d) Taxonomy.find_or_create_by!(slug: "animating", parent: three_d) ar = Taxonomy.find_or_create_by!(slug: "arvr", parent: three_d) Taxonomy.find_or_create_by!(slug: "spark-ar-studio", parent: ar) three_d_assets = Taxonomy.find_or_create_by!(slug: "3d-assets", parent: three_d) Taxonomy.find_or_create_by!(slug: "blender", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "maya", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "modo", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "cinema-4d", parent: three_d_assets) unity = Taxonomy.find_or_create_by!(slug: "unity", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "sketchup", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "unreal-engine", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "3dsmax", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "zbrush", parent: three_d_assets) design = Taxonomy.find_or_create_by!(slug: "design") Taxonomy.find_or_create_by!(slug: "industrial-design", parent: design) Taxonomy.find_or_create_by!(slug: "entertainment-design", parent: design) Taxonomy.find_or_create_by!(slug: "architecture", parent: design) Taxonomy.find_or_create_by!(slug: "fashion-design", parent: design) Taxonomy.find_or_create_by!(slug: "interior-design", parent: design) web = Taxonomy.find_or_create_by!(slug: "ui-and-web", parent: design) Taxonomy.find_or_create_by!(slug: "figma", parent: web) Taxonomy.find_or_create_by!(slug: "xd", parent: web) Taxonomy.find_or_create_by!(slug: "adobe", parent: web) Taxonomy.find_or_create_by!(slug: "html", parent: web) packaging = Taxonomy.find_or_create_by!(slug: "print-and-packaging", parent: design) Taxonomy.find_or_create_by!(slug: "canva", parent: packaging) Taxonomy.find_or_create_by!(slug: "illustrator", parent: packaging) Taxonomy.find_or_create_by!(slug: "powerpoint", parent: packaging) Taxonomy.find_or_create_by!(slug: "indesign", parent: packaging) graphics = Taxonomy.find_or_create_by!(slug: "graphics", parent: design) Taxonomy.find_or_create_by!(slug: "textures-and-patterns-2d", parent: graphics) Taxonomy.find_or_create_by!(slug: "vector-graphics", parent: graphics) Taxonomy.find_or_create_by!(slug: "marketing-and-social", parent: graphics) Taxonomy.find_or_create_by!(slug: "assets-and-templates", parent: graphics) mockups = Taxonomy.find_or_create_by!(slug: "mockups", parent: graphics) Taxonomy.find_or_create_by!(slug: "photoshop", parent: mockups) Taxonomy.find_or_create_by!(slug: "illustrator", parent: mockups) Taxonomy.find_or_create_by!(slug: "canva", parent: mockups) Taxonomy.find_or_create_by!(slug: "indesign", parent: mockups) Taxonomy.find_or_create_by!(slug: "fonts", parent: design) branding = Taxonomy.find_or_create_by!(slug: "branding", parent: design) Taxonomy.find_or_create_by!(slug: "logos", parent: branding) Taxonomy.find_or_create_by!(slug: "business-cards", parent: branding) Taxonomy.find_or_create_by!(slug: "social-media", parent: branding) Taxonomy.find_or_create_by!(slug: "wallpapers", parent: design) icons = Taxonomy.find_or_create_by!(slug: "icons", parent: design) Taxonomy.find_or_create_by!(slug: "3d-icons", parent: icons) Taxonomy.find_or_create_by!(slug: "vector-icons", parent: icons) Taxonomy.find_or_create_by!(slug: "ios-customization", parent: icons) drawing = Taxonomy.find_or_create_by!(slug: "drawing-and-painting") illustration = Taxonomy.find_or_create_by!(slug: "digital-illustration", parent: drawing) Taxonomy.find_or_create_by!(slug: "courses", parent: illustration) Taxonomy.find_or_create_by!(slug: "illustration-textures-and-patterns", parent: illustration) Taxonomy.find_or_create_by!(slug: "illustration-kits", parent: illustration) illbrushes = Taxonomy.find_or_create_by!(slug: "illustration-brushes", parent: illustration) Taxonomy.find_or_create_by!(slug: "photoshop", parent: illbrushes) Taxonomy.find_or_create_by!(slug: "procreate", parent: illbrushes) Taxonomy.find_or_create_by!(slug: "blender", parent: illbrushes) Taxonomy.find_or_create_by!(slug: "traditional-art", parent: drawing) Taxonomy.find_or_create_by!(slug: "artwork-and-commissions", parent: drawing) software_development = Taxonomy.find_or_create_by!(slug: "software-development") programming = Taxonomy.find_or_create_by!(slug: "programming", parent: software_development) Taxonomy.find_or_create_by!(slug: "c-sharp", parent: programming) Taxonomy.find_or_create_by!(slug: "python", parent: programming) web = Taxonomy.find_or_create_by!(slug: "web-development", parent: software_development) Taxonomy.find_or_create_by!(slug: "aws", parent: web) Taxonomy.find_or_create_by!(slug: "ruby", parent: web) js = Taxonomy.find_or_create_by!(slug: "javascript", parent: web) Taxonomy.find_or_create_by!(slug: "react-js", parent: js) mobile = Taxonomy.find_or_create_by!(slug: "app-development", parent: software_development) Taxonomy.find_or_create_by!(slug: "swift", parent: mobile) Taxonomy.find_or_create_by!(slug: "react-native", parent: mobile) software = Taxonomy.find_or_create_by!(slug: "software-and-plugins", parent: software_development) Taxonomy.find_or_create_by!(slug: "wordpress", parent: software) Taxonomy.find_or_create_by!(slug: "vscode", parent: software) hardware = Taxonomy.find_or_create_by!(slug: "hardware", parent: software_development) Taxonomy.find_or_create_by!(slug: "raspberry-pi", parent: hardware) self_improvement = Taxonomy.find_or_create_by!(slug: "self-improvement") Taxonomy.find_or_create_by!(slug: "psychology", parent: self_improvement) Taxonomy.find_or_create_by!(slug: "productivity", parent: self_improvement) Taxonomy.find_or_create_by!(slug: "dating-and-relationships", parent: self_improvement) Taxonomy.find_or_create_by!(slug: "philosophy", parent: self_improvement) spirituality = Taxonomy.find_or_create_by!(slug: "spirituality", parent: self_improvement) Taxonomy.find_or_create_by!(slug: "astrology", parent: spirituality) Taxonomy.find_or_create_by!(slug: "meditation", parent: spirituality) Taxonomy.find_or_create_by!(slug: "magic", parent: spirituality) mysticism = Taxonomy.find_or_create_by!(slug: "mysticism", parent: spirituality) Taxonomy.find_or_create_by!(slug: "tarot", parent: mysticism) Taxonomy.find_or_create_by!(slug: "wicca-witchcraft-and-paganism", parent: spirituality) cooking = Taxonomy.find_or_create_by!(slug: "cooking", parent: self_improvement) Taxonomy.find_or_create_by!(slug: "nutrition", parent: cooking) Taxonomy.find_or_create_by!(slug: "vegan", parent: cooking) Taxonomy.find_or_create_by!(slug: "recipes", parent: cooking) crafts = Taxonomy.find_or_create_by!(slug: "crafts-and-dyi", parent: self_improvement) Taxonomy.find_or_create_by!(slug: "papercrafts", parent: crafts) Taxonomy.find_or_create_by!(slug: "crafts-for-children", parent: crafts) Taxonomy.find_or_create_by!(slug: "jewelry", parent: crafts) Taxonomy.find_or_create_by!(slug: "lego", parent: crafts) Taxonomy.find_or_create_by!(slug: "3d-printing", parent: crafts) Taxonomy.find_or_create_by!(slug: "board-games", parent: crafts) sewing = Taxonomy.find_or_create_by!(slug: "sewing", parent: crafts) Taxonomy.find_or_create_by!(slug: "courses", parent: sewing) Taxonomy.find_or_create_by!(slug: "kits", parent: sewing) woodworking = Taxonomy.find_or_create_by!(slug: "woodworking", parent: crafts) Taxonomy.find_or_create_by!(slug: "courses", parent: woodworking) Taxonomy.find_or_create_by!(slug: "kits", parent: woodworking) Taxonomy.find_or_create_by!(slug: "automotive", parent: crafts) Taxonomy.find_or_create_by!(slug: "wellness", parent: self_improvement) Taxonomy.find_or_create_by!(slug: "weddings", parent: self_improvement) Taxonomy.find_or_create_by!(slug: "travel", parent: self_improvement) outdoors = Taxonomy.find_or_create_by!(slug: "outdoors", parent: self_improvement) Taxonomy.find_or_create_by!(slug: "trekking", parent: outdoors) Taxonomy.find_or_create_by!(slug: "hunting", parent: outdoors) Taxonomy.find_or_create_by!(slug: "boating-and-fishing", parent: outdoors) fitness = Taxonomy.find_or_create_by!(slug: "fitness-and-health") Taxonomy.find_or_create_by!(slug: "sports", parent: fitness) Taxonomy.find_or_create_by!(slug: "exercise-and-workout", parent: fitness) Taxonomy.find_or_create_by!(slug: "running", parent: fitness) Taxonomy.find_or_create_by!(slug: "weight-loss-and-dieting", parent: fitness) Taxonomy.find_or_create_by!(slug: "yoga", parent: fitness) music = Taxonomy.find_or_create_by!(slug: "music-and-sound-design") instruments = Taxonomy.find_or_create_by!(slug: "instruments", parent: music) Taxonomy.find_or_create_by!(slug: "guitar", parent: instruments) Taxonomy.find_or_create_by!(slug: "piano", parent: instruments) Taxonomy.find_or_create_by!(slug: "vocal", parent: music) dance = Taxonomy.find_or_create_by!(slug: "dance-and-theater", parent: music) Taxonomy.find_or_create_by!(slug: "dance", parent: dance) Taxonomy.find_or_create_by!(slug: "theater", parent: dance) sounddesign = Taxonomy.find_or_create_by!(slug: "sound-design", parent: music) Taxonomy.find_or_create_by!(slug: "courses", parent: sounddesign) Taxonomy.find_or_create_by!(slug: "samples", parent: sounddesign) Taxonomy.find_or_create_by!(slug: "sheet-music", parent: sounddesign) sdplugins = Taxonomy.find_or_create_by!(slug: "plugins", parent: sounddesign) Taxonomy.find_or_create_by!(slug: "ableton-live", parent: sdplugins) Taxonomy.find_or_create_by!(slug: "fl-studio", parent: sdplugins) Taxonomy.find_or_create_by!(slug: "logic-pro", parent: sdplugins) photography = Taxonomy.find_or_create_by!(slug: "photography") Taxonomy.find_or_create_by!(slug: "photo-presets-and-actions", parent: photography) Taxonomy.find_or_create_by!(slug: "reference-photos", parent: photography) Taxonomy.find_or_create_by!(slug: "stock-photos", parent: photography) Taxonomy.find_or_create_by!(slug: "photo-courses", parent: photography) Taxonomy.find_or_create_by!(slug: "cosplay", parent: photography) writing = Taxonomy.find_or_create_by!(slug: "writing-and-publishing") Taxonomy.find_or_create_by!(slug: "courses", parent: writing) Taxonomy.find_or_create_by!(slug: "resources", parent: writing) business = Taxonomy.find_or_create_by!(slug: "business-and-money") Taxonomy.find_or_create_by!(slug: "accounting", parent: business) Taxonomy.find_or_create_by!(slug: "investing", parent: business) Taxonomy.find_or_create_by!(slug: "personal-finance", parent: business) marketing = Taxonomy.find_or_create_by!(slug: "marketing-and-sales", parent: business) Taxonomy.find_or_create_by!(slug: "email", parent: marketing) Taxonomy.find_or_create_by!(slug: "social-media", parent: marketing) Taxonomy.find_or_create_by!(slug: "analytics", parent: marketing) Taxonomy.find_or_create_by!(slug: "networking-careers-and-jobs", parent: business) Taxonomy.find_or_create_by!(slug: "management-and-leadership", parent: business) Taxonomy.find_or_create_by!(slug: "real-estate", parent: business) Taxonomy.find_or_create_by!(slug: "gigs-and-side-projects", parent: business) entrepreneurship = Taxonomy.find_or_create_by!(slug: "entrepreneurship", parent: business) Taxonomy.find_or_create_by!(slug: "resources", parent: entrepreneurship) Taxonomy.find_or_create_by!(slug: "courses", parent: entrepreneurship) Taxonomy.find_or_create_by!(slug: "podcasts", parent: entrepreneurship) education = Taxonomy.find_or_create_by!(slug: "education") Taxonomy.find_or_create_by!(slug: "classroom", parent: education) Taxonomy.find_or_create_by!(slug: "test-prep", parent: education) sstudies = Taxonomy.find_or_create_by!(slug: "social-studies", parent: education) Taxonomy.find_or_create_by!(slug: "history", parent: sstudies) Taxonomy.find_or_create_by!(slug: "politics", parent: sstudies) Taxonomy.find_or_create_by!(slug: "law", parent: sstudies) Taxonomy.find_or_create_by!(slug: "english", parent: education) Taxonomy.find_or_create_by!(slug: "history", parent: education) Taxonomy.find_or_create_by!(slug: "math", parent: education) science = Taxonomy.find_or_create_by!(slug: "science", parent: education) Taxonomy.find_or_create_by!(slug: "medicine", parent: science) Taxonomy.find_or_create_by!(slug: "specialties", parent: education) # Listen Taxonomy.find_or_create_by!(slug: "comics-and-graphic-novels") fiction = Taxonomy.find_or_create_by!(slug: "fiction-books") Taxonomy.find_or_create_by!(slug: "childrens-books", parent: fiction) Taxonomy.find_or_create_by!(slug: "teen-and-young-adult", parent: fiction) Taxonomy.find_or_create_by!(slug: "fantasy", parent: fiction) Taxonomy.find_or_create_by!(slug: "science-fiction", parent: fiction) Taxonomy.find_or_create_by!(slug: "romance", parent: fiction) Taxonomy.find_or_create_by!(slug: "mystery", parent: fiction) audio = Taxonomy.find_or_create_by!(slug: "audio") Taxonomy.find_or_create_by!(slug: "hypnosis", parent: audio) Taxonomy.find_or_create_by!(slug: "subliminal-messages", parent: audio) Taxonomy.find_or_create_by!(slug: "healing", parent: audio) Taxonomy.find_or_create_by!(slug: "sleep-and-meditation", parent: audio) Taxonomy.find_or_create_by!(slug: "asmr", parent: audio) Taxonomy.find_or_create_by!(slug: "voiceover", parent: audio) music = Taxonomy.find_or_create_by!(slug: "recorded-music") Taxonomy.find_or_create_by!(slug: "albums", parent: music) singles = Taxonomy.find_or_create_by!(slug: "singles", parent: music) Taxonomy.find_or_create_by!(slug: "alternative-and-indie", parent: singles) Taxonomy.find_or_create_by!(slug: "rock", parent: singles) Taxonomy.find_or_create_by!(slug: "blues", parent: singles) Taxonomy.find_or_create_by!(slug: "broadway-and-vocalists", parent: singles) Taxonomy.find_or_create_by!(slug: "childrens-music", parent: singles) Taxonomy.find_or_create_by!(slug: "christian", parent: singles) Taxonomy.find_or_create_by!(slug: "classical", parent: singles) Taxonomy.find_or_create_by!(slug: "classic-rock", parent: singles) Taxonomy.find_or_create_by!(slug: "comedy-and-miscellaneous", parent: singles) Taxonomy.find_or_create_by!(slug: "country", parent: singles) Taxonomy.find_or_create_by!(slug: "dance-and-electronic", parent: singles) Taxonomy.find_or_create_by!(slug: "folk", parent: singles) Taxonomy.find_or_create_by!(slug: "gospel", parent: singles) Taxonomy.find_or_create_by!(slug: "hard-rock-and-metal", parent: singles) Taxonomy.find_or_create_by!(slug: "holiday-music", parent: singles) Taxonomy.find_or_create_by!(slug: "jazz", parent: singles) Taxonomy.find_or_create_by!(slug: "latin-music", parent: singles) Taxonomy.find_or_create_by!(slug: "new-age", parent: singles) Taxonomy.find_or_create_by!(slug: "opera-and-vocal", parent: singles) Taxonomy.find_or_create_by!(slug: "pop", parent: singles) Taxonomy.find_or_create_by!(slug: "rhythm-and-blues", parent: singles) Taxonomy.find_or_create_by!(slug: "rap-and-hip-hop", parent: singles) Taxonomy.find_or_create_by!(slug: "soundtracks", parent: singles) Taxonomy.find_or_create_by!(slug: "world-music", parent: singles) # Watch films = Taxonomy.find_or_create_by!(slug: "films") Taxonomy.find_or_create_by!(slug: "short-film", parent: films) Taxonomy.find_or_create_by!(slug: "documentary", parent: films) movies = Taxonomy.find_or_create_by!(slug: "movie", parent: films) Taxonomy.find_or_create_by!(slug: "action-and-adventure", parent: movies) Taxonomy.find_or_create_by!(slug: "animation", parent: movies) Taxonomy.find_or_create_by!(slug: "anime", parent: movies) Taxonomy.find_or_create_by!(slug: "black-voices", parent: movies) Taxonomy.find_or_create_by!(slug: "classics", parent: movies) Taxonomy.find_or_create_by!(slug: "comedy", parent: movies) Taxonomy.find_or_create_by!(slug: "drama", parent: movies) Taxonomy.find_or_create_by!(slug: "faith-and-spirituality", parent: movies) Taxonomy.find_or_create_by!(slug: "foreign-language-and-international", parent: movies) Taxonomy.find_or_create_by!(slug: "horror", parent: movies) Taxonomy.find_or_create_by!(slug: "indian-cinema-and-bollywood", parent: movies) Taxonomy.find_or_create_by!(slug: "indie-and-art-house", parent: movies) Taxonomy.find_or_create_by!(slug: "kids-and-family", parent: movies) Taxonomy.find_or_create_by!(slug: "lgbtq", parent: movies) Taxonomy.find_or_create_by!(slug: "music-videos-and-concerts", parent: movies) Taxonomy.find_or_create_by!(slug: "romance", parent: movies) Taxonomy.find_or_create_by!(slug: "science-fiction", parent: movies) Taxonomy.find_or_create_by!(slug: "western", parent: movies) Taxonomy.find_or_create_by!(slug: "dance", parent: films) Taxonomy.find_or_create_by!(slug: "performance", parent: films) Taxonomy.find_or_create_by!(slug: "theater", parent: films) comedy = Taxonomy.find_or_create_by!(slug: "comedy", parent: films) Taxonomy.find_or_create_by!(slug: "standup", parent: comedy) Taxonomy.find_or_create_by!(slug: "sketch", parent: comedy) Taxonomy.find_or_create_by!(slug: "sports-events", parent: films) Taxonomy.find_or_create_by!(slug: "videography", parent: films) vidprod = Taxonomy.find_or_create_by!(slug: "video-production-and-editing", parent: films) Taxonomy.find_or_create_by!(slug: "luts", parent: vidprod) video_assets = Taxonomy.find_or_create_by!(slug: "video-assets-and-loops", parent: vidprod) Taxonomy.find_or_create_by!(slug: "premiere-pro", parent: video_assets) Taxonomy.find_or_create_by!(slug: "after-effects", parent: video_assets) Taxonomy.find_or_create_by!(slug: "cinema-4d", parent: video_assets) Taxonomy.find_or_create_by!(slug: "stock", parent: vidprod) Taxonomy.find_or_create_by!(slug: "courses", parent: vidprod) gaming = Taxonomy.find_or_create_by!(slug: "gaming") Taxonomy.find_or_create_by!(slug: "streaming", parent: gaming) vrchat = Taxonomy.find_or_create_by!(slug: "vrchat", parent: three_d) avatars = Taxonomy.find_or_create_by!(slug: "avatars", parent: three_d) Taxonomy.find_or_create_by!(slug: "female", parent: avatars) Taxonomy.find_or_create_by!(slug: "male", parent: avatars) Taxonomy.find_or_create_by!(slug: "non-binary", parent: avatars) Taxonomy.find_or_create_by!(slug: "optimized", parent: avatars) Taxonomy.find_or_create_by!(slug: "quest", parent: avatars) Taxonomy.find_or_create_by!(slug: "species", parent: avatars) avatar_components = Taxonomy.find_or_create_by!(slug: "avatar-components", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "bases", parent: avatar_components) Taxonomy.find_or_create_by!(slug: "ears", parent: avatar_components) Taxonomy.find_or_create_by!(slug: "feet", parent: avatar_components) Taxonomy.find_or_create_by!(slug: "hair", parent: avatar_components) Taxonomy.find_or_create_by!(slug: "heads", parent: avatar_components) Taxonomy.find_or_create_by!(slug: "horns", parent: avatar_components) Taxonomy.find_or_create_by!(slug: "tails", parent: avatar_components) accessories = Taxonomy.find_or_create_by!(slug: "accessories", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "bags", parent: accessories) Taxonomy.find_or_create_by!(slug: "belts", parent: accessories) Taxonomy.find_or_create_by!(slug: "chokers", parent: accessories) Taxonomy.find_or_create_by!(slug: "gloves", parent: accessories) Taxonomy.find_or_create_by!(slug: "harnesses", parent: accessories) Taxonomy.find_or_create_by!(slug: "jewelry", parent: accessories) Taxonomy.find_or_create_by!(slug: "masks", parent: accessories) Taxonomy.find_or_create_by!(slug: "wings", parent: accessories) clothing = Taxonomy.find_or_create_by!(slug: "clothing", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "bodysuits", parent: clothing) Taxonomy.find_or_create_by!(slug: "bottoms", parent: clothing) Taxonomy.find_or_create_by!(slug: "bras", parent: clothing) Taxonomy.find_or_create_by!(slug: "dresses", parent: clothing) Taxonomy.find_or_create_by!(slug: "jackets", parent: clothing) Taxonomy.find_or_create_by!(slug: "lingerie", parent: clothing) Taxonomy.find_or_create_by!(slug: "outfits", parent: clothing) Taxonomy.find_or_create_by!(slug: "pants", parent: clothing) Taxonomy.find_or_create_by!(slug: "shirts", parent: clothing) Taxonomy.find_or_create_by!(slug: "shorts", parent: clothing) Taxonomy.find_or_create_by!(slug: "skirts", parent: clothing) Taxonomy.find_or_create_by!(slug: "sweaters", parent: clothing) Taxonomy.find_or_create_by!(slug: "swimsuits", parent: clothing) Taxonomy.find_or_create_by!(slug: "tops", parent: clothing) Taxonomy.find_or_create_by!(slug: "underwear", parent: clothing) footwear = Taxonomy.find_or_create_by!(slug: "footwear", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "boots", parent: footwear) Taxonomy.find_or_create_by!(slug: "leggings", parent: footwear) Taxonomy.find_or_create_by!(slug: "shoes", parent: footwear) Taxonomy.find_or_create_by!(slug: "socks", parent: footwear) Taxonomy.find_or_create_by!(slug: "stockings", parent: footwear) headwear = Taxonomy.find_or_create_by!(slug: "headwear", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "hats", parent: headwear) props = Taxonomy.find_or_create_by!(slug: "props", parent: three_d_assets) Taxonomy.find_or_create_by!(slug: "companions", parent: props) Taxonomy.find_or_create_by!(slug: "handheld", parent: props) Taxonomy.find_or_create_by!(slug: "plushies", parent: props) Taxonomy.find_or_create_by!(slug: "prefabs", parent: props) Taxonomy.find_or_create_by!(slug: "weapons", parent: props) Taxonomy.find_or_create_by!(slug: "animations", parent: unity) Taxonomy.find_or_create_by!(slug: "particle-systems", parent: unity) Taxonomy.find_or_create_by!(slug: "shaders", parent: unity) Taxonomy.find_or_create_by!(slug: "avatar-systems", parent: vrchat) Taxonomy.find_or_create_by!(slug: "followers", parent: vrchat) Taxonomy.find_or_create_by!(slug: "osc", parent: vrchat) Taxonomy.find_or_create_by!(slug: "setup-scripts", parent: vrchat) Taxonomy.find_or_create_by!(slug: "spring-joints", parent: vrchat) Taxonomy.find_or_create_by!(slug: "tools", parent: vrchat) Taxonomy.find_or_create_by!(slug: "world-constraints", parent: vrchat) worlds = Taxonomy.find_or_create_by!(slug: "worlds", parent: vrchat) Taxonomy.find_or_create_by!(slug: "assets", parent: worlds) Taxonomy.find_or_create_by!(slug: "midi", parent: worlds) Taxonomy.find_or_create_by!(slug: "quest", parent: worlds) Taxonomy.find_or_create_by!(slug: "tools", parent: worlds) Taxonomy.find_or_create_by!(slug: "udon", parent: worlds) Taxonomy.find_or_create_by!(slug: "udon-system", parent: worlds) Taxonomy.find_or_create_by!(slug: "udon2", parent: worlds) Taxonomy.find_or_create_by!(slug: "tutorials-guides", parent: vrchat) textures = Taxonomy.find_or_create_by!(slug: "textures", parent: three_d) Taxonomy.find_or_create_by!(slug: "base", parent: textures) Taxonomy.find_or_create_by!(slug: "eyes", parent: textures) Taxonomy.find_or_create_by!(slug: "face", parent: textures) Taxonomy.find_or_create_by!(slug: "icons", parent: textures) Taxonomy.find_or_create_by!(slug: "matcap", parent: textures) Taxonomy.find_or_create_by!(slug: "pbr", parent: textures) Taxonomy.find_or_create_by!(slug: "tattoos", parent: textures) Taxonomy.find_or_create_by!(slug: "other")
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/030_staging/mobile_oauth_application.rb
db/seeds/030_staging/mobile_oauth_application.rb
# frozen_string_literal: true mobile_oauth_app = OauthApplication.where(uid: "7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b", secret: "1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b").first mobile_oauth_app = OauthApplication.new if mobile_oauth_app.nil? mobile_oauth_app.owner = User.find_by(email: "seller@gumroad.com") mobile_oauth_app.scopes = "mobile_api creator_api" mobile_oauth_app.redirect_uri = "#{PROTOCOL}://#{DOMAIN}" mobile_oauth_app.name = "staging mobile oauth app" mobile_oauth_app.uid = "7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b" mobile_oauth_app.secret = "1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b" mobile_oauth_app.save!
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/au_tax_rates.rb
db/seeds/020_development_staging/au_tax_rates.rb
# frozen_string_literal: true ZipTaxRate.find_or_create_by(country: "AU").update(combined_rate: 0.10)
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/taxonomy_products.rb
db/seeds/020_development_staging/taxonomy_products.rb
# frozen_string_literal: true def find_or_create_recommendable_user(category_name) user = User.find_by(email: "gumbo_#{category_name}@gumroad.com") return user if user user = User.create!( name: "Gumbo #{category_name}", username: "gumbo#{category_name}", email: "gumbo_#{category_name}@gumroad.com", password: SecureRandom.hex(24), user_risk_state: "compliant", confirmed_at: Time.current, payment_address: "gumbo_#{category_name}@gumroad.com" ) # Skip validations to set a pwned but easy password user.password = "password" user.save!(validate: false) user end def find_or_create_universal_free_offer_code_for(seller) offer_code = seller.offer_codes .universal .alive .find_by(amount_percentage: 100) return offer_code if offer_code.present? OfferCode.create!( user: seller, universal: true, amount_percentage: 100, code: "seed-#{seller.id}-#{SecureRandom.hex(3)}" ) end def create_purchase(seller, buyer, product) purchase = Purchase.new( link_id: product.id, seller_id: seller.id, price_cents: 0, displayed_price_cents: 0, tax_cents: 0, gumroad_tax_cents: 0, total_transaction_cents: 0, purchaser_id: buyer.id, email: buyer.email, card_country: "US", ip_address: "199.241.200.176", offer_code: find_or_create_universal_free_offer_code_for(seller) ) purchase.send(:calculate_fees) purchase.save! purchase.update!(purchase_state: "successful", succeeded_at: Time.current) purchase.post_review(rating: 3) end def create_recommendable_product_if_not_exists(user, taxonomy_slug) product_name = "Beautiful #{taxonomy_slug} widget" product = user.links.find_by(name: product_name) return if product.present? product = user.links.create!( name: product_name, description: "Description for demo product", filetype: "link", price_cents: 500, taxonomy: Taxonomy.find_by(slug: taxonomy_slug), display_product_reviews: true ) product.tag!(taxonomy_slug[0..19]) buyer = User.find_by(email: "seller@gumroad.com") create_purchase(user, buyer, product) end create_recommendable_product_if_not_exists(find_or_create_recommendable_user("film"), "films") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("music"), "music-and-sound-design") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("writing"), "writing-and-publishing") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("education"), "education") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("software"), "software-development") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("comics"), "comics-and-graphic-novels") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("drawing"), "drawing-and-painting") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("animation"), "3d") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("audio"), "audio") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("games"), "gaming") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("photography"), "photography") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("crafts"), "self-improvement") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("design"), "design") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("sports"), "fitness-and-health") create_recommendable_product_if_not_exists(find_or_create_recommendable_user("merchandise"), "fiction-books") DevTools.delete_all_indices_and_reindex_all
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/sg_tax_rates.rb
db/seeds/020_development_staging/sg_tax_rates.rb
# frozen_string_literal: true ZipTaxRate.find_or_create_by(country: "SG", combined_rate: 0.08).update(applicable_years: [2023]) ZipTaxRate.find_or_create_by(country: "SG", combined_rate: 0.09).update(applicable_years: [2024])
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/01_users.rb
db/seeds/020_development_staging/01_users.rb
# frozen_string_literal: true seller = User.find_by(email: "seller@gumroad.com") if seller.blank? seller = User.new seller.email = "seller@gumroad.com" seller.name = "Seller" seller.username = "seller" seller.confirmed_at = Time.current seller.is_team_member = true seller.user_risk_state = "compliant" seller.password = SecureRandom.hex(24) # Make seller eligible for service products seller.created_at = 2.months.ago seller.payments.build( state: "completed", amount_cents: 1000, processor: "paypal", processor_fee_cents: 100, payout_period_end_date: 1.day.ago ) seller.save! # Skip validations to set a pwned but easy password seller.password = "password" seller.save!(validate: false) end TeamMembership::ROLES.excluding(TeamMembership::ROLE_OWNER).each do |role| email = "seller+#{role}@gumroad.com" user = User.find_by(email:) next if user.present? user = User.create!( email:, name: "#{role.humanize}ForSeller", username: "#{role}forseller", confirmed_at: Time.current, user_risk_state: "compliant", password: SecureRandom.hex(24) ) # Skip validations to set a pwned but easy password user.password = "password" user.save!(validate: false) user.create_owner_membership_if_needed! user.user_memberships.create!(user:, seller:, role:) end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/tax_rates_for_countries_that_collect_on_digital_products.rb
db/seeds/020_development_staging/tax_rates_for_countries_that_collect_on_digital_products.rb
# frozen_string_literal: true ZipTaxRate.find_or_create_by(country: "BH").update(combined_rate: 0.10) # Bahrain ZipTaxRate.find_or_create_by(country: "BY").update(combined_rate: 0.20) # Belarus ZipTaxRate.find_or_create_by(country: "CL").update(combined_rate: 0.19) # Chile ZipTaxRate.find_or_create_by(country: "CO").update(combined_rate: 0.19) # Colombia ZipTaxRate.find_or_create_by(country: "CR").update(combined_rate: 0.13) # Costa Rica ZipTaxRate.find_or_create_by(country: "EC").update(combined_rate: 0.12) # Ecuador ZipTaxRate.find_or_create_by(country: "EG").update(combined_rate: 0.14) # Egypt ZipTaxRate.find_or_create_by(country: "GE").update(combined_rate: 0.18) # Georgia ZipTaxRate.find_or_create_by(country: "KE").update(combined_rate: 0.16) # Kenya ZipTaxRate.find_or_create_by(country: "KR").update(combined_rate: 0.10) # South Korea ZipTaxRate.find_or_create_by(country: "KZ").update(combined_rate: 0.12) # Kazakhstan ZipTaxRate.find_or_create_by(country: "MA").update(combined_rate: 0.20) # Morocco ZipTaxRate.find_or_create_by(country: "MD").update(combined_rate: 0.20) # Moldova ZipTaxRate.find_or_create_by(country: "MX").update(combined_rate: 0.16) # Mexico ZipTaxRate.find_or_create_by(country: "MX", flags: 2).update(combined_rate: 0.00) # Mexico ZipTaxRate.find_or_create_by(country: "MY").update(combined_rate: 0.06) # Malaysia ZipTaxRate.find_or_create_by(country: "NG").update(combined_rate: 0.075) # Nigeria ZipTaxRate.find_or_create_by(country: "OM").update(combined_rate: 0.05) # Oman ZipTaxRate.find_or_create_by(country: "RS").update(combined_rate: 0.20) # Serbia ZipTaxRate.find_or_create_by(country: "RU").update(combined_rate: 0.20) # Russia ZipTaxRate.find_or_create_by(country: "SA").update(combined_rate: 0.15) # Saudi Arabia ZipTaxRate.find_or_create_by(country: "TH").update(combined_rate: 0.07) # Thailand ZipTaxRate.find_or_create_by(country: "TR").update(combined_rate: 0.20) # Turkey ZipTaxRate.find_or_create_by(country: "TZ").update(combined_rate: 0.18) # Tanzania ZipTaxRate.find_or_create_by(country: "UA").update(combined_rate: 0.20) # Ukraine ZipTaxRate.find_or_create_by(country: "UZ").update(combined_rate: 0.15) # Uzbekistan ZipTaxRate.find_or_create_by(country: "VN").update(combined_rate: 0.10) # Vietnam
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/tax_rates_for_countries_that_collect_on_all_products.rb
db/seeds/020_development_staging/tax_rates_for_countries_that_collect_on_all_products.rb
# frozen_string_literal: true ZipTaxRate.find_or_create_by(country: "IS").update(combined_rate: 0.24) # Iceland ZipTaxRate.find_or_create_by(country: "IS", flags: 2).update(combined_rate: 0.11) # Iceland ZipTaxRate.find_or_create_by(country: "JP").update(combined_rate: 0.10) # Japan ZipTaxRate.find_or_create_by(country: "NZ").update(combined_rate: 0.15) # New Zealand ZipTaxRate.find_or_create_by(country: "ZA").update(combined_rate: 0.15) # South Africa ZipTaxRate.find_or_create_by(country: "CH").update(combined_rate: 0.081) # Switzerland ZipTaxRate.find_or_create_by(country: "CH", flags: 2).update(combined_rate: 0.026) # Switzerland ZipTaxRate.find_or_create_by(country: "AE").update(combined_rate: 0.05) # United Arab Emirates ZipTaxRate.find_or_create_by(country: "IN").update(combined_rate: 0.18) # India
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/eu_tax_rates.rb
db/seeds/020_development_staging/eu_tax_rates.rb
# frozen_string_literal: true ZipTaxRate.find_or_create_by(country: "AT").update(combined_rate: 0.20) ZipTaxRate.find_or_create_by(country: "BE").update(combined_rate: 0.21) ZipTaxRate.find_or_create_by(country: "BG").update(combined_rate: 0.20) ZipTaxRate.find_or_create_by(country: "CZ").update(combined_rate: 0.21) ZipTaxRate.find_or_create_by(country: "DK").update(combined_rate: 0.25) ZipTaxRate.find_or_create_by(country: "DE").update(combined_rate: 0.19) ZipTaxRate.find_or_create_by(country: "EE").update(combined_rate: 0.20) ZipTaxRate.find_or_create_by(country: "GR").update(combined_rate: 0.24) ZipTaxRate.find_or_create_by(country: "ES").update(combined_rate: 0.21) ZipTaxRate.find_or_create_by(country: "FR").update(combined_rate: 0.20) ZipTaxRate.find_or_create_by(country: "HR").update(combined_rate: 0.25) ZipTaxRate.find_or_create_by(country: "IE").update(combined_rate: 0.23) ZipTaxRate.find_or_create_by(country: "IT").update(combined_rate: 0.22) ZipTaxRate.find_or_create_by(country: "CY").update(combined_rate: 0.19) ZipTaxRate.find_or_create_by(country: "LV").update(combined_rate: 0.21) ZipTaxRate.find_or_create_by(country: "LT").update(combined_rate: 0.21) ZipTaxRate.find_or_create_by(country: "LU").update(combined_rate: 0.17) ZipTaxRate.find_or_create_by(country: "HU").update(combined_rate: 0.27) ZipTaxRate.find_or_create_by(country: "MT").update(combined_rate: 0.18) ZipTaxRate.find_or_create_by(country: "NL").update(combined_rate: 0.21) ZipTaxRate.find_or_create_by(country: "PL").update(combined_rate: 0.23) ZipTaxRate.find_or_create_by(country: "PT").update(combined_rate: 0.23) ZipTaxRate.find_or_create_by(country: "RO").update(combined_rate: 0.19) ZipTaxRate.find_or_create_by(country: "SI").update(combined_rate: 0.22) ZipTaxRate.find_or_create_by(country: "SK").update(combined_rate: 0.20) ZipTaxRate.find_or_create_by(country: "FI").update(combined_rate: 0.24) ZipTaxRate.find_or_create_by(country: "SE").update(combined_rate: 0.25) ZipTaxRate.find_or_create_by(country: "GB").update(combined_rate: 0.20) # EU Country VAT rates for e-publications. # See the "Kindle Books" column from: # https://www.amazon.com/gp/help/customer/display.html?nodeId=GSF5MREL4MX7PTVG ZipTaxRate.find_or_create_by(country: "AT", flags: 2).update(combined_rate: 0.10) # Austria ZipTaxRate.find_or_create_by(country: "BE", flags: 2).update(combined_rate: 0.06) # Belgium ZipTaxRate.find_or_create_by(country: "BG", flags: 2).update(combined_rate: 0.09) # Bulgaria ZipTaxRate.find_or_create_by(country: "HR", flags: 2).update(combined_rate: 0.25) # Croatia ZipTaxRate.find_or_create_by(country: "CY", flags: 2).update(combined_rate: 0.19) # Cyprus ZipTaxRate.find_or_create_by(country: "CZ", flags: 2).update(combined_rate: 0.10) # Czech Republic ZipTaxRate.find_or_create_by(country: "DK", flags: 2).update(combined_rate: 0.25) # Denmark ZipTaxRate.find_or_create_by(country: "EE", flags: 2).update(combined_rate: 0.20) # Estonia ZipTaxRate.find_or_create_by(country: "FI", flags: 2).update(combined_rate: 0.10) # Finland ZipTaxRate.find_or_create_by(country: "FR", flags: 2).update(combined_rate: 0.055) # France ZipTaxRate.find_or_create_by(country: "DE", flags: 2).update(combined_rate: 0.07) # Germany ZipTaxRate.find_or_create_by(country: "GR", flags: 2).update(combined_rate: 0.06) # Greece ZipTaxRate.find_or_create_by(country: "HU", flags: 2).update(combined_rate: 0.27) # Hungary ZipTaxRate.find_or_create_by(country: "IE", flags: 2).update(combined_rate: 0.09) # Ireland ZipTaxRate.find_or_create_by(country: "IT", flags: 2).update(combined_rate: 0.04) # Italy ZipTaxRate.find_or_create_by(country: "LV", flags: 2).update(combined_rate: 0.21) # Latvia ZipTaxRate.find_or_create_by(country: "LT", flags: 2).update(combined_rate: 0.21) # Lithuania ZipTaxRate.find_or_create_by(country: "LU", flags: 2).update(combined_rate: 0.03) # Luxembourg ZipTaxRate.find_or_create_by(country: "MT", flags: 2).update(combined_rate: 0.05) # Malta ZipTaxRate.find_or_create_by(country: "NL", flags: 2).update(combined_rate: 0.09) # Netherlands ZipTaxRate.find_or_create_by(country: "PL", flags: 2).update(combined_rate: 0.05) # Poland ZipTaxRate.find_or_create_by(country: "PT", flags: 2).update(combined_rate: 0.06) # Portugal ZipTaxRate.find_or_create_by(country: "RO", flags: 2).update(combined_rate: 0.05) # Romania ZipTaxRate.find_or_create_by(country: "SK", flags: 2).update(combined_rate: 0.20) # Slovakia ZipTaxRate.find_or_create_by(country: "SI", flags: 2).update(combined_rate: 0.05) # Slovenia ZipTaxRate.find_or_create_by(country: "ES", flags: 2).update(combined_rate: 0.04) # Spain ZipTaxRate.find_or_create_by(country: "SE", flags: 2).update(combined_rate: 0.06) # Sweden ZipTaxRate.find_or_create_by(country: "GB", flags: 2).update(combined_rate: 0.00) # United Kingdom
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/02_products.rb
db/seeds/020_development_staging/02_products.rb
# frozen_string_literal: true product = Link.fetch("demo") if product.blank? # Demo product used on /widgets page for non-logged in users seller = User.find_by(email: "seller@gumroad.com") seller.products.create!( name: "Beautiful widget", unique_permalink: "demo", description: "Description for demo product", filetype: "link", price_cents: 0, ) end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/features.rb
db/seeds/020_development_staging/features.rb
# frozen_string_literal: true features_to_activate = [] features_to_activate.each do |feature| Feature.activate(feature) end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/gumroad_posts.rb
db/seeds/020_development_staging/gumroad_posts.rb
# frozen_string_literal: true email = "hi@gumroad.com" gumroad_user = User.find_by(email:) if gumroad_user.nil? gumroad_user = User.new gumroad_user.email = email gumroad_user.username = "gumroad" gumroad_user.confirmed_at = Time.current gumroad_user.password = SecureRandom.hex(24) gumroad_user.save! # Skip validations to set a pwned but easy password gumroad_user.password = "password" gumroad_user.save!(validate: false) end gumroad_user.reload Installment.create!(seller: gumroad_user, shown_on_profile: true, send_emails: true, message: "This is a new feature<p>#ProductUpdates</p>", name: "Reorder Tiers and Versions", published_at: Time.current, installment_type: "audience") Installment.create!(seller: gumroad_user, shown_on_profile: true, send_emails: true, message: "Sam has been creating and selling digital products on Gumroad for over 3 years now. What started as a side project selling programming tutorials has grown into a thriving business generating well over $100,000 in revenue. His success story showcases how creators can build sustainable income streams by focusing on delivering high-quality educational content. Through consistent effort and engaging with his audience, Sam has built a loyal following of over 20,000 students who appreciate his clear teaching style and practical approach. He attributes much of his success to Gumroad's creator-friendly platform that lets him focus on creating great content while handling all the technical details of running an online business.<p>#CreatorStory</p>", name: "Creator Spotlight: Sam's Success on Gumroad ", published_at: Time.current, installment_type: "audience") posts_directory = Rails.root.join("db", "seeds", "040_posts") if Dir.exist?(posts_directory) Dir.glob("*.html", base: posts_directory).sort.each do |filename| file_path = posts_directory.join(filename) base_name = File.basename(filename, ".html") name = base_name.gsub(/^\d+_/, "").tr("-", " ").titleize message = File.read(file_path).strip Installment.create!( seller: gumroad_user, shown_on_profile: true, send_emails: true, message: message, name: name, published_at: Time.current, installment_type: "audience", ) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/020_development_staging/no_tax_rates.rb
db/seeds/020_development_staging/no_tax_rates.rb
# frozen_string_literal: true ZipTaxRate.find_or_create_by(country: "NO").update(combined_rate: 0.25) ZipTaxRate.find_or_create_by(country: "NO", flags: 2).update(combined_rate: 0.00)
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/030_development/notion_oauth_application.rb
db/seeds/030_development/notion_oauth_application.rb
# frozen_string_literal: true notion_oauth_app = OauthApplication.find_or_initialize_by(name: "Notion (dev)") if notion_oauth_app.new_record? notion_oauth_app.owner = User.find_by(email: "seller@gumroad.com") || User.first notion_oauth_app.scopes = "unfurl" notion_oauth_app.redirect_uri = "https://www.notion.so/externalintegrationauthcallback" notion_oauth_app.uid = Digest::SHA256.hexdigest(SecureRandom.hex(32))[0..31] notion_oauth_app.secret = Digest::SHA256.hexdigest(SecureRandom.hex(32))[0..31] notion_oauth_app.save! end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/030_development/products.rb
db/seeds/030_development/products.rb
# frozen_string_literal: true def load_products if Rails.env.production? puts "Shouldn't run product seeds on production" raise end 10.times.each do |i| # create seller user = User.create!( name: "Gumbo #{i}", username: "gumbo#{i}", email: "gumbo#{i}@gumroad.com", password: SecureRandom.hex(24), user_risk_state: "compliant", confirmed_at: Time.current ) # Skip validations to set a pwned but easy password user.password = "password" user.save!(validate: false) # product product = Link.new( user_id: user.id, name: "Beautiful widget from Gumbo #{i}", description: "Description for Gumbo' beautiful magic widgets", filetype: "link", price_cents: (100 * i), ) product.display_product_reviews = true price = product.prices.build(price_cents: product.price_cents) price.recurrence = 0 product.save! # create tag product.tag!("Tag #{i}") # create buyer buyer = User.create!( name: "Gumbuyer #{i}", username: "gumbuyer#{i}", email: "gumbuyer#{i}@gumroad.com", password: SecureRandom.hex(24), user_risk_state: "compliant", confirmed_at: Time.current ) # Skip validations to set a pwned but easy password buyer.password = "password" buyer.save!(validate: false) # create purchase purchase = Purchase.new( link_id: product.id, seller_id: user.id, price_cents: product.price_cents, displayed_price_cents: product.price_cents, tax_cents: 0, gumroad_tax_cents: 0, total_transaction_cents: product.price_cents, purchaser_id: buyer.id, email: buyer.email, card_country: "US", ip_address: "199.241.200.176" ) purchase.send(:calculate_fees) purchase.save! purchase.update_columns(purchase_state: "successful", succeeded_at: Time.current) # create review w/ rating purchase.post_review(rating: i % 5 + 1) end end load_products DevTools.delete_all_indices_and_reindex_all
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/030_development/mobile_oauth_application.rb
db/seeds/030_development/mobile_oauth_application.rb
# frozen_string_literal: true mobile_oauth_app = OauthApplication.where(uid: "7f3a9b2c1d8e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9", secret: "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2").first mobile_oauth_app = OauthApplication.new if mobile_oauth_app.nil? mobile_oauth_app.owner = User.find_by(email: "seller@gumroad.com") mobile_oauth_app.scopes = "mobile_api creator_api" mobile_oauth_app.redirect_uri = "#{PROTOCOL}://#{DOMAIN}" mobile_oauth_app.name = "development mobile oauth app" mobile_oauth_app.uid = "7f3a9b2c1d8e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9" mobile_oauth_app.secret = "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2" mobile_oauth_app.save!
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/seeds/030_development/helper_oauth_application.rb
db/seeds/030_development/helper_oauth_application.rb
# frozen_string_literal: true helper_oauth_app = OauthApplication.find_or_initialize_by(name: "Helper (dev)") if helper_oauth_app.new_record? helper_oauth_app.owner = User.find_by(email: "seller@gumroad.com") || User.is_team_member.first helper_oauth_app.scopes = "helper_api" helper_oauth_app.redirect_uri = "https://staging.helperai.com/callback" helper_oauth_app.save! end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/migrate/20151014232700_add_user_id_and_deleted_at_to_zip_tax_rates.rb
db/migrate/20151014232700_add_user_id_and_deleted_at_to_zip_tax_rates.rb
# frozen_string_literal: true class AddUserIdAndDeletedAtToZipTaxRates < ActiveRecord::Migration def change add_column :zip_tax_rates, :user_id, :integer add_column :zip_tax_rates, :deleted_at, :datetime add_index :zip_tax_rates, [:user_id] end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/migrate/20141008215224_create_user_compliance_info.rb
db/migrate/20141008215224_create_user_compliance_info.rb
# frozen_string_literal: true class CreateUserComplianceInfo < ActiveRecord::Migration def change create_table :user_compliance_info, options: "DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci" do |t| t.references :user t.string :full_name t.string :street_address t.string :city t.string :state t.string :zip_code t.string :country t.string :telephone_number t.string :vertical t.boolean :is_business t.boolean :has_sold_before t.binary :tax_id t.string :json_data t.integer :flags, default: 0, null: false t.timestamps end add_index :user_compliance_info, :user_id end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/migrate/20120813212650_add_chargebacked_to_purchases.rb
db/migrate/20120813212650_add_chargebacked_to_purchases.rb
# frozen_string_literal: true class AddChargebackedToPurchases < ActiveRecord::Migration def change add_column :purchases, :chargebacked, :boolean, default: false end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/migrate/20151007000000_add_stripe_identity_document_id_to_user_compliance_info.rb
db/migrate/20151007000000_add_stripe_identity_document_id_to_user_compliance_info.rb
# frozen_string_literal: true class AddStripeIdentityDocumentIdToUserComplianceInfo < ActiveRecord::Migration def change add_column :user_compliance_info, :stripe_identity_document_id, :string end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/migrate/20221003082314_add_fee_retention_refund_id_to_credits.rb
db/migrate/20221003082314_add_fee_retention_refund_id_to_credits.rb
# frozen_string_literal: true class AddFeeRetentionRefundIdToCredits < ActiveRecord::Migration[6.1] def change add_column :credits, :fee_retention_refund_id, :integer end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/migrate/20130514223138_create_doorkeeper_tables.rb
db/migrate/20130514223138_create_doorkeeper_tables.rb
# frozen_string_literal: true class CreateDoorkeeperTables < ActiveRecord::Migration def change create_table :oauth_applications do |t| t.string :name, null: false t.string :uid, null: false t.string :secret, null: false t.string :redirect_uri, null: false t.timestamps end add_index :oauth_applications, :uid, unique: true create_table :oauth_access_grants do |t| t.integer :resource_owner_id, null: false t.integer :application_id, null: false t.string :token, null: false t.integer :expires_in, null: false t.string :redirect_uri, null: false t.datetime :created_at, null: false t.datetime :revoked_at t.string :scopes end add_index :oauth_access_grants, :token, unique: true create_table :oauth_access_tokens do |t| t.integer :resource_owner_id t.integer :application_id, null: false t.string :token, null: false t.string :refresh_token t.integer :expires_in t.datetime :revoked_at t.datetime :created_at, null: false t.string :scopes end add_index :oauth_access_tokens, :token, unique: true add_index :oauth_access_tokens, :resource_owner_id add_index :oauth_access_tokens, :refresh_token, unique: true end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/migrate/20151001225321_add_cover_image_url_to_installment.rb
db/migrate/20151001225321_add_cover_image_url_to_installment.rb
# frozen_string_literal: true class AddCoverImageUrlToInstallment < ActiveRecord::Migration def change add_column(:installments, :cover_image_url, :string) end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false
antiwork/gumroad
https://github.com/antiwork/gumroad/blob/638f6c3a40b23b907c09f6881d4df18339da069c/db/migrate/20190127011053_add_deleted_from_cdn_at_to_transcoded_videos.rb
db/migrate/20190127011053_add_deleted_from_cdn_at_to_transcoded_videos.rb
# frozen_string_literal: true class AddDeletedFromCdnAtToTranscodedVideos < ActiveRecord::Migration def change add_column :transcoded_videos, :deleted_from_cdn_at, :datetime end end
ruby
MIT
638f6c3a40b23b907c09f6881d4df18339da069c
2026-01-04T15:39:11.815677Z
false