lib/fawry/contracts/refund_request_contract.rb in fawry-0.3.0 vs lib/fawry/contracts/refund_request_contract.rb in fawry-1.0.0
- old
+ new
@@ -4,14 +4,26 @@
module Fawry
module Contracts
class RefundRequestContract < Dry::Validation::Contract
params do
- required(:merchant_code).value(:string)
required(:reference_number).value(:string)
required(:refund_amount).value(:decimal)
- required(:fawry_secure_key).value(:string)
+ optional(:merchant_code).value(:string)
+ optional(:fawry_secure_key).value(:string)
optional(:reason).value(:string)
+ end
+
+ rule(:fawry_secure_key) do
+ if ENV['FAWRY_SECURE_KEY'].nil? && value.nil?
+ key(:fawry_secure_key).failure('fawry secure key is required as a param or an env var')
+ 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