<commit_before># frozen_string_literal: true
module Api
  module Stateless
    module Braintree
      class PaymentMethodsController < StatelessController
        before_filter :authenticate_request!

        def index
          @payment_methods = PaymentHelper::Braintree.payment_methods_for_member(@current_member)
        end

        def destroy
          @payment_method = PaymentHelper::Braintree.payment_method_for_member(member: @current_member, id: params[:id])

          result = begin
                     ::Braintree::PaymentMethod.delete(@payment_method.token)
                   rescue ::Braintree::NotFoundError
                     @payment_method.destroy
                   end

          @payment_method.destroy if result.success?

          # TODO: return something else if `destroy` returns false.
          render json: { success: true }
        end
      end
    end
  end
end<commit_msg>Log when payment method not found on braintree<commit_after># frozen_string_literal: true
module Api
  module Stateless
    module Braintree
      class PaymentMethodsController < StatelessController
        before_filter :authenticate_request!

        def index
          @payment_methods = PaymentHelper::Braintree.payment_methods_for_member(@current_member)
        end

        def destroy
          @payment_method = PaymentHelper::Braintree.payment_method_for_member(member: @current_member, id: params[:id])

          begin
            ::Braintree::PaymentMethod.delete(@payment_method.token)
          rescue ::Braintree::NotFoundError
            Rails.logger.error("Payment Method #{@payment_method.token} not found on Braintree")
          end

          @payment_method.destroy

          render json: { success: true }
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06670403587443946, 'fraction_numerical': 0.0, 'mean_word_length': 2.5207100591715976, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '259114', 'n_tokens_mistral': 460, 'n_tokens_neox': 447, 'n_words': 107}