alpha_card 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.travis.yml +1 -5
  4. data/CHANGELOG.md +54 -0
  5. data/Gemfile.lock +25 -37
  6. data/LICENSE +1 -1
  7. data/README.md +207 -67
  8. data/ROADMAP.md +12 -0
  9. data/alpha_card.gemspec +5 -4
  10. data/lib/alpha_card.rb +11 -6
  11. data/lib/alpha_card/alpha_card_object.rb +59 -3
  12. data/lib/alpha_card/alpha_card_response.rb +99 -16
  13. data/lib/alpha_card/data/avs_responses.yml +20 -0
  14. data/lib/alpha_card/data/credit_card_codes.yml +1 -1
  15. data/lib/alpha_card/data/cvv_responses.yml +5 -0
  16. data/lib/alpha_card/data/response_messages.yml +33 -0
  17. data/lib/alpha_card/errors/alpha_card_error.rb +1 -1
  18. data/lib/alpha_card/errors/invalid_object_error.rb +8 -0
  19. data/lib/alpha_card/objects/account.rb +1 -1
  20. data/lib/alpha_card/objects/billing.rb +15 -4
  21. data/lib/alpha_card/objects/capture.rb +51 -0
  22. data/lib/alpha_card/objects/order.rb +41 -4
  23. data/lib/alpha_card/objects/refund.rb +20 -0
  24. data/lib/alpha_card/objects/sale.rb +32 -22
  25. data/lib/alpha_card/objects/shipping.rb +15 -4
  26. data/lib/alpha_card/objects/update.rb +54 -0
  27. data/lib/alpha_card/objects/void.rb +45 -0
  28. data/lib/alpha_card/version.rb +18 -2
  29. data/spec/alpha_card/objects/account_spec.rb +20 -0
  30. data/spec/alpha_card/objects/capture_spec.rb +51 -0
  31. data/spec/alpha_card/objects/deprecated_methods_spec.rb +32 -0
  32. data/spec/alpha_card/objects/refund_spec.rb +35 -0
  33. data/spec/alpha_card/objects/sale_spec.rb +143 -0
  34. data/spec/alpha_card/objects/update_spec.rb +36 -0
  35. data/spec/alpha_card/objects/void_spec.rb +48 -0
  36. data/spec/alpha_card/response_spec.rb +111 -0
  37. data/spec/spec_helper.rb +7 -2
  38. metadata +44 -9
  39. data/spec/alpha_card/alpha_card_account_spec.rb +0 -18
  40. data/spec/alpha_card/alpha_card_response_spec.rb +0 -63
  41. data/spec/alpha_card/alpha_card_spec.rb +0 -123
@@ -42,7 +42,7 @@ module AlphaCard
42
42
  # #=> false
43
43
  def filled?
44
44
  attrs = [username, password]
45
- !attrs.empty? && attrs.all? { |attr| attr && !attr.strip.empty? }
45
+ attrs.all? { |attr| attr && !attr.strip.empty? }
46
46
  end
47
47
  end
48
48
  end
@@ -3,18 +3,29 @@ module AlphaCard
3
3
  # Implementation of Alpha Card Services order billing information.
4
4
  # Contains all the billing information (customer name, email, email, etc).
5
5
  class Billing < AlphaCardObject
6
- attribute :firstname, String
7
- attribute :lastname, String
6
+ attribute :first_name, String
7
+ attribute :last_name, String
8
8
  attribute :email, String
9
9
  attribute :phone, String
10
10
  attribute :company, String
11
- attribute :address1, String
12
- attribute :address2, String
11
+ attribute :address_1, String
12
+ attribute :address_2, String
13
13
  attribute :city, String
14
14
  attribute :state, String
15
15
  attribute :zip, String
16
16
  attribute :country, String
17
17
  attribute :fax, String
18
18
  attribute :website, String
19
+
20
+ ##
21
+ # Original AlphaCard transaction variables names
22
+ ORIGIN_TRANSACTION_VARIABLES = {
23
+ first_name: :firstname,
24
+ last_name: :lastname,
25
+ address_1: :address1,
26
+ address_2: :address2
27
+ }.freeze
28
+
29
+ deprecate_old_variables!
19
30
  end
20
31
  end
@@ -0,0 +1,51 @@
1
+ module AlphaCard
2
+ ##
3
+ # Implementation of Alpha Card Services Capture transaction.
4
+ class Capture < AlphaCardObject
5
+ attribute :transaction_id, String
6
+ # Format: xx.xx
7
+ attribute :amount, String
8
+ attribute :tracking_number, String
9
+ attribute :shipping_carrier, String
10
+ attribute :order_id, String
11
+
12
+ ##
13
+ # Transaction type (default is 'capture')
14
+ #
15
+ # @attribute [r] type
16
+ attribute :type, String, default: 'capture', writer: :private
17
+
18
+ ##
19
+ # Original AlphaCard transaction variables names
20
+ ORIGIN_TRANSACTION_VARIABLES = {
21
+ transaction_id: :transactionid,
22
+ order_id: :orderid
23
+ }.freeze
24
+
25
+ ##
26
+ # Creates a Capture with the <code>AlphaCard::Account</code> credentials.
27
+ #
28
+ # @param [AlphaCard::Account] account
29
+ # An <code>AlphaCard::Account</code> object.
30
+ #
31
+ # @return [Boolean]
32
+ # True if capture was created successfully.
33
+ # Raise an AlphaCardError exception if some error occurred.
34
+ #
35
+ # @raise [Exception]
36
+ # Exception if one of required attributes doesn't specified.
37
+ #
38
+ # @example
39
+ # account = AlphaCard::Account.new('demo', 'password')
40
+ # capture = AlphaCard::Capture.new(transaction_id: '981562', amount: '10.05')
41
+ # capture.create(account)
42
+ #
43
+ # #=> [true, #<AlphaCard::AlphaCardResponse:0x1a0fda ...>]
44
+ def create(account)
45
+ abort_if_attributes_blank!(:amount, :transaction_id)
46
+
47
+ response = AlphaCard.request(account, attributes_for_request)
48
+ [response.success?, response]
49
+ end
50
+ end
51
+ end
@@ -3,13 +3,50 @@ module AlphaCard
3
3
  # Implementation of Alpha Card Services Order object.
4
4
  # Contains all the information about order (id, description, etc).
5
5
  class Order < AlphaCardObject
6
- attribute :orderid, String
7
- attribute :orderdescription, String
8
- attribute :ponumber, String
6
+ attribute :id, String
7
+ attribute :description, String
8
+ attribute :po_number, String
9
9
  attribute :tax, String
10
- attribute :ipaddress, String
10
+ # Format: xxx.xxx.xxx.xxx
11
+ attribute :ip_address, String
11
12
 
12
13
  attribute :billing, AlphaCard::Billing
13
14
  attribute :shipping, AlphaCard::Shipping
15
+
16
+ ##
17
+ # Original AlphaCard transaction variables names
18
+ ORIGIN_TRANSACTION_VARIABLES = {
19
+ id: :orderid,
20
+ description: :orderdescription,
21
+ po_number: :ponumber,
22
+ ip_address: :ipaddress
23
+ }.freeze
24
+
25
+ ##
26
+ # Overloaded method to return all the attributes from the
27
+ # sale + billing + shipping objects.
28
+ #
29
+ # @return [Hash]
30
+ # Filled attributes with the original Alpha Card Services
31
+ # transaction variables names.
32
+ #
33
+ # @example
34
+ # billing = AlphaCard::Billing.new(email: 'test@example.com')
35
+ # shipping = AlphaCard::Shipping.new(first_name: 'John', last_name: 'Doe')
36
+ # order = AlphaCard::Order.new(id: '1', billing: billing, shipping: shipping)
37
+ # order.attributes_for_request
38
+ #
39
+ # #=> { orderid: '1', email: 'test@example.com', shipping_first_name: 'John', shipping_last_name: 'Doe' }
40
+ def attributes_for_request(*)
41
+ attributes = filled_attributes.dup
42
+
43
+ billing = attributes.delete(:billing)
44
+ attributes.merge!(billing.attributes_for_request) if billing
45
+
46
+ shipping = attributes.delete(:shipping)
47
+ attributes.merge!(shipping.attributes_for_request) if shipping
48
+
49
+ super(attributes)
50
+ end
14
51
  end
15
52
  end
@@ -0,0 +1,20 @@
1
+ module AlphaCard
2
+ ##
3
+ # Implementation of Alpha Card Services Refund transaction.
4
+ class Refund < Void
5
+ # Format: xx.xx
6
+ attribute :amount, String
7
+
8
+ ##
9
+ # Transaction type (default is 'refund')
10
+ #
11
+ # @attribute [r] type
12
+ attribute :type, String, default: 'refund', writer: :private
13
+
14
+ ##
15
+ # Original AlphaCard transaction variables names
16
+ ORIGIN_TRANSACTION_VARIABLES = {
17
+ transaction_id: :transactionid
18
+ }.freeze
19
+ end
20
+ end
@@ -1,21 +1,38 @@
1
1
  module AlphaCard
2
2
  ##
3
- # Implementation of Alpha Card Services Sale object.
3
+ # Implementation of Alpha Card Services Sale transaction.
4
4
  # Contains all the information about Customer Credit Card,
5
5
  # such as CVV, number, expiration date, etc.
6
6
  # Process the Alpha Card Services payment.
7
7
  class Sale < AlphaCardObject
8
- attribute :ccexp, String
9
- attribute :ccnumber, String
8
+ # Format: MMYY
9
+ attribute :card_expiration_date, String
10
+ attribute :card_number, String
10
11
  attribute :amount, String
11
12
  attribute :cvv, String
13
+ # Values: 'true' or 'false'
14
+ attribute :customer_receipt, String
12
15
 
13
16
  ##
14
- # Not writable attribute, defines the type of transaction (default is 'sale')
17
+ # Payment type.
18
+ # Values: 'creditcard' or 'check'
19
+ attribute :payment, String, default: 'creditcard'
20
+
21
+ ##
22
+ # Transaction type (default is 'sale')
15
23
  #
16
24
  # @attribute [r] type
17
25
  attribute :type, String, default: 'sale', writer: :private
18
26
 
27
+ ##
28
+ # Original AlphaCard transaction variables names
29
+ ORIGIN_TRANSACTION_VARIABLES = {
30
+ card_expiration_date: :ccexp,
31
+ card_number: :ccnumber
32
+ }.freeze
33
+
34
+ deprecate_old_variables!
35
+
19
36
  ##
20
37
  # Creates the sale for the specified <code>AlphaCard::Order</code>
21
38
  # with the <code>AlphaCard::Account</code> credentials.
@@ -29,29 +46,28 @@ module AlphaCard
29
46
  # True if sale was created successfully.
30
47
  # Raise an AlphaCardError exception if some error occurred.
31
48
  #
32
- # @raise [Exception]
49
+ # @raise [AlphaCard::InvalidObjectError]
33
50
  # Exception if one of required attributes doesn't specified.
34
51
  #
35
52
  # @example
36
53
  # account = AlphaCard::Account.new('demo', 'password')
37
- # order = AlphaCard::Order.new({orderid: 1, orderdescription: 'Test order'})
38
- # sale = AlphaCard::Sale.new({ccexp: '0117', ccnumber: '4111111111111111', amount: "5.00" })
54
+ # order = AlphaCard::Order.new(id: 1, description: 'Test order')
55
+ # sale = AlphaCard::Sale.new(card_expiration_date: '0117', card_number: '4111111111111111', amount: '5.00' )
39
56
  # sale.create(order, account)
40
57
  #
41
- # #=> true
58
+ # #=> [true, #<AlphaCard::AlphaCardResponse:0x1a0fda ...>]
42
59
  def create(order, account)
43
- [:ccexp, :ccnumber, :amount].each do |attr|
44
- fail ArgumentError, "No #{attr} information provided!" if self[attr].nil? || self[attr].empty?
45
- end
60
+ abort_if_attributes_blank!(:card_expiration_date, :card_number, :amount)
46
61
 
47
- AlphaCard.request(account, params_with(order)).success?
62
+ response = AlphaCard.request(account, params_for_sale(order))
63
+ [response.success?, response]
48
64
  end
49
65
 
50
66
  private
51
67
 
52
68
  ##
53
- # Return params for Alpha Card merged with
54
- # params of another object passed through arguments
69
+ # Returns all the necessary attributes with it's original
70
+ # names that must be passed with Sale transaction.
55
71
  #
56
72
  # @param [AlphaCard::Order] order
57
73
  # An <code>AlphaCard::Order</code> object.
@@ -59,14 +75,8 @@ module AlphaCard
59
75
  # @return [Hash]
60
76
  # Params of *self* object merged with params
61
77
  # of another object (<code>AlphaCard::Order</code>)
62
- def params_with(order)
63
- params = filled_attributes || {}
64
-
65
- [order, order.billing, order.shipping].compact.each do |obj|
66
- params.merge!(obj ? obj.filled_attributes : {})
67
- end
68
-
69
- params
78
+ def params_for_sale(order)
79
+ attributes_for_request.merge(order.attributes_for_request)
70
80
  end
71
81
  end
72
82
  end
@@ -3,8 +3,8 @@ module AlphaCard
3
3
  # Implementation of Alpha Card Services order shipping information.
4
4
  # Contains all the shipping information (address, city, zip, etc).
5
5
  class Shipping < AlphaCardObject
6
- attribute :firstname, String
7
- attribute :lastname, String
6
+ attribute :first_name, String
7
+ attribute :last_name, String
8
8
  attribute :company, String
9
9
  attribute :address_1, String
10
10
  attribute :address_2, String
@@ -14,6 +14,17 @@ module AlphaCard
14
14
  attribute :country, String
15
15
  attribute :email, String
16
16
 
17
+ ##
18
+ # Original AlphaCard transaction variables names
19
+ ORIGIN_TRANSACTION_VARIABLES = {
20
+ first_name: :firstname,
21
+ last_name: :lastname,
22
+ address_1: :address1,
23
+ address_2: :address2
24
+ }.freeze
25
+
26
+ deprecate_old_variables!
27
+
17
28
  ##
18
29
  # Overloaded <code>filled_attributes</code> method from
19
30
  # <code>AlphaCard::AlphaCardObject</code>. All attribute names of
@@ -24,10 +35,10 @@ module AlphaCard
24
35
  # Only filled attributes of Shipping resource with "shipping_" prefix.
25
36
  #
26
37
  # @example
27
- # shipping = AlphaCard::Shipping.new({firstname: 'John', state: 'NY'})
38
+ # shipping = AlphaCard::Shipping.new(firstname: 'John', state: 'NY')
28
39
  # shipping.filled_attributes
29
40
  #
30
- # #=> {shipping_firstname: 'John', shipping_state: 'NY'}
41
+ # #=> { shipping_firstname: 'John', shipping_state: 'NY' }
31
42
  def filled_attributes
32
43
  Hash[super.map { |k, v| ["shipping_#{k}".to_sym, v] }]
33
44
  end
@@ -0,0 +1,54 @@
1
+ module AlphaCard
2
+ ##
3
+ # Implementation of Alpha Card Services Update transaction.
4
+ # Transaction updates can be used to update previous transactions
5
+ # with specific order information, such as a tracking number
6
+ # and shipping carrier.
7
+ class Update < Void
8
+ # Total shipping amount.
9
+ # Format: x.xx
10
+ attribute :shipping, String
11
+ attribute :shipping_postal, String
12
+ attribute :ship_from_postal, String
13
+ attribute :shipping_country, String
14
+ # Values: 'ups', 'fedex', 'dhl', or 'usps'
15
+ attribute :shipping_carrier, String
16
+ # Format: YYYYMMDD
17
+ attribute :shipping_date, String
18
+ attribute :order_description, String
19
+ attribute :order_date, String
20
+ # Values: 'true' or 'false'
21
+ attribute :customer_receipt, String
22
+ attribute :po_number, String
23
+ attribute :summary_commodity_code, String
24
+ # Format: x.xx
25
+ attribute :duty_amount, String
26
+ # Format: x.xx
27
+ attribute :discount_amount, String
28
+ # Format: x.xx
29
+ attribute :tax, String
30
+ # Format: x.xx
31
+ attribute :national_tax_amount, String
32
+ # Format: x.xx
33
+ attribute :alternate_tax_amount, String
34
+ attribute :alternate_tax_id, String
35
+ attribute :vat_tax_amount, String
36
+ attribute :vat_tax_rate, String
37
+ attribute :vat_invoice_reference_number, String
38
+ attribute :customer_vat_registration, String
39
+ attribute :merchant_vat_registration, String
40
+
41
+ ##
42
+ # Transaction type (default is 'update')
43
+ #
44
+ # @attribute [r] type
45
+ attribute :type, String, default: 'update', writer: :private
46
+
47
+ ##
48
+ # Original AlphaCard transaction variables names
49
+ ORIGIN_TRANSACTION_VARIABLES = {
50
+ transaction_id: :transactionid,
51
+ po_number: :ponumber
52
+ }.freeze
53
+ end
54
+ end
@@ -0,0 +1,45 @@
1
+ module AlphaCard
2
+ ##
3
+ # Implementation of Alpha Card Services Void transaction.
4
+ class Void < AlphaCardObject
5
+ attribute :transaction_id, String
6
+
7
+ ##
8
+ # Transaction type (default is 'void')
9
+ #
10
+ # @attribute [r] type
11
+ attribute :type, String, default: 'void', writer: :private
12
+
13
+ ##
14
+ # Original AlphaCard transaction variables names
15
+ ORIGIN_TRANSACTION_VARIABLES = {
16
+ transaction_id: :transactionid
17
+ }.freeze
18
+
19
+ ##
20
+ # Creates void transaction with the <code>AlphaCard::Account</code> credentials.
21
+ #
22
+ # @param [AlphaCard::Account] account
23
+ # An <code>AlphaCard::Account</code> object.
24
+ #
25
+ # @return [Boolean]
26
+ # True if transaction was created successfully.
27
+ # Raise an AlphaCardError exception if some error occurred.
28
+ #
29
+ # @raise [AlphaCard::InvalidObjectError]
30
+ # Exception if one of required attributes doesn't specified.
31
+ #
32
+ # @example
33
+ # account = AlphaCard::Account.new('demo', 'password')
34
+ # void = AlphaCard::Void.new(transaction_id: '981562')
35
+ # void.create(account)
36
+ #
37
+ # #=> [true, #<AlphaCard::AlphaCardResponse:0x1a0fda ...>]
38
+ def create(account)
39
+ abort_if_attributes_blank!(:transaction_id)
40
+
41
+ response = AlphaCard.request(account, attributes_for_request)
42
+ [response.success?, response]
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,21 @@
1
1
  module AlphaCard
2
2
  ##
3
- # Version information for AlphaCard gem.
4
- VERSION = '0.2.6'.freeze
3
+ # AlphaCard gem version.
4
+ def self.gem_version
5
+ Gem::Version.new VERSION::STRING
6
+ end
7
+
8
+ ##
9
+ # AlphaCard semantic versioning
10
+ module VERSION
11
+ # Major version number
12
+ MAJOR = 0
13
+ # Minor version number
14
+ MINOR = 3
15
+ # Smallest version number
16
+ TINY = 0
17
+
18
+ # Full version number
19
+ STRING = [MAJOR, MINOR, TINY].compact.join('.')
20
+ end
5
21
  end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe AlphaCard::Account do
4
+ let(:valid_account) { AlphaCard::Account.new('demo', 'password') }
5
+ let(:invalid_account) { AlphaCard::Account.new('', '') }
6
+
7
+ describe '#filled?' do
8
+ context 'with filled credentials' do
9
+ it 'returns true' do
10
+ expect(valid_account.filled?).to be_truthy
11
+ end
12
+ end
13
+
14
+ context 'with blank credentials' do
15
+ it 'returns false' do
16
+ expect(invalid_account.filled?).to be_falsey
17
+ end
18
+ end
19
+ end
20
+ end