astro_pay 0.0.2 → 0.0.3

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: cc46963e43d93f0c7679d68a55feec74081bc535
4
- data.tar.gz: b5d1e2642aefeb66797ffd226801e3fbe52c7abf
3
+ metadata.gz: 9acac83578a0e07585a44eeabb2010472c83b7c1
4
+ data.tar.gz: e7d42e5a332a57b4a6c6eff1cf7c670800fd06f9
5
5
  SHA512:
6
- metadata.gz: 8352474f0b1f8d4d166defd4de9cae74d8e7a9c60b09e9d9dd687715708a062fb17e9fb4297047a56f6fc079b42054555b0ff437dea310b07e80fd91f0760676
7
- data.tar.gz: 0b6a75cff9129f90748e93e4bdaa50d7f74d9042b8e1f23ba6dce33724bd8729d20d3faef1585c4c8f7ad52a890b149ca012afff1ac5ba70ed4e95b774929ae1
6
+ metadata.gz: 5304f7ebf8b1e8816004ed63616122479eaafd8b69d4632783205a618c137ecf147b0359af522905569736b464acd351d3c8c2699964ddd302c9fc54b2dce60f
7
+ data.tar.gz: 4e13f55415704634e69d00f07bb8f09fcbc3f00ba93f62c01453b797f179bccbac2ca01467adf83bf2801a8fb79d37b0da537995d01d837e77e9525192ec7cc2
@@ -23,25 +23,45 @@ module AstroPay
23
23
  attr_writer :configuration
24
24
  end
25
25
 
26
+ # Gets the configuration attribute.
27
+ #
28
+ # @return [AstroPay::Configuration] object.
26
29
  def self.configuration
27
30
  @configuration ||= Configuration.new
28
31
  end
29
32
 
33
+ # Allows to set the configuration passing a block where the values are set.
30
34
  def self.configure
31
35
  yield(configuration)
32
36
  end
33
37
 
38
+ # Gets a new [AstroPay::Direct] instance with the given arguments.
39
+ #
40
+ # @param args [Array] (See AstroPay::Direct#initialize).
41
+ # @return [AstroPay::Direct] object.
34
42
  def self.direct(*args)
35
43
  Direct.new(*args)
36
44
  end
37
45
 
46
+ # Gets a new [AstroPay::Card] instance with the given arguments.
47
+ #
48
+ # @params args [Array] (See AstroPay::Card#initialize).
49
+ # @return [AstroPay::Card] object.
38
50
  def self.card(*args)
39
51
  Card.new(*args)
40
52
  end
41
53
 
42
- # Optional:
43
- # You can send a Hash containing the following accepted params:
44
- # :description, :currency, :cpf, :return_url, :confirmation_url
54
+ # Gets a new [AstroPay::Direct] instance with the given arguments and some
55
+ # optional values. See the AstroPay Direct Manual.
56
+ #
57
+ # @param invoice [String] unique transaction ID number at the merchant.
58
+ # @param amount [Float] the amount of the payment.
59
+ # @param iduser [String] user’s unique ID at the merchant / account number.
60
+ # @param country [String] country code.
61
+ # @param bank [String] bank code.
62
+ # @param sub_code [Int] mandatory parameter for PSPs.
63
+ # @param args [Hash] Other arguments.
64
+ # @return [AstroPay::Direct] object.
45
65
  def self.create_direct(invoice, amount, iduser, country, bank='', sub_code=1, args={})
46
66
  direct(
47
67
  args.merge(
@@ -55,6 +75,19 @@ module AstroPay
55
75
  ).create
56
76
  end
57
77
 
78
+ # Gets a new [AstroPay::Card] instance with the given arguments and some
79
+ # optional values. See the AstroPay Card Manual.
80
+ #
81
+ # @param number [String] AstroPay Card number.
82
+ # @param ccv [Int] AstroPay Card security code.
83
+ # @param exp_date [String] expiration date of AstroPay Card. Format: MM/YYYY
84
+ # @param amount [Float] transaction amount.
85
+ # @param bank [String] bank code.
86
+ # @param unique_id [String] unique, anonymized identifier of users in the
87
+ # merchant system.
88
+ # @param invoice_num [String] unique identifier of merchant transaction.
89
+ # @param additional_params [Hash] other arguments.
90
+ # @return [AstroPay::Card] object.
58
91
  def self.create_card(number, ccv, exp_date, amount, unique_id, invoice_num, additional_params={})
59
92
  card(
60
93
  number: number,
@@ -8,11 +8,16 @@ module AstroPay
8
8
  class Card < AstroPay::Model
9
9
 
10
10
  # Input params
11
- attr_accessor :approval_code, :number, :ccv, :exp_date
12
- attr_accessor :amount, :unique_id, :invoice_num, :transaction_id
13
- attr_accessor :additional_params, :type
11
+ attr_accessor :approval_code, :number, :ccv, :exp_date, :amount, :unique_id
12
+ attr_accessor :invoice_num, :transaction_id, :additional_params, :type
14
13
 
15
- def initialize(args={})
14
+ # Creates a new instance of [AstroPay::Card].
15
+ #
16
+ # @param attributes [Hash] with the following fields: :approval_code,
17
+ # :number, :ccv, :exp_date, :amount, :unique_id :invoice_num,
18
+ # :transaction_id, :additional_params, :type.
19
+ # @return [AstroPay::Card] object.
20
+ def initialize(args = {})
16
21
  config = AstroPay.configuration
17
22
 
18
23
  @x_login = config.card_x_login
@@ -21,12 +26,19 @@ module AstroPay
21
26
 
22
27
  base_url = "https://#{'sandbox-' if @sandbox}api.astropaycard.com/"
23
28
 
24
- @x_version = "2.0" #AstroPay API version (default "2.0")
25
- @x_delim_char = "|" #Field delimit character, the character that separates the fields (default "|")
26
- @x_test_request = 'N' #Change to N for production
27
- @x_duplicate_window = 30 #Time window of a transaction with the sames values is taken as duplicated (default 120)
29
+ # AstroPay API version (default "2.0")
30
+ @x_version = "2.0"
31
+ # Field delimiter (default "|")
32
+ @x_delim_char = "|"
33
+ # Change to N for production
34
+ @x_test_request = 'N'
35
+ # Time window of a transaction with the sames values is taken as
36
+ # duplicated (default 120)
37
+ @x_duplicate_window = 30
28
38
  @x_method = "CC"
29
- @x_response_format = "json" #Response format: "string", "json", "xml" (default: string) (recommended: json)
39
+ # Response format:
40
+ # "string", "json", "xml" (default: string; recommended: json)
41
+ @x_response_format = "json"
30
42
 
31
43
  @additional_params = Hash.new
32
44
 
@@ -36,16 +48,20 @@ module AstroPay
36
48
  @transtatus_url = "#{base_url}verif/transtatus"
37
49
  end
38
50
 
39
- # Authorizes a transaction
51
+ # Requests AstroPay to AUTHORIZE a transaction.
40
52
  #
41
- # number AstroPay Card number (16 digits)
42
- # ccv AstroPay Card security code (CVV)
43
- # exp_date AstroPay Card expiration date
44
- # amount Amount of the transaction
45
- # unique_id Unique user ID of the merchant
46
- # invoice_num Merchant transaction identificator, i.e. the order number
47
- # additional_params Array of additional info that you would send to AstroPay for reference purpose.
48
- # return json of params returned by AstroPay capture API. Please see section 3.1.3 "Response" of AstroPay Card integration manual for more info
53
+ # @note This method sends in the request the following data:
54
+ # 'number', AstroPay Card number (16 digits);
55
+ # 'ccv', AstroPay Card security code (CVV);
56
+ # 'exp_date', AstroPay Card expiration date;
57
+ # 'amount', Amount of the transaction;
58
+ # 'unique_id', Unique user ID of the merchant;
59
+ # 'invoice_num', Merchant transaction identifier, i.e. the order
60
+ # number;
61
+ # 'additional_params', Array of additional info that you would send
62
+ # to AstroPay for reference purpose.
63
+ # @return [Hash] response by AstroPay capture API. Please see section 3.1.3
64
+ # "Response" of AstroPay Card integration manual for more info.
49
65
  def auth_transaction
50
66
  data = full_params.merge(
51
67
  'x_unique_id' => unique_id,
@@ -56,17 +72,11 @@ module AstroPay
56
72
  astro_curl(@validator_url, data)
57
73
  end
58
74
 
59
- # Caputures previous authorized transaction
75
+ # Requests AstroPay to CAPTURE the previous authorized transaction.
60
76
  #
61
- # auth_code The x_auth_code returned by auth_transaction method
62
- # number AstroPay Card number (16 digits)
63
- # ccv AstroPay Card security code (CVV)
64
- # exp_date AstroPay Card expiration date
65
- # amount Amount of the transaction
66
- # unique_id Unique user ID of the merchant
67
- # invoice_num Merchant transaction identificator, i.e. the order number
68
- # additional_params Array of additional info that you would send to AstroPay for reference purpose.
69
- # return json returned by AstroPay capture API. Please see section 3.1.3 "Response" of AstroPay Card integration manual for more info
77
+ # @note (See #auth_transaction) to known the data sent on the request.
78
+ # @return [Hash] response by AstroPay capture API. Please see section 3.1.3
79
+ # "Response" of AstroPay Card integration manual for more info.
70
80
  def capture_transaction
71
81
  data = full_params.merge(
72
82
  'x_unique_id' => unique_id,
@@ -78,16 +88,12 @@ module AstroPay
78
88
  astro_curl(@validator_url, data)
79
89
  end
80
90
 
81
- # Authorize and capture a transaction at the same time (if it is possible)
91
+ # Requests AstroPay to AUTHORIZE and CAPTURE a transaction at the same time
92
+ # (if it is possible).
82
93
  #
83
- # number AstroPay Card number (16 digits)
84
- # ccv AstroPay Card security code (CVV)
85
- # exp_date AstroPay Card expiration date
86
- # amount Amount of the transaction
87
- # unique_id Unique user ID of the merchant
88
- # invoice_num Merchant transaction identificator, i.e. the order number
89
- # additional_params Array of additional info that you would send to AstroPay for reference purpose.
90
- # return json returned by AstroPay capture API. Please see section 3.1.3 "Response" of AstroPay Card integration manual for more info
94
+ # @note (See #auth_transaction) to known the data sent on the request.
95
+ # @return [Hash] response by AstroPay capture API. Please see section 3.1.3
96
+ # "Response" of AstroPay Card integration manual for more info.
91
97
  def auth_capture_transaction
92
98
  data = full_params.merge(
93
99
  'x_unique_id' => unique_id,
@@ -98,15 +104,13 @@ module AstroPay
98
104
  astro_curl(@validator_url, data)
99
105
  end
100
106
 
101
- # Refund a transaction
107
+ # Requests AstroPay to REFUND a transaction.
102
108
  #
103
- # transaction_id merchant invoice number sent in previus call of capture_transaction or auth_transaction
104
- # number AstroPay Card number (16 digits)
105
- # ccv AstroPay Card security code (CVV)
106
- # exp_date AstroPay Card expiration date
107
- # amount Amount of the transaction
108
- # additional_params Array of additional info that you would send to AstroPay for reference purpose.
109
- # return json returned by AstroPay capture API. Please see section 3.2.2 "Response" of AstroPay Card integration manual for more info
109
+ # @note This request includes the transaction_id merchant invoice number
110
+ # sent in previous call of capture_transaction or auth_transaction.
111
+ # (See #auth_transaction) to known the data sent on the request.
112
+ # @return [Hash] response by AstroPay capture API. Please see section 3.1.3
113
+ # "Response" of AstroPay Card integration manual for more info.
110
114
  def refund_transaction
111
115
  data = full_params.merge(
112
116
  'x_trans_id' => transaction_id,
@@ -116,15 +120,13 @@ module AstroPay
116
120
  astro_curl(@validator_url, data)
117
121
  end
118
122
 
119
- # VOID a transaction
123
+ # Requests AstroPay to VOID a transaction.
120
124
  #
121
- # transaction_id merchant invoice number sent in previus call of capture_transaction or auth_transaction
122
- # number AstroPay Card number (16 digits)
123
- # ccv AstroPay Card security code (CVV)
124
- # exp_date AstroPay Card expiration date
125
- # amount Amount of the transaction
126
- # additional_params Array of additional info that you would send to AstroPay for reference purpose.
127
- # return json returned by AstroPay capture API. Please see section 3.2.2 "Response" of AstroPay Card integration manual for more info
125
+ # @note This request includes the transaction_id merchant invoice number
126
+ # sent in previous call of capture_transaction or auth_transaction.
127
+ # (See #auth_transaction) to known the data sent on the request.
128
+ # @return [Hash] response by AstroPay capture API. Please see section 3.1.3
129
+ # "Response" of AstroPay Card integration manual for more info.
128
130
  def void_transaction
129
131
  data = full_params.merge(
130
132
  'x_trans_id' => transaction_id,
@@ -134,11 +136,14 @@ module AstroPay
134
136
  astro_curl(@validator_url, data)
135
137
  end
136
138
 
137
- # Checks the status of a transaction
139
+ # Requests AstroPay the status of a transaction.
138
140
  #
139
- # invoice_num The merchant id sent in the transaction
140
- # type 0 for basic info, 1 for detailed info
141
- # return json. Please see section 3.2.3 of APC integration manual from more details.
141
+ # @note This request includes the basic credentials data and the following
142
+ # fields:
143
+ # 'invoice_num', The merchant id sent in the transaction;
144
+ # 'type', 0 for basic info, 1 for detailed info.
145
+ # @return [Hash] response by AstroPay capture API. Please see section 3.1.3
146
+ # "Response" of AstroPay Card integration manual for more info.
142
147
  def check_transaction_status
143
148
  data = basic_credentials.merge(
144
149
  'x_trans_key' => @x_trans_key,
@@ -149,16 +154,32 @@ module AstroPay
149
154
  astro_curl(@transtatus_url, data)
150
155
  end
151
156
 
152
- def astro_curl(url, params_hash)
153
- AstroPay::Curl.post(url, params_hash)
157
+ # Makes a request to the AstroPay API.
158
+ #
159
+ # @param url [String] endpoint for the AstroPay API.
160
+ # @param params [Hash] data and options for the request.
161
+ # @return [Hash] of the successful response or [String] of the response if
162
+ # an error rises.
163
+ def astro_curl(url, params)
164
+ AstroPay::Curl.post(url, params)
154
165
  end
155
166
 
167
+ # Generates an hexadecimal code intended to be used in the checksum of the
168
+ # messages received.
169
+ #
170
+ # @param transaction_id [String] merchant's id for the transaction.
171
+ # @param amount [Float] of the transaction.
172
+ # @return [String] of 64 uppercase characters.
156
173
  def calculate_control(transaction_id, amount)
157
- Digest::MD5.hexdigest("#{@x_login}#{transaction_id}#{amount}");
174
+ Digest::MD5.hexdigest("#{@x_login}#{transaction_id}#{amount}")
158
175
  end
159
176
 
160
177
  private
161
178
 
179
+ # Sets a collection with the basic credentials for the AstroPay API.
180
+ #
181
+ # @return [Hash] Please see section 3.4 of the AstroPay Card integration
182
+ # manual for more info.
162
183
  def basic_credentials
163
184
  {
164
185
  'x_login' => @x_login,
@@ -169,6 +190,9 @@ module AstroPay
169
190
  }
170
191
  end
171
192
 
193
+ # Sets a collection with the complete credentials for the AstroPay API.
194
+ #
195
+ # @return [Hash] See the AstroPay Card integration manual for more info.
172
196
  def full_credentials
173
197
  basic_credentials.merge(
174
198
  'x_method' => @x_method,
@@ -177,6 +201,9 @@ module AstroPay
177
201
  )
178
202
  end
179
203
 
204
+ # Sets a collection with the basic data of an AstroPay card.
205
+ #
206
+ # @return [Hash] See the AstroPay Card integration manual for more info.
180
207
  def basic_variables
181
208
  {
182
209
  'x_card_num' => number,
@@ -186,6 +213,11 @@ module AstroPay
186
213
  }
187
214
  end
188
215
 
216
+ # Sets a collection with the credentials, the card data and additional
217
+ # parameters to be used on API calls.
218
+ #
219
+ # @return [Hash] See #basic_credential, #full_credentials and
220
+ # #basic_variables.
189
221
  def full_params
190
222
  full_credentials.merge(
191
223
  additional_params
@@ -194,4 +226,4 @@ module AstroPay
194
226
  )
195
227
  end
196
228
  end
197
- end
229
+ end
@@ -10,9 +10,13 @@ module AstroPay
10
10
  #Optional attributes
11
11
  attr_accessor :sandbox, :enable_ssl
12
12
 
13
+ # Creates a new instance of [AstroPay::Configuration].
14
+ #
15
+ # @param attributes [Hash] with the following fields: :error, :message.
16
+ # @return [AstroPay::Configuration] instance.
13
17
  def initialize
14
18
  @sandbox = true
15
19
  @enable_ssl = true
16
20
  end
17
21
  end
18
- end
22
+ end
@@ -1,9 +1,20 @@
1
1
  module AstroPay
2
2
  class Curl
3
+
4
+ # Gets the configuration flag for SSL use with Astropay connections.
5
+ #
6
+ # @return [Boolean]
3
7
  def self.enable_ssl
4
8
  AstroPay.configuration.enable_ssl
5
9
  end
6
10
 
11
+ # Performs a POST request to the given URL with the given parameters.
12
+ # @param url [String] to where the request will be made.
13
+ # @param params_hash [Hash] parameters to be sent with the request.
14
+ # @return [Hash] of the response or, if an error rises, [String] of
15
+ # the response content.
16
+ # @note When SSL is enabled, no certificate is actually verified due to
17
+ # SSLv3 incompatibilities.
7
18
  def self.post(url, params_hash)
8
19
  uri = URI.parse(url)
9
20
  http = Net::HTTP.new(uri.host, uri.port)
@@ -24,4 +35,4 @@ module AstroPay
24
35
  end
25
36
  end
26
37
  end
27
- end
38
+ end
@@ -12,7 +12,13 @@ module AstroPay
12
12
  attr_accessor :description, :cpf, :sub_code, :return_url, :confirmation_url
13
13
  attr_accessor :response_type
14
14
 
15
- def initialize(args={})
15
+ # Creates a new instance of [AstroPay::Direct].
16
+ #
17
+ # @param attributes [Hash] with the following fields: :invoice, :amount,
18
+ # :iduser, :bank, :country, :currency, :description, :cpf,
19
+ # :sub_code, :return_url, :confirmation_url.
20
+ # @return [AstroPay::Direct] object.
21
+ def initialize(args = {})
16
22
  config = AstroPay.configuration
17
23
 
18
24
  @x_login = config.direct_x_login
@@ -35,6 +41,11 @@ module AstroPay
35
41
  }
36
42
  end
37
43
 
44
+ # Creates a new transaction.
45
+ #
46
+ # @return [Hash] of the response that includes the URL to where an user
47
+ # should be redirected to validate and complete the process. If
48
+ # there is an error, the [String] response is returned.
38
49
  def create
39
50
  params_hash = {
40
51
  'x_login' => @x_login,
@@ -64,9 +75,13 @@ module AstroPay
64
75
  astro_curl(@astro_urls['create'], params_hash)
65
76
  end
66
77
 
78
+ # Requests a list of valid banks by country.
79
+ #
80
+ # @return [Hash] of the response that includes the list of banks. If there
81
+ # is an error, the [String] response is returned.
67
82
  def get_banks_by_country
68
83
  params_hash = {
69
- #Mandatory
84
+ # Mandatory
70
85
  'x_login' => @x_login,
71
86
  'x_trans_key' => @x_trans_key,
72
87
  'country_code' => country,
@@ -76,9 +91,13 @@ module AstroPay
76
91
  astro_curl(@astro_urls['banks'], params_hash)
77
92
  end
78
93
 
94
+ # Requests the status of a transaction.
95
+ #
96
+ # @return [Hash] of the response that includes the transaction status. If
97
+ # there is an error, the [String] response is returned.
79
98
  def get_invoice_status
80
99
  params_hash = {
81
- #Mandatory
100
+ # Mandatory
82
101
  'x_login' => @x_login_for_webpaystatus,
83
102
  'x_trans_key' => @x_trans_key_for_webpaystatus,
84
103
  'x_invoice' => invoice,
@@ -88,9 +107,13 @@ module AstroPay
88
107
  astro_curl(@astro_urls['status'], params_hash)
89
108
  end
90
109
 
110
+ # Requests the exchange rate from USD to the currency of a target country.
111
+ #
112
+ # @return [Hash] of the response that includes the exchange rate. If there
113
+ # is an error, the [String] response is returned.
91
114
  def get_exchange
92
115
  params_hash = {
93
- #Mandatory
116
+ # Mandatory
94
117
  'x_login' => @x_login_for_webpaystatus,
95
118
  'x_trans_key' => @x_trans_key_for_webpaystatus,
96
119
  'x_country' => country,
@@ -100,6 +123,12 @@ module AstroPay
100
123
  astro_curl(@astro_urls['exchange'], params_hash)
101
124
  end
102
125
 
126
+ # Makes a request to the AstroPay API.
127
+ #
128
+ # @param url [String] endpoint for the AstroPay API.
129
+ # @param params [Hash] data and options for the request.
130
+ # @return [Hash] of the successful response or [String] of the response if
131
+ # an error rises.
103
132
  def astro_curl(url, params_hash)
104
133
  AstroPay::Curl.post(url, params_hash)
105
134
  end
@@ -6,10 +6,20 @@ module AstroPay
6
6
  include ActiveModel::Conversion
7
7
  extend ActiveModel::Naming
8
8
 
9
+ # Creates a new instance of [AstroPay::Model].
10
+ #
11
+ # @param attributes [Hash] with the following fields: :error, :message.
12
+ # @return [AstroPay::Model] object.
9
13
  def initialize(attributes = {})
10
14
  self.attributes = attributes
11
15
  end
12
16
 
17
+ # Sets a given hash values as attribute values for the class. It will try
18
+ # to match the keys of the hash to existent attributes that have accessors.
19
+ #
20
+ # @param attributes [Hash]
21
+ # @note If raised, [NoMethodError] will be caught and a message will be
22
+ # printed to the standard output.
13
23
  def attributes=(attributes = {})
14
24
  attributes.each do |name, value|
15
25
  begin
@@ -20,6 +30,10 @@ module AstroPay
20
30
  end
21
31
  end
22
32
 
33
+ # Gets the instance attributes.
34
+ #
35
+ # @return [Hash] with the attribute name as key, and the attribute value as
36
+ # value.
23
37
  def attributes
24
38
  Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }]
25
39
  end
@@ -1,3 +1,3 @@
1
1
  module AstroPay
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astro_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Galaviz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler