module AlphaCard
AlphaCard
is a library for processing payments with Alpha Card Services, Inc.
Constants
- CREDIT_CARD_CODES
Global Payment Systems (NDC)
Credit
Card Authorization Codes@see floristwiki.ftdi.com/images/c/ce/Appendix_A_-_Credit_Card_Authorization_Codes.pdf
Credit
Card Authorization Codes
Attributes
@return [String] Alpha Card Gateway DirectPost API URL.
Public Class Methods
AlphaCard
gem version.
# File lib/alpha_card/version.rb, line 4 def self.gem_version Gem::Version.new VERSION::STRING end
Raises an exception if a network error occurs. It could be request timeout, socket error or anything else.
@param error [Exception] exception object
@raise [APIConnectionError]
Failed request exception.
# File lib/alpha_card.rb, line 110 def handle_connection_errors(error) case error when Timeout::Error, Errno::EINVAL, Errno::ECONNRESET message = "Could not connect to Alpha Card Gateway (#{@api_base}). " \ 'Please check your internet connection and try again. ' \ 'If this problem persists, you should check Alpha Card services status.' when SocketError message = 'Unexpected error communicating when trying to connect to Alpha Card Gateway. ' \ 'You may be seeing this message because your DNS is not working.' else message = 'Unexpected error communicating with Alpha Card Gateway.' end raise APIConnectionError, "#{message}\n\n(Network error: #{error.message})" end
Send secure HTTP(S) request with params to requested URL.
@param url [String] URL @param params [Hash] hash of params for the request
@return [HTTPResponse]
Response of the request as HTTPResponse object
# File lib/alpha_card.rb, line 136 def http_post_request(url, params) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(uri.request_uri) request.set_form_data(params) http.request(request) end
Send the POST request to the AlphaCard
Gateway from the specified account. Request must contains params - Alpha Card transaction variables.
@param params [Hash]
hash with Alpha Card transaction variables and it's values
@param credentials [Hash]
Alpha Card merchant account credentials
@return [AlphaCard::Response]
Response from Alpha Card Gateway.
@raise [APIConnectionError] HTTP request error
@example
response = AlphaCard.request( { cexp: '0720', ccnumber: '4111111111111111', amount: '10.00' }, { username: 'demo', password: 'password' } ) #=> #<AlphaCard::Response:0x1a0fda8 @data={"response"=>"1", "responsetext"=>"SUCCESS", "authcode"=>"123", "transactionid"=>"123", "avsresponse"=>"", "cvvresponse"=>"N", "orderid"=>"", "type"=>"", "response_code"=>"100"}>
# File lib/alpha_card.rb, line 90 def request(params = {}, credentials = Account.credentials) raise ArgumentError, 'You must pass a Hash with Account credentials!' unless Account.valid_credentials?(credentials) begin response = http_post_request(@api_base, params.merge(credentials)) rescue => e handle_connection_errors(e) end Response.new(response.body) end