class PostalTransfersPl::Client
Attributes
configuration[RW]
error_report[RW]
response[RW]
client[RW]
Public Class Methods
configure() { |configuration| ... }
click to toggle source
# File lib/postal_transfers_pl.rb, line 12 def self.configure self.configuration ||= Configuration.new yield(configuration) end
confirm_mass_order(id:)
click to toggle source
# File lib/postal_transfers_pl.rb, line 109 def self.confirm_mass_order(id:) self.new.client.call( PostalTransfersPl::Client.configuration.confirm.to_sym, message: { 'v1:UIP' => id } ) @response = self.track_mass_order(id: id) self.trigger_payment_tracking(id: id) end
confirm_or_destroy_mass_order(id:)
click to toggle source
# File lib/postal_transfers_pl.rb, line 83 def self.confirm_or_destroy_mass_order(id:) @response = self.track_mass_order(id: id) case response.fetch(:stan) when 'OdrzuconyZPowoduBleduWeryfikacji', 'NIEOBSLUGIWANY' self.destroy_mass_order(id: id) when 'UtworzonyCzekaNaWeryfikacjeMKP' sleep 5 self.confirm_or_destroy_mass_order(id: id) when 'ZweryfikowanyOczekujacyNaZatwierdzenie' self.confirm_mass_order(id: id) else @error_report = 'File is invalid!' end error_report.blank? ? response : { error: error_report } end
create_mass_order(service_name:, file_path:, auto_approve: false)
click to toggle source
# File lib/postal_transfers_pl.rb, line 72 def self.create_mass_order(service_name:, file_path:, auto_approve: false) file_name = File.basename(URI.parse(file_path.path).path) api_file_name = Regexp.new(PostalTransfersPl::Client.configuration.file_name_regexp.to_s).match(file_name).to_s + '.csv' base = Base64.encode64(file_path.read) resp = self.new.client.call( PostalTransfersPl::Client.configuration.create.to_sym, message: { 'v1:RodzajUslugi' => service_name, 'v1:NazwaPliku' => api_file_name, 'v1:ZawartoscPliku' => base, 'v1:ZatwierdzenieAutomatyczne' => auto_approve } ).to_hash.fetch((PostalTransfersPl::Client.configuration.create.to_s + '_response').to_sym) self.confirm_or_destroy_mass_order(id: resp.fetch(:uip)) end
destroy_mass_order(id:)
click to toggle source
# File lib/postal_transfers_pl.rb, line 99 def self.destroy_mass_order(id:) doc = self.list_documents(id: id)[:opis_dokumentu] doc_id = doc[:identyfikator] @error_report = doc_id.blank? ? nil : Base64.decode64(self.read_document(id: doc_id)) self.new.client.call( PostalTransfersPl::Client.configuration.delete.to_sym, message: { 'v1:UIP' => id } ) end
list_documents(id:)
click to toggle source
# File lib/postal_transfers_pl.rb, line 125 def self.list_documents(id:) self.new.client.call( PostalTransfersPl::Client.configuration.list_documents.to_sym, message: { 'v1:UIP' => id } ).to_hash.fetch((PostalTransfersPl::Client.configuration.list_documents.to_s + '_response').to_sym).fetch(:lista_dokumentow) end
new()
click to toggle source
# File lib/postal_transfers_pl.rb, line 43 def initialize raise 'No configuration credentials provided !' if PostalTransfersPl::Client.configuration.blank? @client = Savon.client( wsdl: PostalTransfersPl::Client.configuration.wsdl, ssl_version: PostalTransfersPl::Client.configuration.ssl_version.to_sym, log: true, pretty_print_xml: true, namespace_identifier: PostalTransfersPl::Client.configuration.namespace.to_sym, namespaces: {"xmlns:#{PostalTransfersPl::Client.configuration.namespace}" => PostalTransfersPl::Client.configuration.namespace_uri}, wsse_auth: [PostalTransfersPl::Client.configuration.user, PostalTransfersPl::Client.configuration.password], headers: {'Content-Type' => 'text/xml;charset=utf-8;'} ) end
payment_tracking(id:)
click to toggle source
# File lib/postal_transfers_pl.rb, line 64 def self.payment_tracking(id:) self.trigger_payment_tracking(id: id) self.new.client.call( PostalTransfersPl::Client.configuration.payment_tracking.to_sym, message: { 'v1:UIP' => id } ).to_hash.fetch((PostalTransfersPl::Client.configuration.payment_tracking.to_s + '_response').to_sym).fetch(:stan_oplacenia_pakietu) end
read_document(id:)
click to toggle source
# File lib/postal_transfers_pl.rb, line 132 def self.read_document(id:) self.new.client.call( PostalTransfersPl::Client.configuration.read_document.to_sym, message: { 'v1:IdentyfikatorDokumentu' => id } ).to_hash.fetch((PostalTransfersPl::Client.configuration.read_document.to_s + '_response').to_sym).fetch(:zawartosc_dokumentu) end
track_mass_order(id:)
click to toggle source
# File lib/postal_transfers_pl.rb, line 57 def self.track_mass_order(id:) self.new.client.call( PostalTransfersPl::Client.configuration.track.to_sym, message: { 'v1:UIP' => id } ).to_hash.fetch((PostalTransfersPl::Client.configuration.track.to_s + '_response').to_sym).fetch(:pakiet) end
trigger_payment_tracking(id:)
click to toggle source
# File lib/postal_transfers_pl.rb, line 118 def self.trigger_payment_tracking(id:) self.new.client.call( PostalTransfersPl::Client.configuration.payment_tracking_trigger.to_sym, message: { 'v1:UIP' => id } ) end