class ApplePay::Merchant

Attributes

client_cert[RW]
display_name[RW]
domain[RW]
identifier[RW]
private_key[RW]

Public Class Methods

new(identifier, domain:, display_name:) click to toggle source
# File lib/apple_pay/merchant.rb, line 7
def initialize(identifier, domain:, display_name:)
  self.identifier   = identifier
  self.domain       = domain
  self.display_name = display_name
end

Public Instance Methods

authenticate(client_cert, private_key) click to toggle source
# File lib/apple_pay/merchant.rb, line 13
def authenticate(client_cert, private_key)
  self.client_cert = client_cert # NOTE: Apple Pay Merchant Identity
  self.private_key = private_key
  self
end
http_client() click to toggle source
# File lib/apple_pay/merchant.rb, line 19
def http_client
  client = HTTPClient.new(
    agent_name: "ApplePay Gem (v#{VERSION})"
  )
  client.request_filter << RequestFilter::Debugger.new if ApplePay.debugging?
  client.ssl_config.client_cert = client_cert
  client.ssl_config.client_key  = private_key
  client
end
start_session!(validation_url) click to toggle source
# File lib/apple_pay/merchant.rb, line 29
def start_session!(validation_url)
  handle_response do
    http_client.post validation_url, {
      merchantIdentifier: identifier,
      domainName: domain,
      displayName: display_name
    }.to_json, 'Content-Type': 'application/json'
  end
end

Private Instance Methods

handle_response() { || ... } click to toggle source
# File lib/apple_pay/merchant.rb, line 41
def handle_response
  response = yield
  case response.status
  when 200..201
    JSON.parse(response.body).with_indifferent_access
  else
    raise APIError 'Start Session Failed'
  end
end