Skip to content

Commit 61cd1a5

Browse files
authored
Merge pull request #67 from fatzebra/DASH-4820-make-3ds-cybs-sdk
DASH-4820 add three d secure module
2 parents 00cfd0e + 14b1da2 commit 61cd1a5

13 files changed

Lines changed: 1641 additions & 0 deletions

File tree

lib/fat_zebra.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
require 'fat_zebra/information'
3333
require 'fat_zebra/card'
3434
require 'fat_zebra/authenticate'
35+
require 'fat_zebra/three_d_secure'
3536
require 'fat_zebra/refund'
3637
require 'fat_zebra/payment_plan'
3738
require 'fat_zebra/customer'

lib/fat_zebra/three_d_secure.rb

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# frozen_string_literal: true
2+
3+
module FatZebra
4+
##
5+
# == FatZebra \ThreeDSecure
6+
#
7+
# Manage 3DS2 authentication for the Cybersource REST API
8+
#
9+
# * setup
10+
# * enrollment
11+
# * validation
12+
#
13+
class ThreeDSecure < APIResource
14+
validates :card_token, required: true, on: :setup
15+
16+
CHECK_ENROLLMENT_REQUIRED_FIELDS = %i[
17+
merchant_username
18+
card_token
19+
amount
20+
currency
21+
reference
22+
verification
23+
device_channel
24+
reference_id
25+
return_url
26+
acs_window_size
27+
browser_accept_content
28+
browser_language
29+
browser_java_enabled
30+
browser_color_depth
31+
browser_screen_height
32+
browser_screen_width
33+
browser_time_difference
34+
browser_user_agent
35+
].freeze
36+
37+
CHECK_ENROLLMENT_REQUIRED_FIELDS.each do |field|
38+
validates field, required: true, on: :check_enrollment
39+
end
40+
41+
VALIDATE_AUTHENTICATION_REQUIRED_FIELDS = %i[
42+
merchant_username
43+
card_token
44+
amount
45+
currency
46+
authentication_transaction_id
47+
].freeze
48+
49+
VALIDATE_AUTHENTICATION_REQUIRED_FIELDS.each do |field|
50+
validates field, required: true, on: :validate_authentication
51+
end
52+
53+
class << self
54+
55+
def resource_name
56+
'three_d_secure'
57+
end
58+
59+
def resource_path
60+
"/sdk/#{resource_name}"
61+
end
62+
63+
##
64+
# Sets up a 3ds request
65+
#
66+
# @param [Hash] params
67+
# @param [Hash] options for the request, and configurations (Optional)
68+
#
69+
# @return [FatZebra::ThreeDSecure]
70+
def setup(params = {}, options = {})
71+
valid!(params, :setup) if respond_to?(:valid!)
72+
73+
response = request(:post, "#{resource_path}/setup", params, options)
74+
initialize_from(response)
75+
end
76+
77+
##
78+
# Enrols card
79+
#
80+
# @param [Hash] params
81+
# @param [Hash] options for the request, and configurations (Optional)
82+
#
83+
# @return [FatZebra::ThreeDSecure]
84+
def check_enrollment(params = {}, options = {})
85+
valid!(params, :check_enrollment) if respond_to?(:valid!)
86+
87+
response = request(:post, "#{resource_path}/check_enrollment", params, options)
88+
initialize_from(response)
89+
end
90+
91+
##
92+
# Validates card
93+
#
94+
# @param [Hash] params
95+
# @param [Hash] options for the request, and configurations (Optional)
96+
#
97+
# @return [FatZebra::ThreeDSecure]
98+
def validate_authentication(params = {}, options = {})
99+
valid!(params, :validate_authentication) if respond_to?(:valid!)
100+
101+
response = request(:post, "#{resource_path}/validate_authentication", params, options)
102+
initialize_from(response)
103+
end
104+
end
105+
end
106+
end

spec/cassettes/FatZebra_ThreeDSecure/_check_enrollment/validations/1_2_2_1.yml

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)