lib/pesapal/merchant.rb in pesapal-1.2.0 vs lib/pesapal/merchant.rb in pesapal-1.2.1

- old
+ new

@@ -3,15 +3,15 @@ class Merchant attr_accessor :config, :order_details def config - @config + @config ||= {} end def order_details - @order_details + @order_details ||= {} end private def api_domain @@ -48,24 +48,26 @@ @post_xml = nil @token_secret = nil set_mode mode - # set the credentials if we have not set a custom path for the YAML config file - if path_to_file.nil? - # no path to file so no YAML override so we load from initializer - set_configuration PesapalRails::Application.config.yaml[@mode] - else - # we have custom path so we load from file + # set the credentials if we have specified a path from which we + # will access a YAML file with the configurations + unless path_to_file.nil? set_configuration_from_yaml path_to_file end end # generate pesapal order url (often iframed) def generate_order_url + # check if the config is empty, if yes, we try load what was set by the initializer into Pesapal.config + if config.empty? + set_configuration Pesapal.config[@mode] + end + # build xml with input data, the format is standard so no editing is # required @post_xml = Pesapal::Post::generate_post_xml @order_details # initialize setting of @params (oauth_signature left empty) @@ -81,10 +83,15 @@ end # query the details of the transaction def query_payment_details(merchant_reference, transaction_tracking_id) + # check if the config is empty, if yes, we try load what was set by the initializer into Pesapal.config + if config.empty? + set_configuration Pesapal.config[@mode] + end + # initialize setting of @params (oauth_signature left empty) @params = Pesapal::Details::set_parameters(@config[:consumer_key], merchant_reference, transaction_tracking_id) # generate oauth signature and add signature to the request parameters @params[:oauth_signature] = Pesapal::Oauth::generate_oauth_signature("GET", @api_endpoints[:querypaymentdetails], @params, @config[:consumer_secret], @token_secret) @@ -103,11 +110,16 @@ :transaction_tracking_id => response[0] } end # query the status of the transaction def query_payment_status(merchant_reference, transaction_tracking_id = nil) - + + # check if the config is empty, if yes, we try load what was set by the initializer into Pesapal.config + if config.empty? + set_configuration Pesapal.config[@mode] + end + # initialize setting of @params (oauth_signature left empty) @params = Pesapal::Status::set_parameters(@config[:consumer_key], merchant_reference, transaction_tracking_id) # generate oauth signature and add signature to the request parameters @params[:oauth_signature] = Pesapal::Oauth::generate_oauth_signature("GET", @api_endpoints[:querypaymentstatus], @params, @config[:consumer_secret], @token_secret) @@ -123,20 +135,20 @@ response["pesapal_response_data"][0] end # set mode when called def set_mode(mode = :development) - + # convert symbol to string and downcase @mode = "#{mode.to_s.downcase}" # set api endpoints depending on the mode set_endpoints end # listen to ipn response def ipn_listener(notification_type, merchant_reference, transaction_tracking_id) - + status = query_payment_status(merchant_reference, transaction_tracking_id) output = { :status => status } if status == "COMPLETED"