Class: PaygatePk::Providers::PayFast::Auth
- Defined in:
- lib/paygate_pk/providers/pay_fast/auth.rb
Overview
Auth client for PayFast API
Constant Summary collapse
- ENDPOINT =
"/Ecommerce/api/Transaction/GetAccessToken"
Instance Method Summary collapse
-
#get_access_token(basket_id:, amount:, currency: PaygatePk.config.default_currency, endpoint: ENDPOINT) ⇒ Object
Returns Contracts::AccessToken Required by PayFast: MERCHANT_ID, SECURED_KEY, BASKET_ID, TXNAMT, CURRENCY_CODE.
Methods inherited from Client
#create_checkout, #get_bearer_token, #initialize, #instruments, #verify_ipn!
Constructor Details
This class inherits a constructor from PaygatePk::Providers::PayFast::Client
Instance Method Details
#get_access_token(basket_id:, amount:, currency: PaygatePk.config.default_currency, endpoint: ENDPOINT) ⇒ Object
Returns Contracts::AccessToken Required by PayFast: MERCHANT_ID, SECURED_KEY, BASKET_ID, TXNAMT, CURRENCY_CODE
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/paygate_pk/providers/pay_fast/auth.rb', line 15 def get_access_token(basket_id:, amount:, currency: PaygatePk.config.default_currency, endpoint: ENDPOINT) ensure_config! ensure_args!(basket_id: basket_id, amount: amount, currency: currency) # Guide endpoint: .../Ecommerce/api/Transaction/GetAccessToken resp = http.post(endpoint, form: payload(basket_id, amount, currency)) token = resp.is_a?(Hash) ? (resp["ACCESS_TOKEN"] || resp["access_token"]) : nil raise AuthError, "missing ACCESS_TOKEN in response" unless token Contracts::AccessToken.new(token: token, raw: resp) end |