Module: AlphaCard

Defined in:
lib/alpha_card.rb,
lib/alpha_card/utils.rb,
lib/alpha_card/version.rb,
lib/alpha_card/objects/sale.rb,
lib/alpha_card/objects/order.rb,
lib/alpha_card/objects/account.rb,
lib/alpha_card/objects/billing.rb,
lib/alpha_card/objects/shipping.rb,
lib/alpha_card/alpha_card_object.rb,
lib/alpha_card/alpha_card_response.rb,
lib/alpha_card/errors/alpha_card_error.rb,
lib/alpha_card/errors/api_connection_error.rb

Overview

AlphaCard is a library for processing payments with Alpha Card Services, Inc.

Defined Under Namespace

Classes: APIConnectionError, Account, AlphaCardError, AlphaCardObject, AlphaCardResponse, Billing, Order, Sale, Shipping, Utils

Constant Summary collapse

CREDIT_CARD_CODES =

Global Payment Systems (NDC) Credit Card Authorization Codes

YAML.load_file(File.expand_path('../alpha_card/data/credit_card_codes.yml', __FILE__))
VERSION =

Version information for AlphaCard gem.

'0.2.4'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_baseString


39
40
41
# File 'lib/alpha_card.rb', line 39

def api_base
  @api_base
end

Class Method Details

.request(params = {}, account) ⇒ AlphaCard::AlphaCardResponse

Send the POST request to the AlphaCard Gateway from the specified account. Request must contains params - Alpha Card transaction variables.

Examples:

account = AlphaCard::Account.new('demo', 'password')
response = AlphaCard.request(
  {
    cexp: '0720',
    ccnumber: '4111111111111111',
    amount: '10.00'
  },
  account
)

#=> #<AlphaCard::AlphaCardResponse:0x1a0fda8 @data={"response"=>"1",
    "responsetext"=>"SUCCESS", "authcode"=>"123", "transactionid"=>"123",
    "avsresponse"=>"", "cvvresponse"=>"N", "orderid"=>"", "type"=>"",
    "response_code"=>"100"}>

account = AlphaCard::Account.new('demo', 'password')
response = AlphaCard.request(
  {
    cexp: '0720',
    ccnumber: '123',
    amount: '10.00'
  },
  account
)

#=> AlphaCard::AlphaCardError: AlphaCard::AlphaCardError

Raises:


85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/alpha_card.rb', line 85

def self.request(params = {}, )
  fail AlphaCardError, 'You must set credentials to create the sale!' unless .filled?

  begin
    response = RestClient.post(@api_base, params.merge(.attributes))
  rescue => e
    handle_connection_errors(e)
  end

  alpha_card_response = AlphaCardResponse.new(response.to_str)
  handle_alpha_card_errors(alpha_card_response)

  alpha_card_response
end