Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/fat_zebra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
require 'fat_zebra/information'
require 'fat_zebra/card'
require 'fat_zebra/authenticate'
require 'fat_zebra/three_d_secure'
require 'fat_zebra/refund'
require 'fat_zebra/payment_plan'
require 'fat_zebra/customer'
Expand Down
106 changes: 106 additions & 0 deletions lib/fat_zebra/three_d_secure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \ThreeDSecure
#
# Manage 3DS2 authentication for the Cybersource REST API
#
# * setup
# * enrollment
# * validation
#
class ThreeDSecure < APIResource
validates :card_token, required: true, on: :setup

CHECK_ENROLLMENT_REQUIRED_FIELDS = %i[
merchant_username
card_token
amount
currency
reference
verification
device_channel
reference_id
return_url
acs_window_size
browser_accept_content
browser_language
browser_java_enabled
browser_color_depth
browser_screen_height
browser_screen_width
browser_time_difference
browser_user_agent
].freeze

CHECK_ENROLLMENT_REQUIRED_FIELDS.each do |field|
validates field, required: true, on: :check_enrollment
end

VALIDATE_AUTHENTICATION_REQUIRED_FIELDS = %i[
merchant_username
card_token
amount
currency
authentication_transaction_id
].freeze

VALIDATE_AUTHENTICATION_REQUIRED_FIELDS.each do |field|
validates field, required: true, on: :validate_authentication
end

class << self

def resource_name
'three_d_secure'
end

def resource_path
"/sdk/#{resource_name}"
end

##
# Sets up a 3ds request
#
# @param [Hash] params
# @param [Hash] options for the request, and configurations (Optional)
#
# @return [FatZebra::ThreeDSecure]
def setup(params = {}, options = {})
valid!(params, :setup) if respond_to?(:valid!)

response = request(:post, "#{resource_path}/setup", params, options)
initialize_from(response)
end

##
# Enrols card

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be viewed as "checking if the card is enrolled", rather than "enrolling the card". This is a common misconception.

#
# @param [Hash] params
# @param [Hash] options for the request, and configurations (Optional)
#
# @return [FatZebra::ThreeDSecure]
def check_enrollment(params = {}, options = {})
valid!(params, :check_enrollment) if respond_to?(:valid!)

response = request(:post, "#{resource_path}/check_enrollment", params, options)
initialize_from(response)
end

##
# Validates card
#
# @param [Hash] params
# @param [Hash] options for the request, and configurations (Optional)
#
# @return [FatZebra::ThreeDSecure]
def validate_authentication(params = {}, options = {})
valid!(params, :validate_authentication) if respond_to?(:valid!)

response = request(:post, "#{resource_path}/validate_authentication", params, options)
initialize_from(response)
end
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading