class AmexTokenizationClient
developer.americanexpress.com/products/amex-token-service/resources
Constants
- VERSION
Attributes
base_path[R]
client_id[R]
client_secret[R]
encryption_key[R]
encryption_key_id[R]
host[R]
logger[RW]
token_requester_id[R]
Public Class Methods
new(host:, token_requester_id:, client_id:, client_secret:, encryption_key_id:, encryption_key:, logger: Logger.new('/dev/null'))
click to toggle source
# File lib/amex_tokenization_client.rb, line 20 def initialize(host:, token_requester_id:, client_id:, client_secret:, encryption_key_id:, encryption_key:, logger: Logger.new('/dev/null')) @host = host @base_path = "/payments/digital/v2/tokens".freeze @token_requester_id = token_requester_id @client_id, @client_secret = client_id, client_secret @encryption_key_id, @encryption_key = encryption_key_id, Base64.decode64(encryption_key) @logger = logger end
Public Instance Methods
headers(authorization)
click to toggle source
# File lib/amex_tokenization_client.rb, line 95 def headers(authorization) Hash[ 'Content-Type' => 'application/json', 'Content-Language' => 'en-US', 'Accept-Language' => 'en', 'x-amex-token-requester-id' => token_requester_id, 'x-amex-api-key' => client_id, 'x-amex-request-id' => SecureRandom.uuid, 'authorization' => authorization, ] end
hmac_digest(s)
click to toggle source
# File lib/amex_tokenization_client.rb, line 87 def hmac_digest(s) Base64.strict_encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, client_secret, s.to_s)) end
jwe_decrypt(data)
click to toggle source
# File lib/amex_tokenization_client.rb, line 67 def jwe_decrypt(data) JWE.decrypt(data, encryption_key) end
metadata(token_ref_id)
click to toggle source
# File lib/amex_tokenization_client.rb, line 55 def metadata(token_ref_id) JSON.parse send_authorized_request('GET', "#{token_ref_id}/metadata") end
new_request(method, resource_path, authorization)
click to toggle source
# File lib/amex_tokenization_client.rb, line 91 def new_request(method, resource_path, authorization) Request.new(method, "https://#{host}/#{resource_path}", headers(authorization), logger: logger) end
notifications(kargs)
click to toggle source
# File lib/amex_tokenization_client.rb, line 47 def notifications(kargs) send_authorized_request('POST', 'notifications', notifications_payload(kargs)) end
notifications_payload(kargs)
click to toggle source
# File lib/amex_tokenization_client.rb, line 63 def notifications_payload(kargs) NotificationsPayload.new(kargs).to_json(encryption_key_id, encryption_key) end
provisioning(kargs)
click to toggle source
@return [Hash] token_ref_id and other values.
# File lib/amex_tokenization_client.rb, line 34 def provisioning(kargs) response = JSON.parse send_authorized_request('POST', 'provisioning', provisioning_payload(kargs)) response.merge! JSON.parse jwe_decrypt response.delete('secure_token_data') response end
provisioning_payload(kargs)
click to toggle source
# File lib/amex_tokenization_client.rb, line 59 def provisioning_payload(kargs) ProvisioningPayload.new(kargs).to_json(encryption_key_id, encryption_key) end
provisionings(kargs)
click to toggle source
@return [Hash] token_ref_id and other values.
# File lib/amex_tokenization_client.rb, line 41 def provisionings(kargs) response = JSON.parse send_authorized_request('POST', 'provisionings', provisioning_payload(kargs)) response.merge! JSON.parse jwe_decrypt response.delete('secure_token_data') response end
status(token_ref_id)
click to toggle source
# File lib/amex_tokenization_client.rb, line 51 def status(token_ref_id) JSON.parse send_authorized_request('GET', "#{token_ref_id}/status") end