Class: SepayPgRuby::Checkout
- Inherits:
-
Object
- Object
- SepayPgRuby::Checkout
- Defined in:
- lib/sepay_pg_ruby/checkout.rb
Constant Summary collapse
- SIGNABLE_FIELDS =
[ 'merchant', 'operation', 'payment_method', 'order_amount', 'currency', 'order_invoice_number', 'order_description', 'customer_id', 'success_url', 'error_url', 'cancel_url', 'order_id', 'agreement_id', 'agreement_name', 'agreement_type', 'agreement_payment_frequency', 'agreement_amount_per_payment' ].freeze
Instance Method Summary collapse
- #init_checkout_url ⇒ Object
- #init_one_time_payment_fields(fields) ⇒ Object
-
#initialize(client) ⇒ Checkout
constructor
A new instance of Checkout.
- #sign_fields(fields) ⇒ Object
Constructor Details
#initialize(client) ⇒ Checkout
Returns a new instance of Checkout.
26 27 28 |
# File 'lib/sepay_pg_ruby/checkout.rb', line 26 def initialize(client) @client = client end |
Instance Method Details
#init_checkout_url ⇒ Object
30 31 32 |
# File 'lib/sepay_pg_ruby/checkout.rb', line 30 def init_checkout_url "#{@client.base_checkout_url}/init" end |
#init_one_time_payment_fields(fields) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/sepay_pg_ruby/checkout.rb', line 34 def init_one_time_payment_fields(fields) payload = fields.transform_keys(&:to_s).dup payload['merchant'] = @client.merchant_id payload['operation'] ||= 'PURCHASE' payload['signature'] = sign_fields(payload) payload end |
#sign_fields(fields) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/sepay_pg_ruby/checkout.rb', line 42 def sign_fields(fields) normalized = fields.transform_keys(&:to_s) signed = [] # We must iterate over the keys in the order they were added to the hash # to match the insertion-order behavior of the Node.js SDK normalized.keys.each do |field| next unless SIGNABLE_FIELDS.include?(field) next if normalized[field].nil? signed << "#{field}=#{normalized[field]}" end digest = OpenSSL::HMAC.digest('sha256', @client.secret_key, signed.join(',')) Base64.strict_encode64(digest) end |