Sha256: abee4790719eaf531c5ecdd38cb6d2825a5ad44fc329039e4bf7b78a98091ea7

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

require 'cgi'

module WirecardCheckoutPage
  module Toolkit
    class Response
      def self.from_typhoeus_response(response)
        new(response.body, original_response: response)
      end

      def initialize(body, original_response: nil)
        @body = body
        @original_response = original_response
      end

      attr_reader :original_response

      attr_reader :body

      def success?
        status == '0'
      end

      def error_code
        param('errorCode').to_s
      end

      def order_number
        param('orderNumber').to_i
      end

      def params
        { payment_url: original_response.headers['Location'] }
      end

      private

      def status
        param 'status'
      end

      def param(key)
        parsed_body[key].last
      end

      def parsed_body
        @parsed_body ||= CGI::parse(body)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wirecard_checkout_page-0.1.0 lib/wirecard_checkout_page/toolkit/response.rb