Skip to content

Commit

Permalink
Add basic setup
Browse files Browse the repository at this point in the history
Tweaks

Add todo

Fix things

Remove nav shadow (#7109)

Update copy on `DonationStep` (#7083)

* Update copy on `DonationStep`

* Remove old `DonationStep`

* Adjust test

Update CODEOWNERS (#7091)

Don't consider bootcamp purchases to be donations

Tweaks
  • Loading branch information
iHiD committed Oct 28, 2024
1 parent 223cc20 commit 7282ae3
Show file tree
Hide file tree
Showing 90 changed files with 5,123 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/commands/payments/payment/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Payments::Payment::Create
initialize_with :user, :provider, :external_id, :amount_in_cents, :external_receipt_url, subscription: nil

def call
# TODO: Check product id here!

Payments::Payment.create!(
user:,
provider:,
Expand Down
15 changes: 15 additions & 0 deletions app/commands/payments/stripe/payment_intent/handle_success.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(id: nil, payment_intent: nil)

def call
return unless user
return unless should_record_payment?

subscription = Payments::Stripe::Subscription::Create.(user, subscription_data) if subscription_data
Payments::Stripe::Payment::Create.(user, payment_intent, subscription:)
Expand All @@ -35,6 +36,20 @@ def subscription_data
Stripe::Subscription.retrieve(invoice.subscription)
end

memoize
def should_record_payment?
return true if subscription_data

charge = Stripe::Charge.retrieve(payment_intent.latest_charge)

# If there is an email, then it's the Bootcamp.
# If there's not an email, then through our integration.
# This is terrible, I know.
charge.billing_details.email.blank?
rescue StandardError
true
end

memoize
def payment_intent
@payment_intent || Stripe::PaymentIntent.retrieve(id)
Expand Down
49 changes: 49 additions & 0 deletions app/controllers/bootcamp_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class BootcampController < ApplicationController
layout false
COMPLETE_PRICE = 149.99
PART_1_PRICE = 99.99

def index
@full_complete_price = COMPLETE_PRICE
@full_part_1_price = PART_1_PRICE

if Rails.env.production?
begin
data = JSON.parse(RestClient.get("https://vpnapi.io/api/#{request.remote_ip}?key=#{Exercism.config.vpnapi_key}").body)
@country_code_2 = data.dig("location", "country_code")
@is_vpn = data.dig("security", "vpn")
rescue StandardError
# Rate limit probably
end
else
@country_code_2 = "BA"
@is_vpn = false
end

country_data = DATA[@country_code_2]
if country_data && !@is_vpn
@country_name = country_data[0]
@hello = country_data[1]

@has_discount = true
@complete_price = country_data[2].to_f
@part_1_price = country_data[3].to_f
@full_payment_url = country_data[4]
@part_1_payment_url = country_data[5]

@discount_percentage = ((COMPLETE_PRICE - @complete_price) / COMPLETE_PRICE * 100).round
else
@has_discount = false
@full_payment_link = "https://buy.stripe.com/14k9BE4FBcyBeDmf0f"
@part_1_payment_link = "https://buy.stripe.com/6oE4hk9ZVfKNeDm7xO"
end
end

DATA = JSON.parse(File.read(Rails.root / 'config' / 'bootcamp.json')).freeze
end

#
# Full: buy.stripe.com/9AQ5logoj1TX52MaEE
# Full with code: ?prefilled_promo_code=XXX
#
#
Loading

0 comments on commit 7282ae3

Please sign in to comment.