Class: Pesepay::Pesepay
- Inherits:
-
Object
- Object
- Pesepay::Pesepay
- Defined in:
- lib/pesepay.rb
Instance Attribute Summary collapse
-
#result_url ⇒ Object
Returns the value of attribute result_url.
-
#return_url ⇒ Object
Returns the value of attribute return_url.
Instance Method Summary collapse
- #check_payment(reference_number) ⇒ Object
- #create_seamless_transaction(currency_code, payment_method_code, customer_email = nil, customer_phone = nil, customer_name = nil) ⇒ Object
- #create_transaction(amount, currency_code, reason_for_payment, reference) ⇒ Object
- #get_payment_method_code(currency_code) ⇒ Object
-
#initialize(integration_key, encryption_key) ⇒ Pesepay
constructor
A new instance of Pesepay.
- #initiate_transaction(transaction) ⇒ Object
- #make_seamless_payment(payment, reason_for_payment, amount, payment_method_required_fields, reference = nil) ⇒ Object
- #poll_transaction(poll_url) ⇒ Object
Constructor Details
#initialize(integration_key, encryption_key) ⇒ Pesepay
Returns a new instance of Pesepay.
16 17 18 19 |
# File 'lib/pesepay.rb', line 16 def initialize(integration_key, encryption_key) @integration_key = integration_key @encryption_key = encryption_key end |
Instance Attribute Details
#result_url ⇒ Object
Returns the value of attribute result_url.
14 15 16 |
# File 'lib/pesepay.rb', line 14 def result_url @result_url end |
#return_url ⇒ Object
Returns the value of attribute return_url.
14 15 16 |
# File 'lib/pesepay.rb', line 14 def return_url @return_url end |
Instance Method Details
#check_payment(reference_number) ⇒ Object
59 60 61 62 |
# File 'lib/pesepay.rb', line 59 def check_payment(reference_number) url = "https://api.pesepay.com/api/payments-engine/v1/payments/check-payment?referenceNumber=#{reference_number}" poll_transaction(url) end |
#create_seamless_transaction(currency_code, payment_method_code, customer_email = nil, customer_phone = nil, customer_name = nil) ⇒ Object
25 26 27 |
# File 'lib/pesepay.rb', line 25 def create_seamless_transaction(currency_code, payment_method_code, customer_email = nil, customer_phone = nil, customer_name = nil) Payment.new(currency_code, payment_method_code, customer_email, customer_phone, customer_name) end |
#create_transaction(amount, currency_code, reason_for_payment, reference) ⇒ Object
21 22 23 |
# File 'lib/pesepay.rb', line 21 def create_transaction(amount, currency_code, reason_for_payment, reference) Transaction.new(amount, currency_code, reason_for_payment, reference) end |
#get_payment_method_code(currency_code) ⇒ Object
39 40 41 42 |
# File 'lib/pesepay.rb', line 39 def get_payment_method_code(currency_code) response = get_payment_method_code_request(currency_code) process_get_code_method(response) end |
#initiate_transaction(transaction) ⇒ Object
29 30 31 32 |
# File 'lib/pesepay.rb', line 29 def initiate_transaction(transaction) response = create_transaction_request(transaction) process_response(response) end |
#make_seamless_payment(payment, reason_for_payment, amount, payment_method_required_fields, reference = nil) ⇒ Object
34 35 36 37 |
# File 'lib/pesepay.rb', line 34 def make_seamless_payment(payment, reason_for_payment, amount, payment_method_required_fields, reference = nil) response = create_seamless_payment_request(payment, reason_for_payment, amount, payment_method_required_fields, reference) process_response(response) end |
#poll_transaction(poll_url) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pesepay.rb', line 44 def poll_transaction(poll_url) url = URI(poll_url) http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["Authorization"] = @integration_key request["Content-Type"] = "application/json" response = http.request(request) process_poll_response(response) end |