Class: PciProxy::Token

Inherits:
Base
  • Object
show all
Defined in:
lib/pci_proxy/token.rb

Constant Summary collapse

SANDBOX_ENDPOINT =
'https://api.sandbox.datatrans.com/upp/services/v1/inline/token'.freeze
LIVE_ENDPOINT =
'https://api.datatrans.com/upp/services/v1/inline/token'.freeze

Constants inherited from Base

Base::JSON_UTF8_CONTENT_TYPE

Instance Attribute Summary

Attributes inherited from Base

#api_endpoint, #api_password, #api_username

Instance Method Summary collapse

Methods inherited from Base

#api_get, #api_post, #client, #error_class

Constructor Details

#initialize(api_username:, api_password:, endpoint: SANDBOX_ENDPOINT) ⇒ Token

Initialise with the specified api_username and api_password from PCI Proxy.

Defaults to the sandbox API endpoint - to use the live environment, supply the LIVE_ENDPOINT constant as the value of the endpoint kwarg



12
13
14
15
16
# File 'lib/pci_proxy/token.rb', line 12

def initialize(api_username:, api_password:, endpoint: SANDBOX_ENDPOINT)
  @api_endpoint = endpoint
  @api_username = api_username
  @api_password = api_password
end

Instance Method Details

#execute(transaction_id:, return_payment_method: true, cvv_mandatory: false) ⇒ PciProxy::Model::TokenisedCard

Perform a token API request to turn the specified transaction_id into card and CVV tokens

Parameters:

  • +return_payment_method+ (true/false)
    • whether or not to return the identified payment method (default: true)

  • +cvv_mandatory+ (true/false)
    • whether or not to consider the CVV alias should be mandatory (default: false)

Returns:

Raises:

  • (PciProxyAPIError)

    in cases where the API responds with a non-200 response code



26
27
28
29
30
31
32
33
# File 'lib/pci_proxy/token.rb', line 26

def execute(transaction_id:, return_payment_method: true, cvv_mandatory: false)
  raise "transaction_id is required" unless transaction_id && !transaction_id.empty?

  PciProxy::Model::TokenisedCard.new(api_get(params: {
      transactionId: transaction_id,
      returnPaymentMethod: return_payment_method,
      mandatoryAliasCVV: cvv_mandatory }))
end