alpha_card 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ca151fb5ff57a0e885ee58031cc037b36bff410
4
- data.tar.gz: a2c4814fd862a98e1cc26b0b0bdac870368e5e15
3
+ metadata.gz: 8d1b3608b60661b5688717b2f96768ac0e36a83c
4
+ data.tar.gz: 8d0a9f755a5faa7802d36feac0828bd1d3877cc1
5
5
  SHA512:
6
- metadata.gz: 5c36aeb545f3ee57bb5477d6bc09669edda527e5335da16e6c3a5ba09a631be81502694c0906d6270e860375ac1228dac145947f42544e54a2a50abb5517af85
7
- data.tar.gz: 516c6219c3ca1ad01646f3052f0bcb7b8849f00e77f68a7aefd2931d69b99703a80fce250e2686c3fbbdd10275b069c807c4e36a3f34dceedee8edf9e95660de
6
+ metadata.gz: c752b3a03ce5299126ae280a3456d7d7507803e63a8c0bd0cca7dd3cffaa2ec34764694da072d962658666d7b876231ba3b026a27d99554edbfb87d075729d9b
7
+ data.tar.gz: 531987ff7b2dcf6555e29816eccd92394bbf6d1577219064e321020a6a75713d8c37c7037e1a117a8d77ef5c7f184f6ab6a7834108676467419bf1970cdb92b0
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'alpha_card'
3
- gem.version = '0.1.3'
3
+ gem.version = '0.1.4'
4
4
  gem.date = '2014-06-25'
5
5
  gem.summary = 'Alpha Card Services DirectPost API for Ruby'
6
6
  gem.description = 'Gem for creating sales with Alpha Card Services DirectPost API'
@@ -15,14 +15,24 @@ require 'alpha_card/order'
15
15
  require 'alpha_card/sale'
16
16
 
17
17
  module AlphaCard
18
+ # DirectPost API URL
18
19
  @api_base = 'https://secure.alphacardgateway.com/api/transact.php'
19
20
 
21
+ # Global Payment Systems (NDC) Credit Card Authorization Codes
20
22
  CREDIT_CARD_CODES = YAML.load_file(File.expand_path('../alpha_card/data/codes.yml', __FILE__)) unless defined? CREDIT_CARD_CODES
21
23
 
22
24
  class << self
23
25
  attr_accessor :api_base
24
26
  end
25
27
 
28
+ # AlphaCard.request(params, account) -> AlphaCardResponse
29
+ #
30
+ # Do the POST request to the AlphaCard Gateway with <i>params</i>
31
+ # from specified AlphaCard <i>account</i>.
32
+ #
33
+ # account = AlphaCard::Account.new('user', 'pass')
34
+ # params = {amount: '10.00'}
35
+ # r = AlphaCard.request(params, account) #=> AlphaCardResponse
26
36
  def self.request(params = {}, account)
27
37
  unless account.filled?
28
38
  raise AlphaCardError.new('You must set credentials to create the sale!')
@@ -38,6 +48,14 @@ module AlphaCard
38
48
 
39
49
  private
40
50
 
51
+ # AlphaCard.handle_errors(response) -> Exception
52
+ # AlphaCard.handle_errors(response) -> nil
53
+ #
54
+ # Raise an exception if AlphaCard Gateway return an error or decline
55
+ # the request.
56
+ #
57
+ # response = AlphaCard.request(params, account)
58
+ # handle_errors(response) #=> nil or Exception
41
59
  def self.handle_errors(response)
42
60
  code = response.text
43
61
  raise AlphaCardError.new(CREDIT_CARD_CODES[code] || code) unless response.success?
@@ -2,10 +2,15 @@ module AlphaCard
2
2
  class AlphaCardObject
3
3
  include Virtus.model
4
4
 
5
- def to_query
6
- Rack::Utils.build_query(self.filled_attributes)
7
- end
5
+ # filled_attributes -> Hash
6
+ #
7
+ # Returns only filled attributes, not nil ones.
8
+ #
9
+ # order = AlphaCard::Order.new({})
10
+ # order.filled_attributes #=> {}
8
11
 
12
+ # order = AlphaCard::Order.new({orderid: '1'})
13
+ # order.filled_attributes #=> {orderid: '1'}
9
14
  def filled_attributes
10
15
  self.attributes.select { |key, value| value.present? }
11
16
  end
@@ -1,3 +1,8 @@
1
+ # Object class needed to implement some nice
2
+ # active_support features for projects, that
3
+ # doesn't need active_support.
4
+ #
5
+ # Use-case: standalone Ruby scripts
1
6
  class Object
2
7
  def blank?
3
8
  respond_to?(:empty?) ? !!empty? : !self
@@ -5,8 +5,20 @@ module AlphaCard
5
5
  attribute :amount, String
6
6
  attribute :cvv, String
7
7
 
8
+ # Not writable attribute, define the type of transaction (default is 'sale')
8
9
  attribute :type, String, default: 'sale', writer: :private
9
10
 
11
+ # create(order, account) -> true
12
+ # create(order, account) -> false
13
+ # create(order, account) -> Exception
14
+ #
15
+ # Creates the sale for the <i>order</i> with specified
16
+ # attributes, such as <i>ccexp</i>, <i>ccnumber</i>, <i>amount</i>
17
+ # and <i>cvv</i>.
18
+ #
19
+ # attrs = {ccexp: '0117', ccnumber: '123', amount: '10.00'}
20
+ # sale = AlphaCard::Sale.new(attrs)
21
+ # sale.create(order, account) #=> true or false
10
22
  def create(order, account)
11
23
  [:ccexp, :ccnumber, :amount].each do |attr|
12
24
  raise Exception.new("No #{attr.to_s} information provided") if self.send(attr.to_s).blank?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alpha_card
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Bulaj