Class: PurchaseKit::Purchase::CompletionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PurchaseKit::Purchase::CompletionsController
- Defined in:
- app/controllers/purchase_kit/purchase/completions_controller.rb
Overview
Demo mode only - simulates purchase completion for Xcode StoreKit testing
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/purchase_kit/purchase/completions_controller.rb', line 7 def create return head :not_found unless PurchaseKit.config.demo_mode? intent = Intent::Demo.find(params[:id]) # Simulate a subscription.created webhook event = { type: "subscription.created", customer_id: intent.customer_id.to_s, subscription_id: "sub_#{SecureRandom.hex(12)}", store: "apple", store_product_id: intent.product.apple_product_id, subscription_name: "Demo Subscription", status: "active", current_period_start: Time.current.iso8601, current_period_end: 1.month.from_now.iso8601, ends_at: nil, success_path: intent.success_path } # Publish the event (triggers callbacks and Pay integration if available) PurchaseKit::Events.publish(:subscription_created, event) # Queue for Pay if available PurchaseKit::Pay::Webhook.queue(event) if PurchaseKit.pay_enabled? redirect_to intent.success_path || main_app.root_path, notice: "Purchase completed!" rescue PurchaseKit::NotFoundError head :not_found end |