module Braintree class WebhookNotification include BaseModule module Kind SubscriptionCanceled = "subscription_canceled" SubscriptionChargedSuccessfully = "subscription_charged_successfully" SubscriptionChargedUnsuccessfully = "subscription_charged_unsuccessfully" SubscriptionExpired = "subscription_expired" SubscriptionTrialEnded = "subscription_trial_ended" SubscriptionWentActive = "subscription_went_active" SubscriptionWentPastDue = "subscription_went_past_due" SubMerchantAccountApproved = "sub_merchant_account_approved" SubMerchantAccountDeclined = "sub_merchant_account_declined" TransactionDisbursed = "transaction_disbursed" PartnerUserCreated = "partner_user_created" end attr_reader :subscription, :kind, :timestamp, :partner_credentials, :transaction def self.parse(signature, payload) Configuration.gateway.webhook_notification.parse(signature, payload) end def self.verify(challenge) Configuration.gateway.webhook_notification.verify(challenge) end def initialize(gateway, attributes) # :nodoc: @gateway = gateway set_instance_variables_from_hash(attributes) @error_result = ErrorResult.new(gateway, @subject[:api_error_response]) if @subject.has_key?(:api_error_response) @merchant_account = MerchantAccount._new(gateway, @subject[:merchant_account]) if @subject.has_key?(:merchant_account) @partner_credentials = OpenStruct.new(@subject[:partner_credentials]) if @subject.has_key?(:partner_credentials) @subscription = Subscription._new(gateway, @subject[:subscription]) if @subject.has_key?(:subscription) @transaction = Transaction._new(gateway, @subject[:transaction]) if @subject.has_key?(:transaction) end def merchant_account @error_result.nil? ? @merchant_account : @error_result.merchant_account end def errors @error_result.errors if @error_result end def message @error_result.message if @error_result end class << self protected :new def _new(*args) # :nodoc: self.new *args end end end end