Class: Pesapal::OrderUrl
- Inherits:
-
Object
- Object
- Pesapal::OrderUrl
- Defined in:
- lib/mobile-money/pesapal/order_url.rb
Constant Summary collapse
- HTTP_METHOD =
'get'
- API_ACTION =
'/API/PostPesapalDirectOrderV4'
Instance Attribute Summary collapse
-
#callback_url ⇒ Object
readonly
Returns the value of attribute callback_url.
-
#post_data_xml ⇒ Object
readonly
Returns the value of attribute post_data_xml.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #api_domain ⇒ Object
- #consumer ⇒ Object
- #consumer_key ⇒ Object
- #consumer_secret ⇒ Object
- #escaped_xml ⇒ Object
-
#initialize(post_data_xml, callback_url, test = true) ⇒ OrderUrl
constructor
A new instance of OrderUrl.
- #params ⇒ Object
- #params_to_string ⇒ Object
- #request_url ⇒ Object
- #signed_request ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(post_data_xml, callback_url, test = true) ⇒ OrderUrl
Returns a new instance of OrderUrl.
14 15 16 17 18 19 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 14 def initialize(post_data_xml, callback_url, test=true) @post_data_xml = post_data_xml @callback_url = callback_url @token = nil @test = test end |
Instance Attribute Details
#callback_url ⇒ Object (readonly)
Returns the value of attribute callback_url.
9 10 11 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 9 def callback_url @callback_url end |
#post_data_xml ⇒ Object (readonly)
Returns the value of attribute post_data_xml.
9 10 11 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 9 def post_data_xml @post_data_xml end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
9 10 11 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 9 def test @test end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 9 def token @token end |
Instance Method Details
#api_domain ⇒ Object
21 22 23 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 21 def api_domain test ? 'http://demo.pesapal.com' : 'https://www.pesapal.com' end |
#consumer ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 29 def consumer @consumer ||= begin OAuth::Consumer.new(consumer_key, consumer_secret, { site: api_domain, http_method: HTTP_METHOD, scheme: :query_string }) end end |
#consumer_key ⇒ Object
39 40 41 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 39 def consumer_key Rails.application.secrets.pesapal_consumer_key end |
#consumer_secret ⇒ Object
43 44 45 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 43 def consumer_secret Rails.application.secrets.pesapal_consumer_secret end |
#escaped_xml ⇒ Object
71 72 73 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 71 def escaped_xml HTMLEntities.new.encode(post_data_xml) end |
#params ⇒ Object
56 57 58 59 60 61 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 56 def params @params ||= { 'oauth_callback' => callback_url, 'pesapal_request_data' => escaped_xml, } end |
#params_to_string ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 63 def params_to_string strings = [] params.each do |key, value| strings << "#{key}=#{ERB::Util.url_encode(value)}" end strings.join('&') end |
#request_url ⇒ Object
51 52 53 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 51 def request_url API_ACTION + "?" + params_to_string end |
#signed_request ⇒ Object
47 48 49 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 47 def signed_request consumer.create_signed_request HTTP_METHOD, request_url, nil, {}, params end |
#url ⇒ Object
25 26 27 |
# File 'lib/mobile-money/pesapal/order_url.rb', line 25 def url "#{api_domain}#{signed_request.path}" end |