lib/buckaruby/request.rb in buckaruby-1.0.0 vs lib/buckaruby/request.rb in buckaruby-1.0.1

- old
+ new

@@ -22,11 +22,11 @@ raw_response = post_buckaroo(uri, build_request_data(options)) response = parse_response(raw_response) @logger.debug("[execute] response: #{response.inspect}") - return response + response end def build_request_params(_options) raise NotImplementedError end @@ -57,29 +57,29 @@ params[:add_buckaruby] = "Buckaruby #{Buckaruby::VERSION}" # Sign the data with our secret key. params[:brq_signature] = Signature.generate_signature(params, @options) - return params + params end def post_data(params) - return params.map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&") + params.map { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&") end def parse_response(body) query = CGI.parse(body) query.each { |key, value| query[key] = value.first } - return query + query end def test? - return @options[:mode] == :test + @options[:mode] == :test end def api_url - return test? ? Urls::TEST_URL : Urls::PRODUCTION_URL + test? ? Urls::TEST_URL : Urls::PRODUCTION_URL end end # Base class for a transaction request. class TransactionRequest < Request @@ -100,24 +100,20 @@ params[:brq_clientip] = options[:client_ip] if options[:client_ip] params[:brq_description] = options[:description] if options[:description] params[:brq_return] = options[:return_url] if options[:return_url] - return params + params end def build_transaction_request_params(_options) raise NotImplementedError end end # Request for a creating a new transaction. class SetupTransactionRequest < TransactionRequest - def execute(options) - super(options.merge(action: Action::PAY)) - end - def build_transaction_request_params(options) params = {} case options[:payment_method] when PaymentMethod::IDEAL @@ -128,18 +124,21 @@ ) when PaymentMethod::SEPA_DIRECT_DEBIT params.merge!( brq_service_sepadirectdebit_action: Action::PAY, brq_service_sepadirectdebit_customeriban: options[:account_iban], - brq_service_sepadirectdebit_customeraccountname: options[:account_name], - brq_service_sepadirectdebit_collectdate: (Date.today + 5).strftime("%Y-%m-%d") + brq_service_sepadirectdebit_customeraccountname: options[:account_name] ) if options[:account_bic] params[:brq_service_sepadirectdebit_customerbic] = options[:account_bic] end + if options[:collect_date] + params[:brq_service_sepadirectdebit_collectdate] = options[:collect_date].strftime("%Y-%m-%d") + end + if options[:mandate_reference] params.merge!( brq_service_sepadirectdebit_action: [Action::PAY, Action::EXTRA_INFO].join(","), brq_service_sepadirectdebit_mandatereference: options[:mandate_reference], brq_service_sepadirectdebit_mandatedate: Date.today.strftime("%Y-%m-%d") @@ -147,20 +146,16 @@ end end params[:brq_startrecurrent] = options[:recurring] if options[:recurring] - return params + params end end # Request for a creating a recurrent transaction. class RecurrentTransactionRequest < TransactionRequest - def execute(options) - super(options.merge(action: Action::PAY_RECURRENT)) - end - def build_transaction_request_params(options) params = {} key = :"brq_service_#{options[:payment_method]}_action" params[key] = Action::PAY_RECURRENT @@ -169,11 +164,11 @@ # This is needed to make recurrent payments working. params[:brq_channel] = "backoffice" params[:brq_originaltransaction] = options[:transaction_id] - return params + params end end # Request for getting the status of a transaction. class StatusRequest < Request @@ -185,9 +180,9 @@ params = {} params[:brq_transaction] = options[:transaction_id] if options[:transaction_id] params[:brq_payment] = options[:payment_id] if options[:payment_id] - return params + params end end end