Sha256: adf05201cbeb3d6b082e5532d6a2e919965476e0c04a8ed7a2f69e6675b3b436

Contents?: true

Size: 806 Bytes

Versions: 2

Compression:

Stored size: 806 Bytes

Contents

module FakeBraintree
  class Redirect
    include Helpers

    attr_reader :id

    def initialize(params, merchant_id)
      hash, query = *params[:tr_data].split("|", 2)
      @transparent_data = Rack::Utils.parse_query(query)
      @merchant_id = merchant_id
      @id = create_id(@merchant_id)
      @params = params
    end

    def url
      uri.to_s
    end

    def confirm
      Customer.new(@params["customer"], {:merchant_id => @merchant_id}).create
    end

    private

    def uri
      URI.parse(@transparent_data["redirect_url"]).merge("?#{base_query}&hash=#{hash(base_query)}")
    end

    def base_query
      "http_status=200&id=#{@id}&kind=create_customer"
    end

    def hash(string)
      Braintree::Digest.hexdigest(Braintree::Configuration.private_key, string)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fake_braintree-0.2.1 lib/fake_braintree/redirect.rb
fake_braintree-0.2.0 lib/fake_braintree/redirect.rb