|
| 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 |
0 commit comments