From 57dadad169fd920c6510f390c61b3150c87dd7d3 Mon Sep 17 00:00:00 2001 From: Andrei Popa Date: Thu, 16 Apr 2020 08:23:50 +0300 Subject: [PATCH 1/3] Removed redundant code - tests not yet updated --- lib/twocheckout.rb | 2 -- lib/twocheckout/api.rb | 4 +-- lib/twocheckout/checkout.rb | 4 --- lib/twocheckout/coupon.rb | 41 -------------------------- lib/twocheckout/option.rb | 57 ------------------------------------- lib/twocheckout/sale.rb | 7 ----- test/minitest_helper.rb | 5 +--- test/twocheckout_test.rb | 18 +++--------- 8 files changed, 6 insertions(+), 132 deletions(-) delete mode 100644 lib/twocheckout/coupon.rb delete mode 100644 lib/twocheckout/option.rb diff --git a/lib/twocheckout.rb b/lib/twocheckout.rb index a7ea2fe..558714f 100644 --- a/lib/twocheckout.rb +++ b/lib/twocheckout.rb @@ -6,8 +6,6 @@ require "twocheckout/lineitem" require "twocheckout/invoice" require "twocheckout/sale" -require "twocheckout/coupon" require "twocheckout/product" -require "twocheckout/option" require "twocheckout/checkout" require "twocheckout/twocheckout_error" diff --git a/lib/twocheckout/api.rb b/lib/twocheckout/api.rb index 9b5fbc9..78fab76 100755 --- a/lib/twocheckout/api.rb +++ b/lib/twocheckout/api.rb @@ -4,7 +4,6 @@ module Twocheckout class API PROD_BASE = 'https://www.2checkout.com' - SANDBOX_BASE = 'https://sandbox.2checkout.com' API_VERSION = '1' def self.credentials=(opts) @@ -12,7 +11,6 @@ def self.credentials=(opts) @password = opts[:password] @private_key = opts[:private_key] @seller_id = opts[:seller_id] - @sandbox = opts[:sandbox] end def self.request(http_method, api_call, params = nil) @@ -33,7 +31,7 @@ def self.request(http_method, api_call, params = nil) private def self.set_opts(http_method, api_call, params = null) - url = @sandbox ? SANDBOX_BASE : PROD_BASE + url = PROD_BASE if api_call == 'authService' url += '/checkout/api/' + API_VERSION + '/' + @seller_id + '/rs/' + api_call params['sellerId'] = @seller_id diff --git a/lib/twocheckout/checkout.rb b/lib/twocheckout/checkout.rb index 3f5421a..b2592d8 100755 --- a/lib/twocheckout/checkout.rb +++ b/lib/twocheckout/checkout.rb @@ -3,10 +3,6 @@ class Checkout < HashObject @checkout_url = 'https://www.2checkout.com/checkout/purchase' - def self.sandbox(sandbox) - @checkout_url = sandbox ? 'https://sandbox.2checkout.com/checkout/purchase' : @checkout_url; - end - def self.form(params={}, button_text='Proceed to Checkout') @form = "
\n"; params.each do |k,v| diff --git a/lib/twocheckout/coupon.rb b/lib/twocheckout/coupon.rb deleted file mode 100644 index 3ee27f9..0000000 --- a/lib/twocheckout/coupon.rb +++ /dev/null @@ -1,41 +0,0 @@ -module Twocheckout - class Coupon < HashObject - - def self.find(options) - response = Twocheckout::API.request(:get, 'products/detail_coupon', options) - Coupon.new(response['coupon']) - end - - def self.with_coupon_code(coupon_code) - find(:coupon_code => coupon_code) - end - - def self.create(opts) - response = Twocheckout::API.request(:post, 'products/create_coupon', opts) - find(:coupon_code => response['coupon_code']) - end - - def update(opts) - opts = opts.merge(:coupon_code => self.coupon_code) - Twocheckout::API.request(:post, 'products/update_coupon', opts) - response = Twocheckout::API.request(:get, 'products/detail_coupon', opts) - Coupon.new(response['coupon']) - end - - def delete! - opts = {:coupon_code => self.coupon_code} - Twocheckout::API.request(:post, 'products/delete_coupon', opts) - end - - def self.list(opts=nil) - Twocheckout::API.request(:get, 'products/list_coupons', opts) - end - - protected - - def _key - self.coupon_code - end - - end -end diff --git a/lib/twocheckout/option.rb b/lib/twocheckout/option.rb deleted file mode 100644 index c271216..0000000 --- a/lib/twocheckout/option.rb +++ /dev/null @@ -1,57 +0,0 @@ -module Twocheckout - class Option < HashObject - - # - # Finds option by ID and returns a Option object - # - def self.find(options) - response = Twocheckout::API.request(:get, 'products/detail_option', options) - Option.new(response['option'][0]) - end - - def self.with_option_id(option_id) - find(:option_id => option_id) - end - - # - # Creates a new product option - # - def self.create(opts) - response = Twocheckout::API.request(:post, 'products/create_option', opts) - find(:option_id => response['option_id']) - end - - # - # Updates option and returns a new object - # - def update(opts) - opts = opts.merge(:option_id => self.option_id) - Twocheckout::API.request(:post, 'products/update_option', opts) - response = Twocheckout::API.request(:get, 'products/detail_option', opts) - Option.new(response['option'][0]) - end - - # - # Deletes the option and returns the response - # - def delete! - opts = {:option_id => self.option_id} - Twocheckout::API.request(:post, 'products/delete_option', opts) - end - - # - # An array to index options list - # - def self.list(opts=nil) - response = Twocheckout::API.request(:get, 'products/list_options', opts) - response['options'] - end - - protected - - def _key - self.option_id - end - - end -end diff --git a/lib/twocheckout/sale.rb b/lib/twocheckout/sale.rb index 28ad051..9468560 100644 --- a/lib/twocheckout/sale.rb +++ b/lib/twocheckout/sale.rb @@ -75,13 +75,6 @@ def ship(opts) Twocheckout::API.request(:post, 'sales/mark_shipped', opts) end - # - # Reauthorize sale - # - def reauth - Twocheckout::API.request(:post, 'sales/reauth', sale_id: self.sale_id) - end - # # Get sale list in an array # diff --git a/test/minitest_helper.rb b/test/minitest_helper.rb index f090284..a9db860 100755 --- a/test/minitest_helper.rb +++ b/test/minitest_helper.rb @@ -6,7 +6,4 @@ :password => 'testlibraryapi901248204PASS', :seller_id => '901248204', :private_key => 'BE632CB0-BB29-11E3-AFB6-D99C28100996', - :sandbox => true -} - -Twocheckout::Checkout.sandbox(true); \ No newline at end of file +} \ No newline at end of file diff --git a/test/twocheckout_test.rb b/test/twocheckout_test.rb index 76d4d1b..f2d01d9 100755 --- a/test/twocheckout_test.rb +++ b/test/twocheckout_test.rb @@ -95,16 +95,6 @@ assert_equal("Sale already marked shipped.", e.message) end end - - #reauth - it "Reauthorizing a pending sale returns Twocheckout::TwocheckoutError" do - begin - sale = Twocheckout::Sale.find(:sale_id => 9093717691800) - sale.reauth - rescue Twocheckout::TwocheckoutError => e - assert_equal("Payment is already pending or deposited and cannot be reauthorized.", e.message) - end - end end # @@ -215,7 +205,7 @@ #submit it "Submit return a form + JS to submit" do form = Twocheckout::Checkout.submit({ 'sid' => '1817037', 'cart_order_id' => 'Example Sale', 'total' => '1.00'}) - @form = "\n" + + @form = "\n" + "\n" + "\n" + "\n" + @@ -227,7 +217,7 @@ #form it "Form returns a form" do form = Twocheckout::Checkout.form({ 'sid' => '1817037', 'cart_order_id' => 'Example Sale', 'total' => '1.00'}, "Proceed") - @form = "\n" + + @form = "\n" + "\n" + "\n" + "\n" + @@ -249,7 +239,7 @@ 'country' => 'USA', 'email' => 'no-reply@2co.com' }) - @form = "\n" + + @form = "\n" + "\n" + "\n" + "\n" + @@ -269,7 +259,7 @@ #link it "Link returns a link" do link = Twocheckout::Checkout.link({ 'sid' => '1817037', 'cart_order_id' => 'Example Sale', 'total' => '1.00'}) - @link = "https://sandbox.2checkout.com/checkout/purchase?sid=1817037&cart_order_id=Example+Sale&total=1.00" + @link = "https://www.2checkout.com/checkout/purchase?sid=1817037&cart_order_id=Example+Sale&total=1.00" assert_equal(link, @link) end From c345f782861f7bae1663f162f3b3449f0949dc27 Mon Sep 17 00:00:00 2001 From: Andrei Popa Date: Thu, 16 Apr 2020 14:53:48 +0300 Subject: [PATCH 2/3] Fixed tests && removed redundant code --- lib/twocheckout.rb | 22 +++++----- lib/twocheckout/api.rb | 4 +- lib/twocheckout/version.rb | 2 +- test/minitest_helper.rb | 8 ++-- test/twocheckout_test.rb | 87 ++++++++------------------------------ twocheckout.gemspec | 10 ++--- 6 files changed, 41 insertions(+), 92 deletions(-) diff --git a/lib/twocheckout.rb b/lib/twocheckout.rb index 558714f..e106665 100644 --- a/lib/twocheckout.rb +++ b/lib/twocheckout.rb @@ -1,11 +1,11 @@ -require "twocheckout/version" -require "twocheckout/api" -require "twocheckout/hash_object" -require "twocheckout/validate_response" -require "twocheckout/company" -require "twocheckout/lineitem" -require "twocheckout/invoice" -require "twocheckout/sale" -require "twocheckout/product" -require "twocheckout/checkout" -require "twocheckout/twocheckout_error" +require 'twocheckout/version' +require 'twocheckout/api' +require 'twocheckout/hash_object' +require 'twocheckout/validate_response' +require 'twocheckout/company' +require 'twocheckout/lineitem' +require 'twocheckout/invoice' +require 'twocheckout/sale' +require 'twocheckout/product' +require 'twocheckout/checkout' +require 'twocheckout/twocheckout_error' diff --git a/lib/twocheckout/api.rb b/lib/twocheckout/api.rb index 78fab76..051ef65 100755 --- a/lib/twocheckout/api.rb +++ b/lib/twocheckout/api.rb @@ -3,8 +3,8 @@ module Twocheckout class API - PROD_BASE = 'https://www.2checkout.com' - API_VERSION = '1' + PROD_BASE = 'https://www.2checkout.com'.freeze + API_VERSION = '1'.freeze def self.credentials=(opts) @username = opts[:username] diff --git a/lib/twocheckout/version.rb b/lib/twocheckout/version.rb index f725594..eb00ebf 100755 --- a/lib/twocheckout/version.rb +++ b/lib/twocheckout/version.rb @@ -1,3 +1,3 @@ module Twocheckout - VERSION = "0.4.0" + VERSION = '0.4.0'.freeze end diff --git a/test/minitest_helper.rb b/test/minitest_helper.rb index a9db860..1e8e2f5 100755 --- a/test/minitest_helper.rb +++ b/test/minitest_helper.rb @@ -2,8 +2,8 @@ require "twocheckout" Twocheckout::API.credentials = { - :username => 'testlibraryapi901248204', - :password => 'testlibraryapi901248204PASS', - :seller_id => '901248204', - :private_key => 'BE632CB0-BB29-11E3-AFB6-D99C28100996', + :username => 'test_api_250111206876', + :password => 'Qwerty123', + :seller_id => '250111206876', + :private_key => '1D336D05-05AA-40A4-AEF6-DF58D222E6F4', } \ No newline at end of file diff --git a/test/twocheckout_test.rb b/test/twocheckout_test.rb index f2d01d9..3681a4f 100755 --- a/test/twocheckout_test.rb +++ b/test/twocheckout_test.rb @@ -7,14 +7,14 @@ #retrieve sale it "Sale retrieve returns sale" do - sale = Twocheckout::Sale.find(:sale_id => 9093717691800) - assert_equal('9093717691800', sale.sale_id) + sale = Twocheckout::Sale.find(:sale_id => 250335346812) + assert_equal('250335346812', sale.sale_id) end #retrieve invoice it "Sale retrieve returns invoice" do - invoice = Twocheckout::Sale.find({:invoice_id => 9093717691821}) - assert_equal('9093717691821', invoice.invoice_id) + invoice = Twocheckout::Sale.find({:invoice_id => 250334725631}) + assert_equal('250334725631', invoice.invoice_id) end #retrieve sale list @@ -26,40 +26,40 @@ #refund sale it "Refunding a refunded sale returns Twocheckout::TwocheckoutError" do begin - sale = Twocheckout::Sale.find(:sale_id => 9093717691800) + sale = Twocheckout::Sale.find(:sale_id => 250335365202) sale.refund!({:comment => "test refund", :category => 1}) rescue Twocheckout::TwocheckoutError => e - assert_equal("Invoice was already refunded.", e.message) + assert_equal("Amount greater than remaining balance on invoice.", e.message) end end #refund invoice it "Refunding a refunded invoice returns Twocheckout::TwocheckoutError" do begin - sale = Twocheckout::Sale.find(:sale_id => 9093717691800) + sale = Twocheckout::Sale.find(:sale_id => 250335365202) invoice = sale.invoices.first invoice.refund!({:comment => "test refund", :category => 1}) rescue Twocheckout::TwocheckoutError => e - assert_equal("Invoice was already refunded.", e.message) + assert_equal("Amount greater than remaining balance on invoice.", e.message) end end #refund lineitem it "Refunding a refunded lineitem returns Twocheckout::TwocheckoutError" do begin - sale = Twocheckout::Sale.find(:sale_id => 9093717691800) + sale = Twocheckout::Sale.find(:sale_id => 250192108517) first_invoice = sale.invoices.first last_lineitem = first_invoice.lineitems.last last_lineitem.refund!({:comment => "test refund", :category => 1}) rescue Twocheckout::TwocheckoutError => e - assert_equal("This lineitem cannot be refunded.", e.message) + assert_equal("Lineitem amount greater than remaining balance on invoice.", e.message) end end #stop recurring lineitem it "Stopping a stopped recurring lineitem returns Twocheckout::TwocheckoutError" do begin - sale = Twocheckout::Sale.find(:sale_id => 9093717691800) + sale = Twocheckout::Sale.find(:sale_id => 250192108517) result = sale.stop_recurring! assert_equal(result, []) rescue Twocheckout::TwocheckoutError => e @@ -70,7 +70,7 @@ #stop recurring sale it "Stopping a stopped recurring sale returns Twocheckout::TwocheckoutError" do begin - sale = Twocheckout::Sale.find(:sale_id => 9093717691800) + sale = Twocheckout::Sale.find(:sale_id => 250192108517) last_invoice = sale.invoices.last last_lineitem = last_invoice.lineitems.last last_lineitem.stop_recurring! @@ -81,7 +81,7 @@ #create comment it "Creates a sale comment" do - sale = Twocheckout::Sale.find(:sale_id => 9093717691800) + sale = Twocheckout::Sale.find(:sale_id => 250334624367) result = sale.comment({:sale_comment => "test"}) assert_equal('Created comment successfully.', result['response_message']) end @@ -89,7 +89,7 @@ #mark shipped it "Shipping an intangible sale returns Twocheckout::TwocheckoutError" do begin - sale = Twocheckout::Sale.find(:sale_id => 9093717691800) + sale = Twocheckout::Sale.find(:sale_id => 250335377097) sale.ship({:tracking_number => "123"}) rescue Twocheckout::TwocheckoutError => e assert_equal("Sale already marked shipped.", e.message) @@ -126,60 +126,8 @@ end end -describe Twocheckout::Option do - - # Option list - it "Option list returns array of options" do - option_list = Twocheckout::Option.list({ :pagesize => 3 }) - assert_equal(3, option_list.size) - end - - # Option CRUD - it "Option create, find, update, delete is successful" do - # create - new_option = Twocheckout::Option.create({:option_name => "test option", - :option_value_name => "test option value", :option_value_surcharge => 1.00}) - assert_equal("test option", new_option.option_name) - # find - option = Twocheckout::Option.find({:option_id => new_option.option_id}) - assert_equal(new_option.option_id, option.option_id) - # update - option = option.update({:option_name => "new name"}) - assert_equal("new name", option.option_name) - # delete - result = option.delete! - assert_equal("Option deleted successfully", result['response_message']) - end -end - -describe Twocheckout::Coupon do - - # Coupon list - it "Coupon list returns array of coupons" do - coupon_list = Twocheckout::Coupon.list({ :pagesize => 4 }) - assert_equal(4, coupon_list.size) - end - - # Coupon CRUD - it "Coupon create, find, update, delete is successful" do - # create - new_coupon = Twocheckout::Coupon.create({:date_expire => "2020-01-01", - :type => "shipping", :minimum_purchase => 1.00}) - assert_equal("2020-01-01", new_coupon.date_expire) - # find - coupon = Twocheckout::Coupon.find({:coupon_code => new_coupon.coupon_code}) - assert_equal(new_coupon.coupon_code, coupon.coupon_code) - # update - coupon = coupon.update({:date_expire => "2020-01-02"}) - assert_equal("2020-01-02", coupon.date_expire) - # delete - result = coupon.delete! - assert_equal("Coupon successfully deleted.", result['response_message']) - end -end - describe Twocheckout::ValidateResponse do - #demo + it "Validates Purchase MD5 Hash" do result = Twocheckout::ValidateResponse.purchase({:sid => 1817037, :secret => "tango", :order_number => 1, :total => 0.01, :key => '1BC47EA0D63EB76496E294F434138AD3'}) @@ -267,11 +215,12 @@ it "Authorize creates authorization" do params = { :merchantOrderId => '123', - :token => 'MjQ3YTM2NDEtMmNiNC00ZGM3LTljZDItZjIxMzllYWE5ZmNl', + :token => 'OWM5OTAxM2YtNDhiMC00YjMyLTlkNDQtOWQ5MGRlOGExNDE0', :currency => 'USD', :total => '1.00', + :demo => true, :billingAddr => { - :name => 'Testing Tester', + :name => 'John Doe', :addrLine1 => '123 Test St', :city => 'Columbus', :state => 'OH', diff --git a/twocheckout.gemspec b/twocheckout.gemspec index 02a2890..55217fb 100755 --- a/twocheckout.gemspec +++ b/twocheckout.gemspec @@ -4,17 +4,17 @@ $:.unshift(File.join(File.dirname(__FILE__), 'lib')) Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = 'twocheckout' - s.version = '0.4.0' + s.version = '0.5.0' s.summary = '2Checkout Ruby Library' - s.description = '0.4.0' + s.description = '0.5.0' s.summary = '2Checkout Ruby Library' - s.author = "Craig Christenson", "Ernesto Garcia" - s.email = 'christensoncraig@gmail.com' + s.author = "Craig Christenson", "Ernesto Garcia", "Andrei Popa" + s.email = 'supportplus@2checkout.com' s.homepage = 'https://github.com/2Checkout/2checkout-ruby' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.add_dependency('rest-client', '~> 1.4') + s.add_dependency('rest-client', '>= 1.4') s.require_paths = %w{lib} s.requirements << 'none' s.license = 'MIT' From 67216dd29f449fdfe38ca36082ec555859d272da Mon Sep 17 00:00:00 2001 From: Andrei Popa Date: Tue, 21 Apr 2020 13:30:41 +0300 Subject: [PATCH 3/3] Bumped version --- lib/twocheckout/version.rb | 2 +- test/minitest_helper.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/twocheckout/version.rb b/lib/twocheckout/version.rb index eb00ebf..d7d36bb 100755 --- a/lib/twocheckout/version.rb +++ b/lib/twocheckout/version.rb @@ -1,3 +1,3 @@ module Twocheckout - VERSION = '0.4.0'.freeze + VERSION = '0.5.0'.freeze end diff --git a/test/minitest_helper.rb b/test/minitest_helper.rb index 1e8e2f5..498d303 100755 --- a/test/minitest_helper.rb +++ b/test/minitest_helper.rb @@ -2,8 +2,8 @@ require "twocheckout" Twocheckout::API.credentials = { - :username => 'test_api_250111206876', - :password => 'Qwerty123', - :seller_id => '250111206876', - :private_key => '1D336D05-05AA-40A4-AEF6-DF58D222E6F4', + :username => 'CREDENTIALS HERE', + :password => 'CREDENTIALS HERE', + :seller_id => 'CREDENTIALS HERE', + :private_key => 'CREDENTIALS HERE', } \ No newline at end of file