alpha_card 0.3.0 → 0.4.0

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -4
  3. data/CHANGELOG.md +21 -3
  4. data/Gemfile +0 -2
  5. data/Gemfile.lock +6 -24
  6. data/README.md +115 -85
  7. data/ROADMAP.md +13 -9
  8. data/alpha_card.gemspec +3 -4
  9. data/lib/alpha_card.rb +44 -72
  10. data/lib/alpha_card/account.rb +51 -0
  11. data/lib/alpha_card/attribute.rb +337 -0
  12. data/lib/alpha_card/data/credit_card_codes.yml +54 -54
  13. data/lib/alpha_card/errors/invalid_attribute_format.rb +14 -0
  14. data/lib/alpha_card/errors/invalid_attribute_type.rb +14 -0
  15. data/lib/alpha_card/errors/invalid_attribute_value.rb +14 -0
  16. data/lib/alpha_card/errors/{invalid_object_error.rb → validation_error.rb} +1 -1
  17. data/lib/alpha_card/{alpha_card_object.rb → resource.rb} +14 -28
  18. data/lib/alpha_card/resources/billing.rb +29 -0
  19. data/lib/alpha_card/{objects → resources}/order.rb +8 -8
  20. data/lib/alpha_card/{objects → resources}/shipping.rb +15 -13
  21. data/lib/alpha_card/{alpha_card_response.rb → response.rb} +21 -6
  22. data/lib/alpha_card/transaction.rb +30 -0
  23. data/lib/alpha_card/transactions/auth.rb +18 -0
  24. data/lib/alpha_card/transactions/capture.rb +32 -0
  25. data/lib/alpha_card/transactions/credit.rb +18 -0
  26. data/lib/alpha_card/{objects → transactions}/refund.rb +9 -2
  27. data/lib/alpha_card/transactions/sale.rb +91 -0
  28. data/lib/alpha_card/transactions/update.rb +61 -0
  29. data/lib/alpha_card/transactions/validate.rb +21 -0
  30. data/lib/alpha_card/transactions/void.rb +26 -0
  31. data/lib/alpha_card/version.rb +1 -1
  32. data/spec/alpha_card/attribute_spec.rb +126 -0
  33. data/spec/alpha_card/response_spec.rb +8 -4
  34. data/spec/alpha_card/transactions/auth_spec.rb +43 -0
  35. data/spec/alpha_card/{objects → transactions}/capture_spec.rb +11 -12
  36. data/spec/alpha_card/transactions/credit_spec.rb +102 -0
  37. data/spec/alpha_card/{objects → transactions}/refund_spec.rb +4 -4
  38. data/spec/alpha_card/{objects → transactions}/sale_spec.rb +42 -41
  39. data/spec/alpha_card/{objects → transactions}/update_spec.rb +4 -4
  40. data/spec/alpha_card/transactions/validate_spec.rb +100 -0
  41. data/spec/alpha_card/{objects → transactions}/void_spec.rb +11 -11
  42. data/spec/spec_helper.rb +4 -0
  43. metadata +36 -47
  44. data/lib/alpha_card/errors/alpha_card_error.rb +0 -29
  45. data/lib/alpha_card/objects/account.rb +0 -48
  46. data/lib/alpha_card/objects/billing.rb +0 -31
  47. data/lib/alpha_card/objects/capture.rb +0 -51
  48. data/lib/alpha_card/objects/sale.rb +0 -82
  49. data/lib/alpha_card/objects/update.rb +0 -54
  50. data/lib/alpha_card/objects/void.rb +0 -45
  51. data/spec/alpha_card/objects/account_spec.rb +0 -20
  52. data/spec/alpha_card/objects/deprecated_methods_spec.rb +0 -32
@@ -1,26 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe AlphaCard::Void do
4
- let(:account) { AlphaCard::Account.new('demo', 'password') }
5
-
6
4
  context 'with invalid attributes' do
7
5
  let(:void) { AlphaCard::Void.new(transaction_id: 'Some ID') }
6
+ let(:response) { void.create }
8
7
 
9
8
  it 'response with error' do
10
- expect { void.create(account) }.to raise_error(AlphaCard::AlphaCardError)
9
+ expect(response.error?).to be_truthy
10
+ expect(response.message).to eq('Transaction was rejected by gateway')
11
11
  end
12
12
  end
13
13
 
14
14
  context 'with valid attributes' do
15
- let(:void) { AlphaCard::Void.new(transaction_id: '2303767426') }
15
+ let(:void) { AlphaCard::Void.new(transaction_id: 2303767426) }
16
16
 
17
17
  let(:order) { AlphaCard::Order.new(id: '1', description: 'Test') }
18
- let(:card_exp) { "#{'%02d' % Time.now.month}/#{Time.now.year.next}" }
18
+ let(:card_exp) { (Time.now + 31104000).strftime('%m%y') }
19
19
  let(:sale) { AlphaCard::Sale.new(card_expiration_date: card_exp, card_number: '4111111111111111', amount: '5.00') }
20
20
 
21
21
  it 'has valid request params' do
22
22
  expected_params = {
23
- transactionid: '2303767426',
23
+ transactionid: 2303767426,
24
24
  type: 'void'
25
25
  }
26
26
 
@@ -28,12 +28,12 @@ describe AlphaCard::Void do
28
28
  end
29
29
 
30
30
  it 'processed successfully' do
31
- success, response = sale.create(order, account)
32
- expect(success).to be_truthy
31
+ response = sale.create(order)
32
+ expect(response.success?).to be_truthy
33
33
  expect(response.transaction_id).not_to be_nil
34
34
 
35
- success, response = AlphaCard::Void.new(transaction_id: response.transaction_id).create(account)
36
- expect(success).to be_truthy
35
+ response = AlphaCard::Void.new(transaction_id: response.transaction_id).process
36
+ expect(response.success?).to be_truthy
37
37
  expect(response.text).to eq('Transaction Void Successful')
38
38
  end
39
39
  end
@@ -42,7 +42,7 @@ describe AlphaCard::Void do
42
42
  let(:void) { AlphaCard::Void.new }
43
43
 
44
44
  it 'raises an InvalidObject error' do
45
- expect { void.create(account) }.to raise_error(AlphaCard::InvalidObjectError)
45
+ expect { void.create }.to raise_error(AlphaCard::ValidationError)
46
46
  end
47
47
  end
48
48
  end
@@ -15,4 +15,8 @@ require 'alpha_card'
15
15
 
16
16
  RSpec.configure do |config|
17
17
  config.order = 'random'
18
+
19
+ config.before(:suite) do
20
+ AlphaCard::Account.use_demo_credentials!
21
+ end
18
22
  end
metadata CHANGED
@@ -1,55 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alpha_card
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Bulaj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-22 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: virtus
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.0.5
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.0.5
33
13
  - !ruby/object:Gem::Dependency
34
14
  name: rack
35
15
  requirement: !ruby/object:Gem::Requirement
36
16
  requirements:
37
17
  - - "~>"
38
18
  - !ruby/object:Gem::Version
39
- version: '1.2'
19
+ version: '2.0'
40
20
  - - ">="
41
21
  - !ruby/object:Gem::Version
42
- version: '1.2'
22
+ version: '2.0'
43
23
  type: :runtime
44
24
  prerelease: false
45
25
  version_requirements: !ruby/object:Gem::Requirement
46
26
  requirements:
47
27
  - - "~>"
48
28
  - !ruby/object:Gem::Version
49
- version: '1.2'
29
+ version: '2.0'
50
30
  - - ">="
51
31
  - !ruby/object:Gem::Version
52
- version: '1.2'
32
+ version: '2.0'
53
33
  - !ruby/object:Gem::Dependency
54
34
  name: rspec
55
35
  requirement: !ruby/object:Gem::Requirement
@@ -82,33 +62,42 @@ files:
82
62
  - Rakefile
83
63
  - alpha_card.gemspec
84
64
  - lib/alpha_card.rb
85
- - lib/alpha_card/alpha_card_object.rb
86
- - lib/alpha_card/alpha_card_response.rb
65
+ - lib/alpha_card/account.rb
66
+ - lib/alpha_card/attribute.rb
87
67
  - lib/alpha_card/data/avs_responses.yml
88
68
  - lib/alpha_card/data/credit_card_codes.yml
89
69
  - lib/alpha_card/data/cvv_responses.yml
90
70
  - lib/alpha_card/data/response_messages.yml
91
- - lib/alpha_card/errors/alpha_card_error.rb
92
71
  - lib/alpha_card/errors/api_connection_error.rb
93
- - lib/alpha_card/errors/invalid_object_error.rb
94
- - lib/alpha_card/objects/account.rb
95
- - lib/alpha_card/objects/billing.rb
96
- - lib/alpha_card/objects/capture.rb
97
- - lib/alpha_card/objects/order.rb
98
- - lib/alpha_card/objects/refund.rb
99
- - lib/alpha_card/objects/sale.rb
100
- - lib/alpha_card/objects/shipping.rb
101
- - lib/alpha_card/objects/update.rb
102
- - lib/alpha_card/objects/void.rb
72
+ - lib/alpha_card/errors/invalid_attribute_format.rb
73
+ - lib/alpha_card/errors/invalid_attribute_type.rb
74
+ - lib/alpha_card/errors/invalid_attribute_value.rb
75
+ - lib/alpha_card/errors/validation_error.rb
76
+ - lib/alpha_card/resource.rb
77
+ - lib/alpha_card/resources/billing.rb
78
+ - lib/alpha_card/resources/order.rb
79
+ - lib/alpha_card/resources/shipping.rb
80
+ - lib/alpha_card/response.rb
81
+ - lib/alpha_card/transaction.rb
82
+ - lib/alpha_card/transactions/auth.rb
83
+ - lib/alpha_card/transactions/capture.rb
84
+ - lib/alpha_card/transactions/credit.rb
85
+ - lib/alpha_card/transactions/refund.rb
86
+ - lib/alpha_card/transactions/sale.rb
87
+ - lib/alpha_card/transactions/update.rb
88
+ - lib/alpha_card/transactions/validate.rb
89
+ - lib/alpha_card/transactions/void.rb
103
90
  - lib/alpha_card/version.rb
104
- - spec/alpha_card/objects/account_spec.rb
105
- - spec/alpha_card/objects/capture_spec.rb
106
- - spec/alpha_card/objects/deprecated_methods_spec.rb
107
- - spec/alpha_card/objects/refund_spec.rb
108
- - spec/alpha_card/objects/sale_spec.rb
109
- - spec/alpha_card/objects/update_spec.rb
110
- - spec/alpha_card/objects/void_spec.rb
91
+ - spec/alpha_card/attribute_spec.rb
111
92
  - spec/alpha_card/response_spec.rb
93
+ - spec/alpha_card/transactions/auth_spec.rb
94
+ - spec/alpha_card/transactions/capture_spec.rb
95
+ - spec/alpha_card/transactions/credit_spec.rb
96
+ - spec/alpha_card/transactions/refund_spec.rb
97
+ - spec/alpha_card/transactions/sale_spec.rb
98
+ - spec/alpha_card/transactions/update_spec.rb
99
+ - spec/alpha_card/transactions/validate_spec.rb
100
+ - spec/alpha_card/transactions/void_spec.rb
112
101
  - spec/spec_helper.rb
113
102
  homepage: http://github.com/nbulaj/alpha_card
114
103
  licenses:
@@ -122,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
111
  requirements:
123
112
  - - ">="
124
113
  - !ruby/object:Gem::Version
125
- version: 2.0.0
114
+ version: 2.2.2
126
115
  required_rubygems_version: !ruby/object:Gem::Requirement
127
116
  requirements:
128
117
  - - ">="
@@ -1,29 +0,0 @@
1
- module AlphaCard
2
- ##
3
- # Common class for Alpha Card Gateway errors and exceptions.
4
- class AlphaCardError < StandardError
5
- # Alpha Card Gateway response.
6
- # @attr_reader [AlphaCard::AlphaCardResponse] response
7
- attr_reader :response
8
- # Error message.
9
- # @attr_reader [String] message
10
- attr_reader :message
11
-
12
- ##
13
- # <code>AlphaCard::AlphaCardError</code> constructor.
14
- #
15
- # @param [String] message
16
- # Error message
17
- # @param [AlphaCard::AlphaCardResponse] response
18
- # AlphaCard Gateway response
19
- #
20
- # @example
21
- # AlphaCard::AlphaCardError.new
22
- #
23
- # #=> #<AlphaCard::AlphaCardError: AlphaCard::AlphaCardError>
24
- def initialize(message = nil, response = nil)
25
- @message = message
26
- @response = response
27
- end
28
- end
29
- end
@@ -1,48 +0,0 @@
1
- module AlphaCard
2
- ##
3
- # Implementation of Alpha Card Services account object.
4
- # Contains credentials (username and password) for
5
- # the Alpha Card Gateway API access.
6
- class Account < AlphaCardObject
7
- attribute :username, String
8
- attribute :password, String
9
-
10
- ##
11
- # <code>AlphaCard::Account</code> constructor.
12
- #
13
- # @param [String] username
14
- # @param [String] password
15
- #
16
- # @example
17
- # AlphaCard::Account.new('demo', 'password')
18
- #
19
- # #=> #<AlphaCard::Account:0x000000039b18a8 @username="demo", @password="password">
20
- def initialize(username, password)
21
- self.username = username
22
- self.password = password
23
- end
24
-
25
- ##
26
- # Say if all the credentials of Account is filled.
27
- # Username and password can't be a <code>nil</code>
28
- # object or an empty <code>String</code>.
29
- #
30
- # @return [Boolean]
31
- # True if username and password is filled.
32
- #
33
- # @example
34
- # account = AlphaCard::Account.new('demo', 'password')
35
- # account.filled?
36
- #
37
- # #=> true
38
- #
39
- # account = AlphaCard::Account.new('', nil)
40
- # account.filled?
41
- #
42
- # #=> false
43
- def filled?
44
- attrs = [username, password]
45
- attrs.all? { |attr| attr && !attr.strip.empty? }
46
- end
47
- end
48
- end
@@ -1,31 +0,0 @@
1
- module AlphaCard
2
- ##
3
- # Implementation of Alpha Card Services order billing information.
4
- # Contains all the billing information (customer name, email, email, etc).
5
- class Billing < AlphaCardObject
6
- attribute :first_name, String
7
- attribute :last_name, String
8
- attribute :email, String
9
- attribute :phone, String
10
- attribute :company, String
11
- attribute :address_1, String
12
- attribute :address_2, String
13
- attribute :city, String
14
- attribute :state, String
15
- attribute :zip, String
16
- attribute :country, String
17
- attribute :fax, String
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!
30
- end
31
- end
@@ -1,51 +0,0 @@
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
@@ -1,82 +0,0 @@
1
- module AlphaCard
2
- ##
3
- # Implementation of Alpha Card Services Sale transaction.
4
- # Contains all the information about Customer Credit Card,
5
- # such as CVV, number, expiration date, etc.
6
- # Process the Alpha Card Services payment.
7
- class Sale < AlphaCardObject
8
- # Format: MMYY
9
- attribute :card_expiration_date, String
10
- attribute :card_number, String
11
- attribute :amount, String
12
- attribute :cvv, String
13
- # Values: 'true' or 'false'
14
- attribute :customer_receipt, String
15
-
16
- ##
17
- # Payment type.
18
- # Values: 'creditcard' or 'check'
19
- attribute :payment, String, default: 'creditcard'
20
-
21
- ##
22
- # Transaction type (default is 'sale')
23
- #
24
- # @attribute [r] type
25
- attribute :type, String, default: 'sale', writer: :private
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
-
36
- ##
37
- # Creates the sale for the specified <code>AlphaCard::Order</code>
38
- # with the <code>AlphaCard::Account</code> credentials.
39
- #
40
- # @param [AlphaCard::Order] params
41
- # An <code>AlphaCard::Order</code> object.
42
- # @param [AlphaCard::Account] account
43
- # An <code>AlphaCard::Account</code> object.
44
- #
45
- # @return [Boolean]
46
- # True if sale was created successfully.
47
- # Raise an AlphaCardError exception if some error occurred.
48
- #
49
- # @raise [AlphaCard::InvalidObjectError]
50
- # Exception if one of required attributes doesn't specified.
51
- #
52
- # @example
53
- # account = AlphaCard::Account.new('demo', 'password')
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' )
56
- # sale.create(order, account)
57
- #
58
- # #=> [true, #<AlphaCard::AlphaCardResponse:0x1a0fda ...>]
59
- def create(order, account)
60
- abort_if_attributes_blank!(:card_expiration_date, :card_number, :amount)
61
-
62
- response = AlphaCard.request(account, params_for_sale(order))
63
- [response.success?, response]
64
- end
65
-
66
- private
67
-
68
- ##
69
- # Returns all the necessary attributes with it's original
70
- # names that must be passed with Sale transaction.
71
- #
72
- # @param [AlphaCard::Order] order
73
- # An <code>AlphaCard::Order</code> object.
74
- #
75
- # @return [Hash]
76
- # Params of *self* object merged with params
77
- # of another object (<code>AlphaCard::Order</code>)
78
- def params_for_sale(order)
79
- attributes_for_request.merge(order.attributes_for_request)
80
- end
81
- end
82
- end