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 +4 -4
- data/alpha_card.gemspec +1 -1
- data/lib/alpha_card.rb +18 -0
- data/lib/alpha_card/alpha_card_object.rb +8 -3
- data/lib/alpha_card/object.rb +5 -0
- data/lib/alpha_card/sale.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d1b3608b60661b5688717b2f96768ac0e36a83c
|
4
|
+
data.tar.gz: 8d0a9f755a5faa7802d36feac0828bd1d3877cc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c752b3a03ce5299126ae280a3456d7d7507803e63a8c0bd0cca7dd3cffaa2ec34764694da072d962658666d7b876231ba3b026a27d99554edbfb87d075729d9b
|
7
|
+
data.tar.gz: 531987ff7b2dcf6555e29816eccd92394bbf6d1577219064e321020a6a75713d8c37c7037e1a117a8d77ef5c7f184f6ab6a7834108676467419bf1970cdb92b0
|
data/alpha_card.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'alpha_card'
|
3
|
-
gem.version = '0.1.
|
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'
|
data/lib/alpha_card.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
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
|
data/lib/alpha_card/object.rb
CHANGED
data/lib/alpha_card/sale.rb
CHANGED
@@ -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?
|