Module: Pesapal::Post

Defined in:
lib/pesapal/merchant/post.rb

Class Method Summary collapse

Class Method Details

.generate_post_xml(details) ⇒ Object

build html encoded xml string for PostPesapalDirectOrderV4



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pesapal/merchant/post.rb', line 6

def Post.generate_post_xml(details)
    
    # build xml with input data, the format is standard so no editing is
    # required
    post_xml = ''
    post_xml.concat '<?xml version="1.0" encoding="utf-8"?>'
    post_xml.concat '<PesapalDirectOrderInfo '
    post_xml.concat 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
    post_xml.concat 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
    post_xml.concat "Amount=\"#{details[:amount]}\" "
    post_xml.concat "Description=\"#{details[:description]}\" "
    post_xml.concat "Type=\"#{details[:type]}\" "
    post_xml.concat "Reference=\"#{details[:reference]}\" "
    post_xml.concat "FirstName=\"#{details[:first_name]}\" "
    post_xml.concat "LastName=\"#{details[:last_name]}\" "
    post_xml.concat "Email=\"#{details[:email]}\" "
    post_xml.concat "PhoneNumber=\"#{details[:phonenumber]}\" "
    post_xml.concat 'xmlns="http://www.pesapal.com" />'

    encoder = HTMLEntities.new(:xhtml1)
    post_xml = encoder.encode post_xml

    "#{post_xml}"
end

.set_parameters(callback_url, consumer_key, post_xml) ⇒ Object

set parameters required by the PostPesapalDirectOrderV4 call



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pesapal/merchant/post.rb', line 32

def Post.set_parameters(callback_url, consumer_key, post_xml)

    # parameters required by the PostPesapalDirectOrderV4 call (excludes
    # oauth_signature parameter as per the instructions here
    # http://developer.pesapal.com/how-to-integrate/api-reference#PostPesapalDirectOrderV4)
    
    timestamp = Time.now.to_i.to_s

    params = { :oauth_callback => callback_url,
               :oauth_consumer_key => consumer_key,
               :oauth_nonce => "#{timestamp}" + Pesapal::Oauth.generate_nonce(12),
               :oauth_signature_method => 'HMAC-SHA1',
               :oauth_timestamp => "#{timestamp}",
               :oauth_version => '1.0',
               :pesapal_request_data => post_xml
            }
end