Class: Mercanet::Payment
- Inherits:
-
Object
- Object
- Mercanet::Payment
- Defined in:
- lib/mercanet/payment.rb
Class Method Summary collapse
-
.new_payment(amount, currency_code = '978', order_channel = 'INTERNET', transaction_reference) ⇒ Object
currency_code Euro = 978 order_channel Internet = INTERNET.
Class Method Details
.new_payment(amount, currency_code = '978', order_channel = 'INTERNET', transaction_reference) ⇒ Object
currency_code Euro = 978 order_channel Internet = INTERNET
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mercanet/payment.rb', line 12 def self.new_payment(amount, currency_code = '978', order_channel = 'INTERNET', transaction_reference) data = { amount: amount, automaticResponseUrl: Mercanet.automatic_response_url, currencyCode: currency_code, interfaceVersion: Mercanet.interface_version, keyVersion: Mercanet.key_version, merchantId: Mercanet.merchant_id, normalReturnUrl: Mercanet.normal_return_url, orderChannel: order_channel, transactionReference: transaction_reference } data_to_seal = data.except(:keyVersion) concatenate = data_to_seal.sort.to_h.values.join key = Mercanet.secret_key seal = OpenSSL::HMAC.hexdigest('SHA256', key, concatenate) data[:seal] = seal uri = URI("#{Mercanet.url}/rs-services/v2/paymentInit") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' => 'application/json'}) http.verify_mode = OpenSSL::SSL::VERIFY_NONE if Mercanet.development? req.body = data.to_json response = http.request(req) JSON.parse(response.body) end |