Class: ApplePay::Merchant

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_pay/merchant.rb

Defined Under Namespace

Classes: APIError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, domain:, display_name:) ⇒ Merchant

Returns a new instance of Merchant.



7
8
9
10
11
# 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

Instance Attribute Details

#client_certObject

Returns the value of attribute client_cert.



5
6
7
# File 'lib/apple_pay/merchant.rb', line 5

def client_cert
  @client_cert
end

#display_nameObject

Returns the value of attribute display_name.



5
6
7
# File 'lib/apple_pay/merchant.rb', line 5

def display_name
  @display_name
end

#domainObject

Returns the value of attribute domain.



5
6
7
# File 'lib/apple_pay/merchant.rb', line 5

def domain
  @domain
end

#identifierObject

Returns the value of attribute identifier.



5
6
7
# File 'lib/apple_pay/merchant.rb', line 5

def identifier
  @identifier
end

#private_keyObject

Returns the value of attribute private_key.



5
6
7
# File 'lib/apple_pay/merchant.rb', line 5

def private_key
  @private_key
end

Instance Method Details

#authenticate(client_cert, private_key) ⇒ Object



13
14
15
16
17
# 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_clientObject



19
20
21
22
23
24
25
26
27
# 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) ⇒ Object



29
30
31
32
33
34
35
36
37
# 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