twocheckout 0.4.0 → 0.5.0

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
- SHA1:
3
- metadata.gz: c2c35dc95ae9cdba6bff621701724ca93c71c21a
4
- data.tar.gz: 838bdbed8f8e1dcb5eeff2c33408492460f8b9b6
2
+ SHA256:
3
+ metadata.gz: 6ae819e29f87aa59ae4f4756f06d8e1cdccba403f504f4e2eafd5e3e86ef64c3
4
+ data.tar.gz: dbe2d6eb71fb17e18d37585f2183976225f1da6d3849d09834f1a727cc4304fb
5
5
  SHA512:
6
- metadata.gz: 55449a02efd9c154bd807bebc35d882b1c57f9f2b6ed5ff51ab7f2c4ee18ba436ca9510b58128618e27edd42d3671363b7656ada1f222ada1fd5632783754c37
7
- data.tar.gz: 1f2ecbf090ee57623cf93d2b1d6130bbccb41aa6ccfd05222524e623400bc9a9a53f7500bde362c5fb09343ff7a266291e47f32a86ffe5b56f602e1757154592
6
+ metadata.gz: 9957625ac830b0e2b4be232e449dd29cb9bed844526a943a3aacc0bed878eb0f5eea1b9b95329c7a10d23ca963e486d173d2801ffb623e1855c47bb6579d9f02
7
+ data.tar.gz: 7001057a88943e0c38900c38893bef7e1b9638768285a71848f240381b9c1ed6492e75df4680a5273297026d665cd60d6d550e497bca4b249ccc42412856467c
@@ -1,13 +1,11 @@
1
- require "twocheckout/version"
2
- require "twocheckout/api"
3
- require "twocheckout/hash_object"
4
- require "twocheckout/validate_response"
5
- require "twocheckout/company"
6
- require "twocheckout/lineitem"
7
- require "twocheckout/invoice"
8
- require "twocheckout/sale"
9
- require "twocheckout/coupon"
10
- require "twocheckout/product"
11
- require "twocheckout/option"
12
- require "twocheckout/checkout"
13
- require "twocheckout/twocheckout_error"
1
+ require 'twocheckout/version'
2
+ require 'twocheckout/api'
3
+ require 'twocheckout/hash_object'
4
+ require 'twocheckout/validate_response'
5
+ require 'twocheckout/company'
6
+ require 'twocheckout/lineitem'
7
+ require 'twocheckout/invoice'
8
+ require 'twocheckout/sale'
9
+ require 'twocheckout/product'
10
+ require 'twocheckout/checkout'
11
+ require 'twocheckout/twocheckout_error'
@@ -3,16 +3,14 @@ require 'json'
3
3
 
4
4
  module Twocheckout
5
5
  class API
6
- PROD_BASE = 'https://www.2checkout.com'
7
- SANDBOX_BASE = 'https://sandbox.2checkout.com'
8
- API_VERSION = '1'
6
+ PROD_BASE = 'https://www.2checkout.com'.freeze
7
+ API_VERSION = '1'.freeze
9
8
 
10
9
  def self.credentials=(opts)
11
10
  @username = opts[:username]
12
11
  @password = opts[:password]
13
12
  @private_key = opts[:private_key]
14
13
  @seller_id = opts[:seller_id]
15
- @sandbox = opts[:sandbox]
16
14
  end
17
15
 
18
16
  def self.request(http_method, api_call, params = nil)
@@ -33,7 +31,7 @@ module Twocheckout
33
31
  private
34
32
 
35
33
  def self.set_opts(http_method, api_call, params = null)
36
- url = @sandbox ? SANDBOX_BASE : PROD_BASE
34
+ url = PROD_BASE
37
35
  if api_call == 'authService'
38
36
  url += '/checkout/api/' + API_VERSION + '/' + @seller_id + '/rs/' + api_call
39
37
  params['sellerId'] = @seller_id
@@ -3,10 +3,6 @@ module Twocheckout
3
3
 
4
4
  @checkout_url = 'https://www.2checkout.com/checkout/purchase'
5
5
 
6
- def self.sandbox(sandbox)
7
- @checkout_url = sandbox ? 'https://sandbox.2checkout.com/checkout/purchase' : @checkout_url;
8
- end
9
-
10
6
  def self.form(params={}, button_text='Proceed to Checkout')
11
7
  @form = "<form id=\"2checkout\" action=\"#{@checkout_url}\" method=\"post\">\n";
12
8
  params.each do |k,v|
@@ -75,13 +75,6 @@ module Twocheckout
75
75
  Twocheckout::API.request(:post, 'sales/mark_shipped', opts)
76
76
  end
77
77
 
78
- #
79
- # Reauthorize sale
80
- #
81
- def reauth
82
- Twocheckout::API.request(:post, 'sales/reauth', sale_id: self.sale_id)
83
- end
84
-
85
78
  #
86
79
  # Get sale list in an array
87
80
  #
@@ -1,3 +1,3 @@
1
1
  module Twocheckout
2
- VERSION = "0.4.0"
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -2,11 +2,8 @@ require "minitest/autorun"
2
2
  require "twocheckout"
3
3
 
4
4
  Twocheckout::API.credentials = {
5
- :username => 'testlibraryapi901248204',
6
- :password => 'testlibraryapi901248204PASS',
7
- :seller_id => '901248204',
8
- :private_key => 'BE632CB0-BB29-11E3-AFB6-D99C28100996',
9
- :sandbox => true
10
- }
11
-
12
- Twocheckout::Checkout.sandbox(true);
5
+ :username => 'CREDENTIALS HERE',
6
+ :password => 'CREDENTIALS HERE',
7
+ :seller_id => 'CREDENTIALS HERE',
8
+ :private_key => 'CREDENTIALS HERE',
9
+ }
@@ -7,14 +7,14 @@ describe Twocheckout::Sale do
7
7
 
8
8
  #retrieve sale
9
9
  it "Sale retrieve returns sale" do
10
- sale = Twocheckout::Sale.find(:sale_id => 9093717691800)
11
- assert_equal('9093717691800', sale.sale_id)
10
+ sale = Twocheckout::Sale.find(:sale_id => 250335346812)
11
+ assert_equal('250335346812', sale.sale_id)
12
12
  end
13
13
 
14
14
  #retrieve invoice
15
15
  it "Sale retrieve returns invoice" do
16
- invoice = Twocheckout::Sale.find({:invoice_id => 9093717691821})
17
- assert_equal('9093717691821', invoice.invoice_id)
16
+ invoice = Twocheckout::Sale.find({:invoice_id => 250334725631})
17
+ assert_equal('250334725631', invoice.invoice_id)
18
18
  end
19
19
 
20
20
  #retrieve sale list
@@ -26,40 +26,40 @@ describe Twocheckout::Sale do
26
26
  #refund sale
27
27
  it "Refunding a refunded sale returns Twocheckout::TwocheckoutError" do
28
28
  begin
29
- sale = Twocheckout::Sale.find(:sale_id => 9093717691800)
29
+ sale = Twocheckout::Sale.find(:sale_id => 250335365202)
30
30
  sale.refund!({:comment => "test refund", :category => 1})
31
31
  rescue Twocheckout::TwocheckoutError => e
32
- assert_equal("Invoice was already refunded.", e.message)
32
+ assert_equal("Amount greater than remaining balance on invoice.", e.message)
33
33
  end
34
34
  end
35
35
 
36
36
  #refund invoice
37
37
  it "Refunding a refunded invoice returns Twocheckout::TwocheckoutError" do
38
38
  begin
39
- sale = Twocheckout::Sale.find(:sale_id => 9093717691800)
39
+ sale = Twocheckout::Sale.find(:sale_id => 250335365202)
40
40
  invoice = sale.invoices.first
41
41
  invoice.refund!({:comment => "test refund", :category => 1})
42
42
  rescue Twocheckout::TwocheckoutError => e
43
- assert_equal("Invoice was already refunded.", e.message)
43
+ assert_equal("Amount greater than remaining balance on invoice.", e.message)
44
44
  end
45
45
  end
46
46
 
47
47
  #refund lineitem
48
48
  it "Refunding a refunded lineitem returns Twocheckout::TwocheckoutError" do
49
49
  begin
50
- sale = Twocheckout::Sale.find(:sale_id => 9093717691800)
50
+ sale = Twocheckout::Sale.find(:sale_id => 250192108517)
51
51
  first_invoice = sale.invoices.first
52
52
  last_lineitem = first_invoice.lineitems.last
53
53
  last_lineitem.refund!({:comment => "test refund", :category => 1})
54
54
  rescue Twocheckout::TwocheckoutError => e
55
- assert_equal("This lineitem cannot be refunded.", e.message)
55
+ assert_equal("Lineitem amount greater than remaining balance on invoice.", e.message)
56
56
  end
57
57
  end
58
58
 
59
59
  #stop recurring lineitem
60
60
  it "Stopping a stopped recurring lineitem returns Twocheckout::TwocheckoutError" do
61
61
  begin
62
- sale = Twocheckout::Sale.find(:sale_id => 9093717691800)
62
+ sale = Twocheckout::Sale.find(:sale_id => 250192108517)
63
63
  result = sale.stop_recurring!
64
64
  assert_equal(result, [])
65
65
  rescue Twocheckout::TwocheckoutError => e
@@ -70,7 +70,7 @@ describe Twocheckout::Sale do
70
70
  #stop recurring sale
71
71
  it "Stopping a stopped recurring sale returns Twocheckout::TwocheckoutError" do
72
72
  begin
73
- sale = Twocheckout::Sale.find(:sale_id => 9093717691800)
73
+ sale = Twocheckout::Sale.find(:sale_id => 250192108517)
74
74
  last_invoice = sale.invoices.last
75
75
  last_lineitem = last_invoice.lineitems.last
76
76
  last_lineitem.stop_recurring!
@@ -81,7 +81,7 @@ describe Twocheckout::Sale do
81
81
 
82
82
  #create comment
83
83
  it "Creates a sale comment" do
84
- sale = Twocheckout::Sale.find(:sale_id => 9093717691800)
84
+ sale = Twocheckout::Sale.find(:sale_id => 250334624367)
85
85
  result = sale.comment({:sale_comment => "test"})
86
86
  assert_equal('Created comment successfully.', result['response_message'])
87
87
  end
@@ -89,22 +89,12 @@ describe Twocheckout::Sale do
89
89
  #mark shipped
90
90
  it "Shipping an intangible sale returns Twocheckout::TwocheckoutError" do
91
91
  begin
92
- sale = Twocheckout::Sale.find(:sale_id => 9093717691800)
92
+ sale = Twocheckout::Sale.find(:sale_id => 250335377097)
93
93
  sale.ship({:tracking_number => "123"})
94
94
  rescue Twocheckout::TwocheckoutError => e
95
95
  assert_equal("Sale already marked shipped.", e.message)
96
96
  end
97
97
  end
98
-
99
- #reauth
100
- it "Reauthorizing a pending sale returns Twocheckout::TwocheckoutError" do
101
- begin
102
- sale = Twocheckout::Sale.find(:sale_id => 9093717691800)
103
- sale.reauth
104
- rescue Twocheckout::TwocheckoutError => e
105
- assert_equal("Payment is already pending or deposited and cannot be reauthorized.", e.message)
106
- end
107
- end
108
98
  end
109
99
 
110
100
  #
@@ -136,60 +126,8 @@ describe Twocheckout::Product do
136
126
  end
137
127
  end
138
128
 
139
- describe Twocheckout::Option do
140
-
141
- # Option list
142
- it "Option list returns array of options" do
143
- option_list = Twocheckout::Option.list({ :pagesize => 3 })
144
- assert_equal(3, option_list.size)
145
- end
146
-
147
- # Option CRUD
148
- it "Option create, find, update, delete is successful" do
149
- # create
150
- new_option = Twocheckout::Option.create({:option_name => "test option",
151
- :option_value_name => "test option value", :option_value_surcharge => 1.00})
152
- assert_equal("test option", new_option.option_name)
153
- # find
154
- option = Twocheckout::Option.find({:option_id => new_option.option_id})
155
- assert_equal(new_option.option_id, option.option_id)
156
- # update
157
- option = option.update({:option_name => "new name"})
158
- assert_equal("new name", option.option_name)
159
- # delete
160
- result = option.delete!
161
- assert_equal("Option deleted successfully", result['response_message'])
162
- end
163
- end
164
-
165
- describe Twocheckout::Coupon do
166
-
167
- # Coupon list
168
- it "Coupon list returns array of coupons" do
169
- coupon_list = Twocheckout::Coupon.list({ :pagesize => 4 })
170
- assert_equal(4, coupon_list.size)
171
- end
172
-
173
- # Coupon CRUD
174
- it "Coupon create, find, update, delete is successful" do
175
- # create
176
- new_coupon = Twocheckout::Coupon.create({:date_expire => "2020-01-01",
177
- :type => "shipping", :minimum_purchase => 1.00})
178
- assert_equal("2020-01-01", new_coupon.date_expire)
179
- # find
180
- coupon = Twocheckout::Coupon.find({:coupon_code => new_coupon.coupon_code})
181
- assert_equal(new_coupon.coupon_code, coupon.coupon_code)
182
- # update
183
- coupon = coupon.update({:date_expire => "2020-01-02"})
184
- assert_equal("2020-01-02", coupon.date_expire)
185
- # delete
186
- result = coupon.delete!
187
- assert_equal("Coupon successfully deleted.", result['response_message'])
188
- end
189
- end
190
-
191
129
  describe Twocheckout::ValidateResponse do
192
- #demo
130
+
193
131
  it "Validates Purchase MD5 Hash" do
194
132
  result = Twocheckout::ValidateResponse.purchase({:sid => 1817037, :secret => "tango", :order_number => 1, :total => 0.01,
195
133
  :key => '1BC47EA0D63EB76496E294F434138AD3'})
@@ -215,7 +153,7 @@ describe Twocheckout::Checkout do
215
153
  #submit
216
154
  it "Submit return a form + JS to submit" do
217
155
  form = Twocheckout::Checkout.submit({ 'sid' => '1817037', 'cart_order_id' => 'Example Sale', 'total' => '1.00'})
218
- @form = "<form id=\"2checkout\" action=\"https://sandbox.2checkout.com/checkout/purchase\" method=\"post\">\n" +
156
+ @form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/purchase\" method=\"post\">\n" +
219
157
  "<input type=\"hidden\" name=\"sid\" value=\"1817037\" />\n" +
220
158
  "<input type=\"hidden\" name=\"cart_order_id\" value=\"Example Sale\" />\n" +
221
159
  "<input type=\"hidden\" name=\"total\" value=\"1.00\" />\n" +
@@ -227,7 +165,7 @@ describe Twocheckout::Checkout do
227
165
  #form
228
166
  it "Form returns a form" do
229
167
  form = Twocheckout::Checkout.form({ 'sid' => '1817037', 'cart_order_id' => 'Example Sale', 'total' => '1.00'}, "Proceed")
230
- @form = "<form id=\"2checkout\" action=\"https://sandbox.2checkout.com/checkout/purchase\" method=\"post\">\n" +
168
+ @form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/purchase\" method=\"post\">\n" +
231
169
  "<input type=\"hidden\" name=\"sid\" value=\"1817037\" />\n" +
232
170
  "<input type=\"hidden\" name=\"cart_order_id\" value=\"Example Sale\" />\n" +
233
171
  "<input type=\"hidden\" name=\"total\" value=\"1.00\" />\n" +
@@ -249,7 +187,7 @@ describe Twocheckout::Checkout do
249
187
  'country' => 'USA',
250
188
  'email' => 'no-reply@2co.com'
251
189
  })
252
- @form = "<form id=\"2checkout\" action=\"https://sandbox.2checkout.com/checkout/purchase\" method=\"post\">\n" +
190
+ @form = "<form id=\"2checkout\" action=\"https://www.2checkout.com/checkout/purchase\" method=\"post\">\n" +
253
191
  "<input type=\"hidden\" name=\"sid\" value=\"1817037\" />\n" +
254
192
  "<input type=\"hidden\" name=\"cart_order_id\" value=\"Example Sale\" />\n" +
255
193
  "<input type=\"hidden\" name=\"total\" value=\"1.00\" />\n" +
@@ -269,7 +207,7 @@ describe Twocheckout::Checkout do
269
207
  #link
270
208
  it "Link returns a link" do
271
209
  link = Twocheckout::Checkout.link({ 'sid' => '1817037', 'cart_order_id' => 'Example Sale', 'total' => '1.00'})
272
- @link = "https://sandbox.2checkout.com/checkout/purchase?sid=1817037&cart_order_id=Example+Sale&total=1.00"
210
+ @link = "https://www.2checkout.com/checkout/purchase?sid=1817037&cart_order_id=Example+Sale&total=1.00"
273
211
  assert_equal(link, @link)
274
212
  end
275
213
 
@@ -277,11 +215,12 @@ describe Twocheckout::Checkout do
277
215
  it "Authorize creates authorization" do
278
216
  params = {
279
217
  :merchantOrderId => '123',
280
- :token => 'MjQ3YTM2NDEtMmNiNC00ZGM3LTljZDItZjIxMzllYWE5ZmNl',
218
+ :token => 'OWM5OTAxM2YtNDhiMC00YjMyLTlkNDQtOWQ5MGRlOGExNDE0',
281
219
  :currency => 'USD',
282
220
  :total => '1.00',
221
+ :demo => true,
283
222
  :billingAddr => {
284
- :name => 'Testing Tester',
223
+ :name => 'John Doe',
285
224
  :addrLine1 => '123 Test St',
286
225
  :city => 'Columbus',
287
226
  :state => 'OH',
@@ -4,17 +4,17 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
4
4
  Gem::Specification.new do |s|
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.name = 'twocheckout'
7
- s.version = '0.4.0'
7
+ s.version = '0.5.0'
8
8
  s.summary = '2Checkout Ruby Library'
9
- s.description = '0.4.0'
9
+ s.description = '0.5.0'
10
10
  s.summary = '2Checkout Ruby Library'
11
- s.author = "Craig Christenson", "Ernesto Garcia"
12
- s.email = 'christensoncraig@gmail.com'
11
+ s.author = "Craig Christenson", "Ernesto Garcia", "Andrei Popa"
12
+ s.email = 'supportplus@2checkout.com'
13
13
  s.homepage = 'https://github.com/2Checkout/2checkout-ruby'
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.add_dependency('rest-client', '~> 1.4')
17
+ s.add_dependency('rest-client', '>= 1.4')
18
18
  s.require_paths = %w{lib}
19
19
  s.requirements << 'none'
20
20
  s.license = 'MIT'
metadata CHANGED
@@ -1,32 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twocheckout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Christenson
8
8
  - Ernesto Garcia
9
+ - Andrei Popa
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2015-03-19 00:00:00.000000000 Z
13
+ date: 2020-06-01 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rest-client
16
17
  requirement: !ruby/object:Gem::Requirement
17
18
  requirements:
18
- - - "~>"
19
+ - - ">="
19
20
  - !ruby/object:Gem::Version
20
21
  version: '1.4'
21
22
  type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
- - - "~>"
26
+ - - ">="
26
27
  - !ruby/object:Gem::Version
27
28
  version: '1.4'
28
- description: 0.4.0
29
- email: christensoncraig@gmail.com
29
+ description: 0.5.0
30
+ email: supportplus@2checkout.com
30
31
  executables: []
31
32
  extensions: []
32
33
  extra_rdoc_files: []
@@ -38,11 +39,9 @@ files:
38
39
  - lib/twocheckout/api.rb
39
40
  - lib/twocheckout/checkout.rb
40
41
  - lib/twocheckout/company.rb
41
- - lib/twocheckout/coupon.rb
42
42
  - lib/twocheckout/hash_object.rb
43
43
  - lib/twocheckout/invoice.rb
44
44
  - lib/twocheckout/lineitem.rb
45
- - lib/twocheckout/option.rb
46
45
  - lib/twocheckout/product.rb
47
46
  - lib/twocheckout/sale.rb
48
47
  - lib/twocheckout/twocheckout_error.rb
@@ -71,9 +70,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
70
  version: '0'
72
71
  requirements:
73
72
  - none
74
- rubyforge_project:
75
- rubygems_version: 2.4.3
73
+ rubygems_version: 3.0.3
76
74
  signing_key:
77
75
  specification_version: 4
78
76
  summary: 2Checkout Ruby Library
79
- test_files: []
77
+ test_files:
78
+ - test/minitest_helper.rb
79
+ - test/twocheckout_test.rb
@@ -1,41 +0,0 @@
1
- module Twocheckout
2
- class Coupon < HashObject
3
-
4
- def self.find(options)
5
- response = Twocheckout::API.request(:get, 'products/detail_coupon', options)
6
- Coupon.new(response['coupon'])
7
- end
8
-
9
- def self.with_coupon_code(coupon_code)
10
- find(:coupon_code => coupon_code)
11
- end
12
-
13
- def self.create(opts)
14
- response = Twocheckout::API.request(:post, 'products/create_coupon', opts)
15
- find(:coupon_code => response['coupon_code'])
16
- end
17
-
18
- def update(opts)
19
- opts = opts.merge(:coupon_code => self.coupon_code)
20
- Twocheckout::API.request(:post, 'products/update_coupon', opts)
21
- response = Twocheckout::API.request(:get, 'products/detail_coupon', opts)
22
- Coupon.new(response['coupon'])
23
- end
24
-
25
- def delete!
26
- opts = {:coupon_code => self.coupon_code}
27
- Twocheckout::API.request(:post, 'products/delete_coupon', opts)
28
- end
29
-
30
- def self.list(opts=nil)
31
- Twocheckout::API.request(:get, 'products/list_coupons', opts)
32
- end
33
-
34
- protected
35
-
36
- def _key
37
- self.coupon_code
38
- end
39
-
40
- end
41
- end
@@ -1,57 +0,0 @@
1
- module Twocheckout
2
- class Option < HashObject
3
-
4
- #
5
- # Finds option by ID and returns a Option object
6
- #
7
- def self.find(options)
8
- response = Twocheckout::API.request(:get, 'products/detail_option', options)
9
- Option.new(response['option'][0])
10
- end
11
-
12
- def self.with_option_id(option_id)
13
- find(:option_id => option_id)
14
- end
15
-
16
- #
17
- # Creates a new product option
18
- #
19
- def self.create(opts)
20
- response = Twocheckout::API.request(:post, 'products/create_option', opts)
21
- find(:option_id => response['option_id'])
22
- end
23
-
24
- #
25
- # Updates option and returns a new object
26
- #
27
- def update(opts)
28
- opts = opts.merge(:option_id => self.option_id)
29
- Twocheckout::API.request(:post, 'products/update_option', opts)
30
- response = Twocheckout::API.request(:get, 'products/detail_option', opts)
31
- Option.new(response['option'][0])
32
- end
33
-
34
- #
35
- # Deletes the option and returns the response
36
- #
37
- def delete!
38
- opts = {:option_id => self.option_id}
39
- Twocheckout::API.request(:post, 'products/delete_option', opts)
40
- end
41
-
42
- #
43
- # An array to index options list
44
- #
45
- def self.list(opts=nil)
46
- response = Twocheckout::API.request(:get, 'products/list_options', opts)
47
- response['options']
48
- end
49
-
50
- protected
51
-
52
- def _key
53
- self.option_id
54
- end
55
-
56
- end
57
- end