alpha_card 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/alpha_card.rb +55 -0
- data/lib/alpha_card/account.rb +15 -0
- data/lib/alpha_card/alpha_card_error.rb +4 -0
- data/lib/alpha_card/alpha_card_object.rb +13 -0
- data/lib/alpha_card/alpha_card_response.rb +37 -0
- data/lib/alpha_card/billing.rb +6 -0
- data/lib/alpha_card/data/codes.yml +62 -0
- data/lib/alpha_card/object.rb +17 -0
- data/lib/alpha_card/order.rb +8 -0
- data/lib/alpha_card/sale.rb +25 -0
- data/lib/alpha_card/shipping.rb +10 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd70168d46aad0fa4d47e2b3f4ddc456bfe2a3d9
|
4
|
+
data.tar.gz: e6823a997b69246add52d448ab5069b7334d7136
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d517bc9ab7e41c42eb45df3e430c27b2b235e0f5d388d720229b44e2488ec7d92e795c464321dd9b65cbb5f607d57f02ef00ab2af65669d0ad2c6c9dbf05ef88
|
7
|
+
data.tar.gz: c9038bd884701f52dc6d438217326af53a9a2350c8b5d1f6385d01f62f6d56040cd23da17991e10cfd6d6aba9caf66f501ee4ea6cd5baf973eb2bf06ba9d2f63
|
data/lib/alpha_card.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'curb'
|
2
|
+
require 'yaml'
|
3
|
+
require 'virtus'
|
4
|
+
require 'rack'
|
5
|
+
|
6
|
+
require 'alpha_card/object'
|
7
|
+
|
8
|
+
require 'alpha_card/alpha_card_response'
|
9
|
+
require 'alpha_card/alpha_card_error'
|
10
|
+
require 'alpha_card/alpha_card_object'
|
11
|
+
|
12
|
+
require 'alpha_card/account'
|
13
|
+
require 'alpha_card/billing'
|
14
|
+
require 'alpha_card/order'
|
15
|
+
require 'alpha_card/sale'
|
16
|
+
require 'alpha_card/shipping'
|
17
|
+
|
18
|
+
module AlphaCard
|
19
|
+
@api_base = 'https://secure.alphacardgateway.com/api/transact.php'
|
20
|
+
|
21
|
+
CREDIT_CARD_CODES = YAML.load_file(File.expand_path('../alpha_card/data/codes.yml', __FILE__)) unless defined? CREDIT_CARD_CODES
|
22
|
+
|
23
|
+
class << self
|
24
|
+
attr_accessor :api_base
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.request(params, account)
|
28
|
+
unless account.filled?
|
29
|
+
raise AlphaCardError.new('You must set credentials to create the sale!')
|
30
|
+
end
|
31
|
+
|
32
|
+
auth_params = account.to_query
|
33
|
+
|
34
|
+
curl = Curl::Easy.new(@api_base)
|
35
|
+
curl.connect_timeout = 15
|
36
|
+
curl.timeout = 15
|
37
|
+
curl.header_in_body = false
|
38
|
+
curl.ssl_verify_peer = false
|
39
|
+
curl.post_body = [auth_params, params].join('&')
|
40
|
+
curl.perform
|
41
|
+
|
42
|
+
response = AlphaCardResponse.new(curl.body_str)
|
43
|
+
handle_errors(response)
|
44
|
+
|
45
|
+
response
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def self.handle_errors(response)
|
51
|
+
code = response.text
|
52
|
+
raise AlphaCardError.new(CREDIT_CARD_CODES[code] || code) unless response.success?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module AlphaCard
|
2
|
+
class Account < AlphaCardObject
|
3
|
+
attribute :username, String
|
4
|
+
attribute :password, String
|
5
|
+
|
6
|
+
def initialize(username, password)
|
7
|
+
self.username = username
|
8
|
+
self.password = password
|
9
|
+
end
|
10
|
+
|
11
|
+
def filled?
|
12
|
+
[self.username, self.password].all?(&:present?)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module AlphaCard
|
2
|
+
class AlphaCardResponse
|
3
|
+
attr_reader :data
|
4
|
+
|
5
|
+
APPROVED = '1'
|
6
|
+
DECLINED = '2'
|
7
|
+
ERROR = '3'
|
8
|
+
|
9
|
+
def initialize(request_body)
|
10
|
+
@data = Rack::Utils.parse_nested_query(request_body)
|
11
|
+
end
|
12
|
+
|
13
|
+
def text
|
14
|
+
@data['responsetext']
|
15
|
+
end
|
16
|
+
|
17
|
+
def transaction_id
|
18
|
+
@data['transactionid']
|
19
|
+
end
|
20
|
+
|
21
|
+
def code
|
22
|
+
@data['response_code']
|
23
|
+
end
|
24
|
+
|
25
|
+
def success?
|
26
|
+
@data['response'] == APPROVED
|
27
|
+
end
|
28
|
+
|
29
|
+
def declined?
|
30
|
+
@data['response'] == DECLINED
|
31
|
+
end
|
32
|
+
|
33
|
+
def error?
|
34
|
+
@data['response'] == ERROR
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
"AP": 'Approved or completed successfully'
|
2
|
+
"CALL AE": 'Refer to American Express.'
|
3
|
+
"CALL CB": 'Refer to Carte Blanche.'
|
4
|
+
"CALL DC": 'Refer to Diners Club.'
|
5
|
+
"CALL DISCOVER": 'Refer to Discover.'
|
6
|
+
"CALL JB": 'Refer to JBS.'
|
7
|
+
"CALL ND": 'Call your Visa/MasterCard Voice Authorization Center.'
|
8
|
+
"CALL TC": 'Refer to TeleCredit.'
|
9
|
+
"CALL TK": 'Refer to TeleCheck.'
|
10
|
+
"CALL WC": 'Refer to Worldcheck.'
|
11
|
+
"CALL XXXXXXXXXX": 'Call indicated number.'
|
12
|
+
"ISSUER UNAVAIL NDC": 'cannot contact issuing bank for authorization.'
|
13
|
+
"INVLD MERCH ID": 'Invalid Merchant ID.'
|
14
|
+
"PIC UP": 'Authorization declined.'
|
15
|
+
"DECLINE": 'Authorization declined.'
|
16
|
+
"REVERSED": 'Requested transaction reversal was successful.'
|
17
|
+
"AP WITH ID": 'Approved with positive ID. NDC Host does not capture this transaction.'
|
18
|
+
"INVLD SERV ID": 'Service ID number is incorrect'
|
19
|
+
"INVALID REQUEST": 'Administrative message contains a syntax error.'
|
20
|
+
"INVLD TRAN CODE": 'Processing code entered is incorrect. Please refer to valid processing code.'
|
21
|
+
"INVLD AMOUNT": 'Amount entered is not valid.'
|
22
|
+
"INVLD ACCT": 'Account number does not pass issuer’s edit checks'
|
23
|
+
"INVLD CODE ACCT": 'Valid account number matched with a transaction code for a different card type.'
|
24
|
+
"PLEASE RETRY": 'NDC’s user tables are set up incorrectly for this account.'
|
25
|
+
"INVLD EMP DATE": 'NDC GATEWAY requests a retry.'
|
26
|
+
"PIN INVALID": 'Expired date entered is incorrect.'
|
27
|
+
"UNAUTH TRANS": 'Incorrect PIN entered.'
|
28
|
+
"MAX PIN RETRIES": 'A transaction code was used for which you are not setup on the Merchant Master File.'
|
29
|
+
"AP DUPE": 'Maximum PIN number entry attempts exceeded.'
|
30
|
+
"IN ACCT MATCH": 'Transaction entered is a duplicate.'
|
31
|
+
"INV AMT MATCH": 'The account number entered during a void or adjustment transaction does not match the account number stored in the NDC Host for that item.'
|
32
|
+
"INV ITEM NUM": 'The item number entered for a void or adjustment transaction is incorrect.'
|
33
|
+
"ITEM VOIDED": 'An adjustment or item review was attempted on a transaction previously voided or reversed.'
|
34
|
+
"ITEM REVERSED": 'An adjustment or item review was attempted on a transaction previously voided or reversed.'
|
35
|
+
"MUST BALANCE NOW": 'Terminal has not been balanced within time specified in the NDC Merchant Master File for this merchant.'
|
36
|
+
"USE DUP THEN BAL": 'Terminal has not been balanced within time specified in the NDC Merchant Master File for this merchant, but merchant is set up to perform extra transactions before balancing.'
|
37
|
+
"NO DUP FOUND": 'Override transaction is at tempted on a non-duplicated transaction.'
|
38
|
+
"INVALID DATA": 'Format of the transaction is incorrect.'
|
39
|
+
"NO TRANS FOUND": 'Reversal transaction is attempted on a transaction that is not in the open batch on the host.'
|
40
|
+
"AP NOT CAPTURED": 'Approved but not captured (applied to only credit card transactions).'
|
41
|
+
"AP AUTH-ONLY": 'Approved but this EDC merchant is not set up to capture this card type (applies only to credit card transactions).'
|
42
|
+
"INV BANK": 'Acquiring Bank ID entered is incorrect.'
|
43
|
+
"TRAN TYPE INVLD": 'Transaction not supported by EFT network or EFT Group ID is incorrect.'
|
44
|
+
"APPROVED": 'Merchant is not set up for debit on NDC Merchant Master File.'
|
45
|
+
"DB UNAVAIL 02": 'NDC GATEWAY is down'
|
46
|
+
"DB UNAVAIL 03": 'NDC GATEWAY Link ID timed out.'
|
47
|
+
"DB UNAVAIL 04": 'NDC GATEWAY cannot contact EFT network or EFT Group ID is incorrect.'
|
48
|
+
"UNAUTH USER": 'Merchant is not set up for debit on NDC Merchant Master File.'
|
49
|
+
"INVALID CARD": 'Debit card not on issuer file.'
|
50
|
+
"DB ISSUER UNAVAIL EFT": 'network cannot contact issuer'
|
51
|
+
"INVALID POS CARD": 'Card is not eligible for POS.'
|
52
|
+
"ACCT TYPE INVLD": 'Type of account entered cannot be accessed (checking, savings, etc.)'
|
53
|
+
"INVALID PREFIX": 'No sharing arrangement for this card.'
|
54
|
+
"INVALID FIID NDC GATEWAY": 'Financial Institution ID not set up.'
|
55
|
+
"VERIFY XXXXXXXXXX": 'Match on SCAN file. XXXXXXXXXX is routing/transit number on the negative file.'
|
56
|
+
"INVALID LIC": 'The license or ID number entered during a check authorization transaction is incorrect.'
|
57
|
+
"INVALID STATE CD": 'State code entered is incorrect.'
|
58
|
+
"EDC UNAVAILABLE EDC": 'application down, try later.'
|
59
|
+
"DB UNAVAIL 01": 'Problem at NDC routing transaction.'
|
60
|
+
"SCAN UNAVAILABLE SCAN": 'application is down, try later.'
|
61
|
+
"EXCEEDS MAX AMT": 'Exceeds withdrawal amount limit.'
|
62
|
+
"EXCEEDS MAX USES": 'Exceeds withdrawal frequency limit'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Object
|
2
|
+
def blank?
|
3
|
+
respond_to?(:empty?) ? !!empty? : !self
|
4
|
+
end
|
5
|
+
|
6
|
+
def present?
|
7
|
+
!blank?
|
8
|
+
end
|
9
|
+
|
10
|
+
def try(*a, &b)
|
11
|
+
if a.empty? && block_given?
|
12
|
+
yield self
|
13
|
+
else
|
14
|
+
public_send(*a, &b) if respond_to?(a.first)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module AlphaCard
|
2
|
+
class Sale < AlphaCardObject
|
3
|
+
attribute :ccexp, String
|
4
|
+
attribute :ccnumber, String
|
5
|
+
attribute :amount, String
|
6
|
+
attribute :cvv, String
|
7
|
+
|
8
|
+
attribute :type, String, default: 'sale', writer: :private
|
9
|
+
|
10
|
+
def create(order, account)
|
11
|
+
[:ccexp, :ccnumber, :amount].each do |attr|
|
12
|
+
raise Exception.new("No #{attr.to_s} information provided") if self.send(attr.to_s).blank?
|
13
|
+
end
|
14
|
+
|
15
|
+
sale_query = self.to_query
|
16
|
+
order_query = order.to_query
|
17
|
+
billing_query = order.billing.try(:to_query)
|
18
|
+
shipping_query = order.shipping.try(:to_query)
|
19
|
+
|
20
|
+
params = [order_query, billing_query, sale_query, shipping_query].reject(&:blank?).join('&')
|
21
|
+
|
22
|
+
AlphaCard.request(params, account).success?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alpha_card
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nikita Bulaj
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Gem for creates sales with Alpha Card DirectPost API
|
14
|
+
email: bulajnikita@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/alpha_card.rb
|
20
|
+
- lib/alpha_card/account.rb
|
21
|
+
- lib/alpha_card/alpha_card_error.rb
|
22
|
+
- lib/alpha_card/alpha_card_object.rb
|
23
|
+
- lib/alpha_card/alpha_card_response.rb
|
24
|
+
- lib/alpha_card/billing.rb
|
25
|
+
- lib/alpha_card/data/codes.yml
|
26
|
+
- lib/alpha_card/object.rb
|
27
|
+
- lib/alpha_card/order.rb
|
28
|
+
- lib/alpha_card/sale.rb
|
29
|
+
- lib/alpha_card/shipping.rb
|
30
|
+
homepage: http://github.com/budev/alpha_card
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.2.2
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Alpha Card DirectPost API
|
54
|
+
test_files: []
|