Last active
March 29, 2022 14:34
-
-
Save BrianDunlap89/499582b32e4a599ac7a7cb065d7f3f9e to your computer and use it in GitHub Desktop.
WMT Stale Tip Disbursement (Latest - March 2022)
This file contains hidden or 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
| # Paste these into console | |
| # Change `#create` to `#build` for dry runs in *2* locations | |
| def create_instant_pay_credit_line_item(gig) | |
| gig.line_items.create(category: :promotional_credit, amount: 2, description: "Instant pay credit.") | |
| end | |
| def create_instant_pay_credit_transaction(gig, payment_account, gli) | |
| gig.payment_transactions.create( | |
| payment_account: payment_account, | |
| subject: gig, | |
| profile_id: payment_account.profile_id, | |
| gig_line_item: gli, | |
| category: gli.category, | |
| amount: gli.amount, | |
| description: 'Credit', | |
| transaction_type: :credit, | |
| itemization: { | |
| taxable_amount: gli.amount, | |
| nontaxable_amount: 0 | |
| } | |
| ) | |
| end |
This file contains hidden or 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
| # accumulators and data to operate on | |
| # generally speaking, paste this only once | |
| pt_ids = [ 0, 0, 0 ] ; pt_ids.count # replace with real values | |
| profile_ids = [ 0, 0, 0 ] ; profile_ids.count # replace with real values | |
| pts_processed = [] | |
| pts_unprocessed = [] | |
| profiles_processed = [] | |
| profiles_unprocessed = [] | |
| profiles = Profile.where(id: profile_ids).order(:id); profiles.count | |
| # profiles = profiles.where.not(id: profiles_processed).order(:id); profiles.count |
This file contains hidden or 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
| # send payments | |
| # comment 2 indicated lines below for dry run | |
| # change the `limit` as you see fit on the next line | |
| profiles.limit(1).find_each do |p| | |
| if profiles_processed.include?(p.id) | |
| puts "Skipping already-processed profile #{p.id}" | |
| next | |
| end | |
| pts = p.transactions.where(id: pt_ids, status: :held) | |
| puts "Total tip transactions to be paid to profile #{p.id}: #{pts.count}" | |
| if pts.count == 0 | |
| puts "Skipping profile #{p.id} - no payment_transactions found" | |
| profiles_unprocessed << p.id | |
| next | |
| end | |
| latest_pt = pts.order(id: :asc).last | |
| latest_gig = latest_pt.gig | |
| transactions_paid_count = 0 | |
| pts.each do |pt| | |
| if pt.reload.status != 'held' | |
| puts "Skipping payment transaction #{pt.id} because status is NOT HELD." | |
| pts_unprocessed << pt.id | |
| elsif pt.reload.category != 'net_tip' | |
| puts "Skipping payment transaction #{pt.id} because category is NOT NET_TIP." | |
| pts_unprocessed << pt.id | |
| elsif pt.gig_line_item.amount != pt.amount | |
| puts "Skipping payment transaction #{pt.id} because AMT DOES NOT MATCH LINE ITEM AMT." | |
| pts_unprocessed << pt.id | |
| else | |
| # comment below for dry run | |
| V2::GigTipDisbursement.new(pt).process | |
| transactions_paid_count += 1 | |
| pts_processed << pt.id | |
| gtl = GigTipLog.create(gig_id: pt.gig_id, operation: :manually_processed) | |
| puts "Tip log recorded for gig: #{pt.gig_id}." | |
| end | |
| end | |
| puts "Total transactions paid to driver #{p.id}: #{transactions_paid_count}." | |
| profiles_processed << p.id | |
| next unless transactions_paid_count > 0 | |
| ip_gli = create_instant_pay_credit_line_item(latest_gig) | |
| ip_payment_transaction = create_instant_pay_credit_transaction(latest_gig, latest_pt.payment_account, ip_gli) | |
| # comment below for dry run | |
| PaymentEvent.send(ip_payment_transaction) | |
| puts "Instant pay credit submitted to driver #{p.id}." | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment