Class: RubyNative::Webhooks::AppleController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/ruby_native/webhooks/apple_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/ruby_native/webhooks/apple_controller.rb', line 6

def create
  payload = JSON.parse(request.raw_post)
  signed_payload = payload["signedPayload"]
  return head :ok unless signed_payload

  # TEST notifications from Apple have no transaction data to process.
  decoded = JWT.decode(signed_payload, nil, false).first
  return head :ok if decoded["notificationType"] == "TEST"

  processor = RubyNative::IAP::AppleWebhookProcessor.new
  processor.process(signed_payload)

  head :ok
rescue JSON::ParserError
  head :bad_request
rescue RubyNative::IAP::VerificationError, JWT::DecodeError => e
  Rails.logger.error "[RubyNative] Apple webhook verification failed: #{e.message}"
  head :unprocessable_entity
rescue => e
  Rails.logger.error "[RubyNative] Apple webhook error: #{e.message}"
  head :internal_server_error
end