-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rails generate sidekiq:job Penalty * jquery datepicker * fix method * rubocop * disable * - test
- Loading branch information
Showing
5 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# app/jobs/penalty_job.rb | ||
class PenaltyJob | ||
include Sidekiq::Job | ||
|
||
def perform(note_id) | ||
# Find the note | ||
note = Note.find(note_id) | ||
user = note.user | ||
|
||
# Check if the note is incomplete and the deadline has passed | ||
if !note.completed && note.deadline < Time.current | ||
Rails.logger.info "PenaltyJob: Charging user #{user.id} for not completing the task #{note.id}" | ||
# Charge the user for not completing the task | ||
# charge_user(user, note) | ||
end | ||
end | ||
|
||
private | ||
|
||
def charge_user(user, note) | ||
amount = 100 # Penalty fee in cents ($1.00) | ||
|
||
# Retrieve the user's default payment method from Stripe | ||
payment_method_id = Stripe::Customer.retrieve(user.stripe_id).invoice_settings.default_payment_method | ||
|
||
if payment_method_id | ||
# Create a payment intent to charge the user | ||
Stripe::PaymentIntent.create({ | ||
amount: amount, | ||
currency: "usd", | ||
customer: user.stripe_id, | ||
payment_method: payment_method_id, | ||
off_session: true, # Charge without active user session | ||
confirm: true, | ||
description: "Penalty for not completing the task: #{note.title}" | ||
}) | ||
else | ||
Rails.logger.error "No payment method found for user #{user.id}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters