Class: Monri::Tokens

Inherits:
Object
  • Object
show all
Defined in:
lib/monri/tokens.rb,
lib/monri/tokens/ephemeral_card_token_response.rb

Defined Under Namespace

Classes: EphemeralCardTokenResponse

Constant Summary collapse

TEMP_TOKENIZE_REQUIRED_FIELDS =
[:cvv, :type, :pan, :expiration_date, :temp_card_id, :digest, :timestamp]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configMonri::Config

Returns:



5
6
7
# File 'lib/monri/tokens.rb', line 5

def config
  @config
end

#http_clientMonri::HttpClient

Returns:



8
9
10
# File 'lib/monri/tokens.rb', line 8

def http_client
  @http_client
end

Instance Method Details

#create_ephemeral_card_token(params) ⇒ Object

Note:

Create ephemeral (lasting for a very short time - 15minutes in this case) - token to replace card details.

Required fields are: pan, expiration_date(YYMM), cvv, type (card). Optional fields are: tokenize_pan: bool

Parameters:

  • params (Hash)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/monri/tokens.rb', line 15

def create_ephemeral_card_token(params)

  EphemeralCardTokenResponse.create do
    ensure_configured!

    # If there's no temp-card-id, create one
    unless params.has_key?(:temp_card_id)
      params.merge!(create_card_token)
    end

    missing_keys = TEMP_TOKENIZE_REQUIRED_FIELDS.reject { |k| params.has_key?(k) }

    params[:authenticity_token] = config.authenticity_token

    if missing_keys.length > 0
      raise Monri::Errors::InvalidArgumentsError.new("Missing required keys=#{missing_keys.join(', ')}")
    end

    #  TODO: assert if merchant has PCI-DSS certificate - request pci-dss access token
    http_response = http_client.post('/v2/temp-tokenize', params)
    if http_response.failed?
      raise http_response.exception
    elsif http_response.success?
      http_response.body
    else
      #  TODO: handle this case
    end
  end
end