Module: AlphaCard
- Defined in:
- lib/alpha_card.rb,
lib/alpha_card/account.rb,
lib/alpha_card/version.rb,
lib/alpha_card/resource.rb,
lib/alpha_card/response.rb,
lib/alpha_card/attribute.rb,
lib/alpha_card/transaction.rb,
lib/alpha_card/resources/order.rb,
lib/alpha_card/resources/billing.rb,
lib/alpha_card/transactions/auth.rb,
lib/alpha_card/transactions/sale.rb,
lib/alpha_card/transactions/void.rb,
lib/alpha_card/resources/shipping.rb,
lib/alpha_card/transactions/credit.rb,
lib/alpha_card/transactions/refund.rb,
lib/alpha_card/transactions/update.rb,
lib/alpha_card/transactions/capture.rb,
lib/alpha_card/transactions/validate.rb,
lib/alpha_card/errors/validation_error.rb,
lib/alpha_card/errors/api_connection_error.rb,
lib/alpha_card/errors/invalid_attribute_type.rb,
lib/alpha_card/errors/invalid_attribute_value.rb,
lib/alpha_card/errors/invalid_attribute_format.rb
Overview
AlphaCard is a library for processing payments with Alpha Card Services, Inc.
Defined Under Namespace
Modules: Attribute, VERSION Classes: APIConnectionError, Account, Auth, Billing, Capture, Credit, InvalidAttributeFormat, InvalidAttributeType, InvalidAttributeValue, Order, Refund, Resource, Response, Sale, Shipping, Transaction, Update, Validate, ValidationError, Void
Constant Summary collapse
- CREDIT_CARD_CODES =
Global Payment Systems (NDC) Credit Card Authorization Codes
YAML.load_file(File.('../alpha_card/data/credit_card_codes.yml', __FILE__))
Class Attribute Summary collapse
-
.api_base ⇒ String
Alpha Card Gateway DirectPost API URL.
Class Method Summary collapse
-
.gem_version ⇒ Object
AlphaCard gem version.
-
.handle_connection_errors(error) ⇒ Object
Raises an exception if a network error occurs.
-
.http_post_request(url, params) ⇒ HTTPResponse
Send secure HTTP(S) request with params to requested URL.
-
.request(params = {}, credentials = Account.credentials) ⇒ AlphaCard::Response
Send the POST request to the AlphaCard Gateway from the specified account.
Class Attribute Details
.api_base ⇒ String
Returns Alpha Card Gateway DirectPost API URL.
54 55 56 |
# File 'lib/alpha_card.rb', line 54 def api_base @api_base end |
Class Method Details
.gem_version ⇒ Object
AlphaCard gem version.
4 5 6 |
# File 'lib/alpha_card/version.rb', line 4 def self.gem_version Gem::Version.new VERSION::STRING end |
.handle_connection_errors(error) ⇒ Object
Raises an exception if a network error occurs. It could be request timeout, socket error or anything else.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/alpha_card.rb', line 110 def handle_connection_errors(error) case error when Timeout::Error, Errno::EINVAL, Errno::ECONNRESET = "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 = 'Unexpected error communicating when trying to connect to Alpha Card Gateway. ' \ 'You may be seeing this message because your DNS is not working.' else = 'Unexpected error communicating with Alpha Card Gateway.' end raise APIConnectionError, "#{}\n\n(Network error: #{error.})" end |
.http_post_request(url, params) ⇒ HTTPResponse
Send secure HTTP(S) request with params to requested URL.
136 137 138 139 140 141 142 143 144 145 146 147 |
# 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 |
.request(params = {}, credentials = Account.credentials) ⇒ AlphaCard::Response
Send the POST request to the AlphaCard Gateway from the specified account. Request must contains params - Alpha Card transaction variables.
90 91 92 93 94 95 96 97 98 99 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 |