Class: PaygatePk::Providers::PayFast::Tokenization::Token

Inherits:
Client
  • Object
show all
Defined in:
lib/paygate_pk/providers/pay_fast/tokenization/token.rb

Overview

used to generate the bearer_token

Constant Summary collapse

TOKEN_ENDPOINT =
"/api/token"
DEFAULT_GRANT_TYPE =
"client_credentials"

Instance Method Summary collapse

Methods inherited from Client

#create_checkout, #get_access_token, #get_bearer_token, #initialize, #instruments, #verify_ipn!

Constructor Details

This class inherits a constructor from PaygatePk::Providers::PayFast::Client

Instance Method Details

#get(grant_type: DEFAULT_GRANT_TYPE, options: {}) ⇒ Object

3.1 Authentication Access Token Required: merchant_id, secured_key, grant_type Optional: customer_ip, reserved_1..3, api_version Returns: PaygatePk::Contracts::BearerToken



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/paygate_pk/providers/pay_fast/tokenization/token.rb', line 18

def get(grant_type: DEFAULT_GRANT_TYPE, options: {})
  mid = config.merchant_id
  sec = config.secured_key

  ensure_present!(merchant_id: mid, secured_key: sec, grant_type: grant_type)

  resp = http.post(TOKEN_ENDPOINT, form: body(mid, sec, grant_type, options))

  PaygatePk::Contracts::BearerToken.new(
    access_token: resp["token"], # if present
    refresh_token: resp["refresh_token"], # shown in doc example
    expiry: resp["expiry"],
    code: resp["code"],
    message: resp["message"],
    raw: resp
  )
end