Class: Vpago::AcledaV2::Checkout

Inherits:
Base
  • Object
show all
Defined in:
lib/vpago/acleda_v2/checkout.rb

Overview

Single class handling all three modes (khqr, card, deeplink). Two-step ACLEDA flow: openSessionV2 (JSON, here) yields paymentTokenid + sessionid, then either an auto-POST form to paymentPage.jsp (KHQR/Card) or a JS deeplink redirect (Deep Link).

Constant Summary

Constants inherited from Base

Base::CONTENT_TYPE_JSON, Base::PURCHASE_DESC

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#action_url, #amount, #app_scheme, #callback_url, #continue_success_url, #expiry_time, #get_txn_status_url, #hmac512, #initialize, #login_id, #merchant_id, #merchant_name, #open_session_hash, #open_session_url, #opr_device, #order_number, #parse_json, #password, #payment_method, #payment_number, #platform, #purchase_currency, #purchase_date, #secret, #txn_status_hash, #xpay_service_base_url

Constructor Details

This class inherits a constructor from Vpago::AcledaV2::Base

Instance Attribute Details

#error_messageObject (readonly)

Returns the value of attribute error_message.



10
11
12
# File 'lib/vpago/acleda_v2/checkout.rb', line 10

def error_message
  @error_message
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vpago/acleda_v2/checkout.rb', line 12

def call
  @error_message = nil
  @response = open_session

  if @response.status != 500 && @response.status != 200
    @error_message = 'Server Error'
  elsif @response.status == 500 # mostly when passing a wrong parameter name
    @error_message = @response.body
  elsif json_response.dig('result', 'code') != 0 # invalid payload, wrong loginId, etc.
    @error_message = json_response.dig('result', 'errorDetails') || 'Unknown Error'
  end

  update_payment_source

  self
end

Deep Link redirect target.



59
60
61
62
63
# File 'lib/vpago/acleda_v2/checkout.rb', line 59

def deeplink_url
  return nil if failed?

  json_response.dig('result', 'deeplinkUrl')
end

#failed?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/vpago/acleda_v2/checkout.rb', line 29

def failed?
  @error_message.present?
end

#gateway_paramsObject

KHQR/Card secure web redirect form fields (auto-POSTed to paymentPage.jsp).



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/vpago/acleda_v2/checkout.rb', line 38

def gateway_params
  return {} if failed?

  {
    merchantID: merchant_id,
    sessionid: json_response.dig('result', 'sessionid'),
    paymenttokenid: payment_token_id,
    description: Base::PURCHASE_DESC,
    expirytime: expiry_time,
    amount: amount,
    quantity: '1',
    item: '1',
    invoiceid: order_number,
    currencytype: purchase_currency,
    transactionID: payment_number,
    successUrlToReturn: continue_success_url,
    errorUrl: continue_success_url
  }
end

#json_responseObject



33
34
35
# File 'lib/vpago/acleda_v2/checkout.rb', line 33

def json_response
  @json_response ||= parse_json(@response.body)
end