Class: ApplePay::PaymentToken

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_pay/payment_token.rb,
lib/apple_pay/payment_token/signature.rb,
lib/apple_pay/payment_token/encrypted_data.rb,
lib/apple_pay/payment_token/certificate_chain.rb

Defined Under Namespace

Classes: CertificateChain, EncryptedData, Signature

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ PaymentToken

Returns a new instance of PaymentToken.



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

def initialize(token)
  self.token = token.with_indifferent_access
end

Instance Attribute Details

#tokenObject

Returns the value of attribute token.



3
4
5
# File 'lib/apple_pay/payment_token.rb', line 3

def token
  @token
end

Instance Method Details

#decrypt!(client_cert, private_key) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/apple_pay/payment_token.rb', line 20

def decrypt!(client_cert, private_key)
  decrypted = EncryptedData.new(
    token[:paymentData][:data]
  ).decrypt!(
    client_cert,
    private_key,
    token[:paymentData][:header][:ephemeralPublicKey]
  )
  JSON.parse decrypted
end

#verify!Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/apple_pay/payment_token.rb', line 9

def verify!
  Signature.new(
    token[:paymentData][:signature],
    data: token[:paymentData][:data],
    ephemeral_public_key: token[:paymentData][:header][:ephemeralPublicKey],
    transaction_id: token[:paymentData][:header][:transactionId],
    application_data: token[:paymentData][:header][:applicationData]
  ).verify!
  self
end