Class: PciProxy::Check
Constant Summary collapse
- SANDBOX_ENDPOINT =
'https://api.sandbox.datatrans.com/v1/transactions/validate'.freeze
- LIVE_ENDPOINT =
'https://api.datatrans.com/v1/transactions/validate'.freeze
- CHF =
'CHF'.freeze
- EUR =
'EUR'.freeze
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#api_endpoint, #api_password, #api_username
Instance Method Summary collapse
-
#execute(reference:, card_token:, card_type:, expiry_month:, expiry_year:, currency: nil) ⇒ Hash
Perform a check API request to verify the card token.
-
#initialize(api_username:, api_password:, endpoint: SANDBOX_ENDPOINT) ⇒ Check
constructor
Initialise with the specified
api_username
andapi_password
from PCI Proxy.
Methods inherited from Base
#api_get, #api_post, #client, #error_class
Constructor Details
#initialize(api_username:, api_password:, endpoint: SANDBOX_ENDPOINT) ⇒ Check
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
18 19 20 21 22 |
# File 'lib/pci_proxy/check.rb', line 18 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(reference:, card_token:, card_type:, expiry_month:, expiry_year:, currency: nil) ⇒ Hash
Perform a check API request to verify the card token
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/pci_proxy/check.rb', line 36 def execute(reference:, card_token:, card_type:, expiry_month:, expiry_year:, currency: nil) raise "reference is required" if reference.empty? raise "card_token is required" unless card_token && !card_token.empty? raise "card_type must be one of 'visa', 'mastercard' or 'amex'" unless [:visa, :mastercard, :amex].include?(card_type.to_sym) raise "invalid expiry_month" unless (1..12).include?(expiry_month.to_i) raise "invalid expiry_year" unless expiry_year.to_i > 0 # default the currency where not specified - according to the documentation Amex should use EUR, Visa and MC should use CHF currency ||= :amex == card_type.to_sym ? EUR : CHF card = { alias: card_token, expiryMonth: expiry_month.to_s, expiryYear: expiry_year.to_s.chars.last(2).join } body = { refno: reference, currency: currency, card: card } PciProxy::Model::CheckResult.new(api_post(endpoint: @api_endpoint, body: body, raise_on_error: false)) end |