Class: DkPaymentGateway::PullPayment

Inherits:
Object
  • Object
show all
Defined in:
lib/dk_payment_gateway/pull_payment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ PullPayment

Returns a new instance of PullPayment.



7
8
9
# File 'lib/dk_payment_gateway/pull_payment.rb', line 7

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/dk_payment_gateway/pull_payment.rb', line 5

def client
  @client
end

Class Method Details

.generate_stan(source_app_suffix, transaction_identifier = nil) ⇒ String

Generate STAN number

Parameters:

  • source_app_suffix (String)

    Last 4 digits of source_app (e.g., “0201”)

  • transaction_identifier (String) (defaults to: nil)

    8-digit identifier (timestamp or counter)

Returns:

  • (String)

    12-digit STAN number



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dk_payment_gateway/pull_payment.rb', line 74

def self.generate_stan(source_app_suffix, transaction_identifier = nil)
  suffix = source_app_suffix.to_s[-4..]

  identifier = if transaction_identifier
                 transaction_identifier.to_s[-8..]
               else
                 # Generate from current timestamp (HHMMSSMS format)
                 time = Time.now
                 format('%02d%02d%02d%02d', time.hour, time.min, time.sec, time.usec / 10_000)
               end

  "#{suffix}#{identifier}"
end

Instance Method Details

#authorize(params) ⇒ Hash

Payment Gateway Authorization (Account inquiry and OTP request)

Parameters:

  • params (Hash)

    Authorization parameters

Options Hash (params):

  • :transaction_datetime (String)

    Transaction timestamp in UTC (ISO 8601)

  • :stan_number (String)

    12-digit unique transaction number

  • :transaction_amount (Numeric)

    Amount of the transaction

  • :transaction_fee (Numeric)

    Transaction fee (use 0 if no fee)

  • :payment_desc (String)

    Payment description

  • :account_number (String)

    Beneficiary account number

  • :account_name (String)

    Beneficiary account name

  • :email_id (String)

    Beneficiary email (optional)

  • :phone_number (String)

    Beneficiary phone number

  • :remitter_account_number (String)

    Remitter account number

  • :remitter_account_name (String)

    Remitter account name

  • :remitter_bank_id (String)

    Remitter bank identifier

Returns:

  • (Hash)

    Response containing bfs_txn_id, stan_number, account_number, remitter_account_number



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dk_payment_gateway/pull_payment.rb', line 28

def authorize(params)
  validate_authorization_params!(params)

  request_body = build_authorization_body(params)
  signature_headers = generate_signature_headers(request_body)

  response = client.post(
    '/v1/account_auth/pull-payment',
    body: request_body.to_json,
    headers: signature_headers
  )

  validate_response!(response, 'Authorization')
  response['response_data']
end

#debit(params) ⇒ Hash

Payment Gateway Debit Request Completes a previously authorized payment by verifying OTP

Parameters:

  • params (Hash)

    Debit request parameters

Options Hash (params):

  • :request_id (String)

    Unique identifier for the request

  • :bfs_txn_id (String)

    Transaction ID from authorization

  • :bfs_remitter_otp (String)

    OTP sent to remitter

  • :bfs_order_no (String)

    Order number (optional)

Returns:

  • (Hash)

    Response containing bfs_txn_id, code, description



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/dk_payment_gateway/pull_payment.rb', line 54

def debit(params)
  validate_debit_params!(params)

  request_body = build_debit_body(params)
  signature_headers = generate_signature_headers(request_body)

  response = client.post(
    '/v1/debit_request/pull-payment',
    body: request_body.to_json,
    headers: signature_headers
  )

  validate_response!(response, 'Debit')
  response['response_data']
end