Sha256: 040307805a1ecfc3628af9a798900997f5f5a42d2769cc8704cf23495c1004b6

Contents?: true

Size: 974 Bytes

Versions: 2

Compression:

Stored size: 974 Bytes

Contents

# frozen_string_literal: true

require 'dry-validation'

module Fawry
  module Contracts
    class CreateCardTokenRequestContract < Dry::Validation::Contract
      params do
        required(:customer_profile_id).value(:string)
        required(:customer_mobile).value(:string)
        required(:merchant_code).value(:string)
        required(:customer_email).value(:string)
        required(:card_number).value(:string)
        required(:expiry_year).value(:string)
        required(:expiry_month).value(:string)
        required(:cvv).value(:string)
      end

      rule(:customer_email) do
        unless /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.match?(value)
          key? && key.failure('has invalid format')
        end
      end

      rule(:merchant_code) do
        if ENV['FAWRY_MERCHANT_CODE'].nil? && value.nil?
          key(:merchant_code).failure('fawry merchant code is required as a param or an env var')
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fawry-1.2.1 lib/fawry/contracts/create_card_token_request_contract.rb
fawry-1.1.1 lib/fawry/contracts/create_card_token_request_contract.rb