Skip to content

Commit

Permalink
Prepare stripe for 100% off coupons
Browse files Browse the repository at this point in the history
  • Loading branch information
iHiD committed Nov 8, 2024
1 parent 5f37655 commit 420f1f5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/commands/user/generate_bootcamp_affiliate_coupon_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ class User::GenerateBootcampAffiliateCouponCode

initialize_with :user

current_user.bootcamp_affiliate_coupon_code.present?
current_user.bootcamp_free_coupon_code.present?

def call
# Easy cheap guard
return if user_data.bootcamp_affiliate_coupon_code.present?
Expand Down
1 change: 1 addition & 0 deletions app/commands/user/generate_bootcamp_free_coupon_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def call
def generate_coupon_code
promo_code = Stripe::PromotionCode.create(
coupon: COUPON_ID,
max_redemptions: 1,
metadata: {
user_id: user.id
}
Expand Down
1 change: 1 addition & 0 deletions app/controllers/bootcamp_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def stripe_create_checkout_session
session = Stripe::Checkout::Session.create({
ui_mode: 'embedded',
customer_email: @bootcamp_data.email,
customer_creation: "always",
line_items: [{
price: stripe_price,
quantity: 1
Expand Down
1 change: 1 addition & 0 deletions config/initializers/stripe.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'stripe'

Stripe.api_key = Exercism.secrets.stripe_secret_key
Stripe.api_version = '2024-10-28.acacia'
4 changes: 3 additions & 1 deletion test/models/user/generate_bootcamp_free_coupon_code_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ class User::GenerateBootcampFreeCouponCodeTest < ActiveSupport::TestCase
user = create :user
code = SecureRandom.hex(6)
Stripe::PromotionCode.expects(:create).with(
coupon: "OarhoKrd", metadata: { user_id: user.id }
coupon: "OarhoKrd",
max_redemptions: 1,
metadata: { user_id: user.id }
).returns(OpenStruct.new(code:))

User::GenerateBootcampFreeCouponCode.(user)
Expand Down

0 comments on commit 420f1f5

Please sign in to comment.