Class: RubyNative::IAP::CompletionsController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- RubyNative::IAP::CompletionsController
- Includes:
- Decodable, Verifiable
- Defined in:
- app/controllers/ruby_native/iap/completions_controller.rb
Constant Summary
Constants included from Verifiable
Verifiable::APPLE_ROOT_CERT_PATH
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
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 37 38 |
# File 'app/controllers/ruby_native/iap/completions_controller.rb', line 9 def create intent = PurchaseIntent.find_by!(uuid: params[:uuid]) return head :ok if intent.completed? transaction = verify_transaction!(intent) intent.update!(status: :completed, environment: transaction["environment"]&.downcase) event = Event.new( type: "subscription.created", status: "active", owner_token: intent.customer_id, product_id: transaction["productId"], original_transaction_id: transaction["originalTransactionId"], transaction_id: transaction["transactionId"], purchase_date: (transaction["purchaseDate"]), expires_date: (transaction["expiresDate"]), environment: transaction["environment"]&.downcase, notification_uuid: SecureRandom.uuid, success_path: intent.success_path ) RubyNative.fire_subscription_callbacks(event) head :ok rescue ActiveRecord::RecordNotFound head :not_found rescue VerificationError, JWT::DecodeError => e Rails.logger.warn "[RubyNative] Completion verification failed: #{e.}" head :unprocessable_entity end |