class AmazonPay::Sanitize

Removes PII and other sensitive data for the logger

Public Class Methods

new(input_data) click to toggle source
# File lib/amazon_pay/sanitize.rb, line 6
def initialize(input_data)
  @copy = input_data ? input_data.dup : ''
end

Public Instance Methods

sanitize_request_data() click to toggle source
# File lib/amazon_pay/sanitize.rb, line 10
def sanitize_request_data
  # Array of item to remove

  patterns = %w[
    Buyer
    PhysicalDestination
    BillingAddress
    AuthorizationBillingAddress
    SellerNote
    SellerAuthorizationNote
    SellerCaptureNote
    SellerRefundNote
  ]

  patterns.each do |s|
    @copy.gsub!(/([?|&]#{s}=)[^\&]+/ms, s + '=*REMOVED*')
  end

  @copy
end
sanitize_response_data() click to toggle source
# File lib/amazon_pay/sanitize.rb, line 31
def sanitize_response_data
  # Array of item to remove

  patterns = []
  patterns.push(%r{(?<=<Buyer>).*(?=<\/Buyer>)}s)
  patterns.push(%r{(?<=<PhysicalDestination>).*(?=<\/PhysicalDestination>)}ms)
  patterns.push(%r{(?<=<BillingAddress>).*(?=<\/BillingAddress>)}s)
  patterns.push(%r{(?<=<SellerNote>).*(?=<\/SellerNote>)}s)
  patterns.push(%r{(?<=<AuthorizationBillingAddress>).*(?=<\/AuthorizationBillingAddress>)}s)
  patterns.push(%r{(?<=<SellerAuthorizationNote>).*(?=<\/SellerAuthorizationNote>)}s)
  patterns.push(%r{(?<=<SellerCaptureNote>).*(?=<\/SellerCaptureNote>)}s)
  patterns.push(%r{(?<=<SellerRefundNote>).*(?=<\/SellerRefundNote>)}s)

  patterns.each do |s|
    @copy.gsub!(s, '*REMOVED*')
  end

  @copy
end