module GpWebpay::WebServices

Public Instance Methods

bank_id() click to toggle source
# File lib/gp_webpay/web_services.rb, line 63
def bank_id
  "0100"
end
capture_flag() click to toggle source
# File lib/gp_webpay/web_services.rb, line 67
def capture_flag
  1
end
message_id(type = "") click to toggle source
# File lib/gp_webpay/web_services.rb, line 59
def message_id(type = "")
  "#{order_number}0100#{config.merchant_number}#{type}#{Time.now.to_i}"
end
send_request(request_xml) click to toggle source
# File lib/gp_webpay/web_services.rb, line 11
def send_request(request_xml)
  GpWebpay.logger.debug "WS Raw request: #{request_xml}" if GpWebpay.config.debug
  request = Curl::Easy.new(config.web_services_url)
  request.headers["Content-Type"] = "text/xml;charset=UTF-8"
  request.http_post(request_xml)
  request
end
ws_echo() click to toggle source

Expected output <soapenv:Envelope xmlns:soapenv=“schemas.xmlsoap.org/soap/envelope/”>

<soapenv:Body>
  <ns2:echoResponse xmlns:ns2="http://gpe.cz/pay/pay-ws/core" xmlns="http://gpe.cz/pay/pay-ws/core/type"/>
</soapenv:Body>

</soapenv:Envelope>

# File lib/gp_webpay/web_services.rb, line 27
def ws_echo
  get_params_from(send_request(template.echo).body_str)
end
ws_get_master_payment_status() click to toggle source
# File lib/gp_webpay/web_services.rb, line 52
def ws_get_master_payment_status
  attributes = request_attributes("getMasterPaymentStatus")
  raw_response = send_request(template.get_master_payment_status(attributes)).body_str
  GpWebpay.logger.debug "WS Raw response: #{raw_response}" if GpWebpay.config.debug
  get_params_from(raw_response)
end
ws_get_payment_detail() click to toggle source
# File lib/gp_webpay/web_services.rb, line 38
def ws_get_payment_detail
  attributes = request_attributes("getPaymentDetail")
  raw_response = send_request(template.get_payment_detail(attributes)).body_str
  GpWebpay.logger.debug "WS Raw response: #{raw_response}" if GpWebpay.config.debug
  get_params_from(raw_response)
end
ws_get_payment_status() click to toggle source
# File lib/gp_webpay/web_services.rb, line 45
def ws_get_payment_status
  attributes = request_attributes("getPaymentStatus")
  raw_response = send_request(template.get_payment_status(attributes)).body_str
  GpWebpay.logger.debug "WS Raw response: #{raw_response}" if GpWebpay.config.debug
  get_params_from(raw_response)
end
ws_process_regular_subscription_payment() click to toggle source
# File lib/gp_webpay/web_services.rb, line 31
def ws_process_regular_subscription_payment
  attributes = request_attributes("processRegularSubscriptionPayment")
  raw_response = send_request(template.process_regular_subscription_payment(attributes)).body_str
  GpWebpay.logger.debug "WS Raw response: #{raw_response}" if GpWebpay.config.debug
  get_params_from(raw_response)
end

Private Instance Methods

config() click to toggle source
# File lib/gp_webpay/web_services.rb, line 124
def config
  GpWebpay.config
end
get_params_from(response) click to toggle source
# File lib/gp_webpay/web_services.rb, line 73
def get_params_from(response)
  hash_response = Hash.from_xml(Nokogiri::XML(response).to_s)["Envelope"]["Body"]
  first_lvl_key = hash_response.keys.first
  hash_response = hash_response["#{first_lvl_key}"]
  second_lvl_key = hash_response.keys.last
  hash_response = hash_response["#{second_lvl_key}"]
  GpWebpay.logger.info "Response: #{hash_response}"
  GpWebpay::WebServices::Response.new(hash_response)
end
request_attributes(type = "") click to toggle source
# File lib/gp_webpay/web_services.rb, line 83
def request_attributes(type = "")
  base_attributes = {
    message_id: message_id(type),
    merchant_number: config.merchant_number,
    order_number: order_number,
    digest: ws_verification(type).digest,
  }

  case type
  when "processRegularSubscriptionPayment"
    payment_attributes = {
      merchant_order_number: merchant_order_number,
      master_order_number: master_order_number,
      amount: amount_in_cents,
      capture_flag: capture_flag,
      card_holder_name: card_holder.name,
      card_holder_email: card_holder.email,
      card_holder_phone_country: card_holder.phone_country,
      card_holder_phone: card_holder.phone,
      card_holder_mobile_phone_country: card_holder.mobile_phone_country,
      card_holder_mobile_phone: card_holder.mobile_phone,
      address_match: address_match,
      billing_name: billing.name,
      billing_address1: billing.address1,
      billing_city: billing.city,
      billing_postal_code: billing.postal_code,
      billing_country: billing.country,
      shipping_name: shipping.name,
      shipping_address1: shipping.address1,
      shipping_city: shipping.city,
      shipping_postal_code: shipping.postal_code,
      shipping_country: shipping.country,
      # Deprecated Attrs, will remove
      currency: currency,
    }
    base_attributes.merge(payment_attributes)
  else
    base_attributes
  end
end
template() click to toggle source
# File lib/gp_webpay/web_services.rb, line 128
def template
  GpWebpay::WebServices::Template.new
end
ws_attributes(type) click to toggle source
# File lib/gp_webpay/web_services.rb, line 132
def ws_attributes(type)
  PaymentAttributes.new(self, true, type).to_h
end
ws_verification(type) click to toggle source
# File lib/gp_webpay/web_services.rb, line 136
def ws_verification(type)
  ::GpWebpay::Verification.new(ws_attributes(type))
end