Class: Powerpay21

Inherits:
Object
  • Object
show all
Defined in:
lib/powerpay21.rb

Overview

Main class for Powerpay21 API

Constant Summary collapse

URL_HASH =

Constants - URLs

{
			:demo => {
						:init => "https://pay4.powercash21.com/powercash21-3-2/payment/init", 
				        :pre_auth => "https://pay4.powercash21.com/powercash21-3-2/backoffice/payment_preauthorize",
				        :auth => "https://pay4.powercash21.com/powercash21-3-2/backoffice/payment_authorize",
				        :refund => "https://pay4.powercash21.com/powercash21-3-2/backoffice/payment_refund",
				        :reveral => "https://pay4.powercash21.com/powercash21-3-2/backoffice/payment_reversal",
				        :capture => "https://pay4.powercash21.com/powercash21-3-2/backoffice/payment_capture"					

			},
			:live => {
				  		:init => "https://pay4.powercash21.com/powercash21-3-2/payment/init", 
				        :pre_auth => "https://pay4.powercash21.com/powercash21-3-2/backoffice/payment_preauthorize",
				        :auth => "https://pay4.powercash21.com/powercash21-3-2/backoffice/payment_authorize",
				        :refund => "https://pay4.powercash21.com/powercash21-3-2/backoffice/payment_refund",
				        :reveral => "https://pay4.powercash21.com/powercash21-3-2/backoffice/payment_reversal",
				        :capture => "https://pay4.powercash21.com/powercash21-3-2/backoffice/payment_capture"
			}
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(merchantid, secret, live = false) ⇒ Powerpay21

Returns a new instance of Powerpay21.



32
33
34
35
36
37
38
39
40
# File 'lib/powerpay21.rb', line 32

def initialize(merchantid, secret, live=false)
	@merchantid=merchantid
	@secret=secret
	if live
		@live_demo=:live
	else
		@live_demo=:demo
	end
end

Class Method Details

.helpObject



43
44
45
# File 'lib/powerpay21.rb', line 43

def self.help
	puts "This is a Powerpay21 API. Check our website for Guide"
end

Instance Method Details

#authorize(params) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/powerpay21.rb', line 47

def authorize(params)
	uri = URI(URL_HASH[@live_demo][:auth])

	signature = calculate_signature(params)

	params['signature'] = signature

	res = Net::HTTP.post_form(uri, params)
end

#calculate_signature(params) ⇒ Object

Calculates the SHA1Sum signature for give param hash by sorting the keys in ascending order



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/powerpay21.rb', line 59

def calculate_signature(params)
	raw_string = ""
	params.sort.each do |key,value|
		raw_string += value
	end

	sha1 = Digest::SHA1.new

	sha1 << raw_string

	return sha1.hexdigest || ""

end

#cancelObject



85
86
# File 'lib/powerpay21.rb', line 85

def cancel
end

#captureObject



76
77
# File 'lib/powerpay21.rb', line 76

def capture
end

#cftObject



82
83
# File 'lib/powerpay21.rb', line 82

def cft
end

#pre_authorizeObject



73
74
# File 'lib/powerpay21.rb', line 73

def pre_authorize
end

#refundObject



79
80
# File 'lib/powerpay21.rb', line 79

def refund
end

#statusObject



88
89
# File 'lib/powerpay21.rb', line 88

def status
end