Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle v1 and v2 api version #225

Merged
merged 11 commits into from
Oct 13, 2023
2 changes: 1 addition & 1 deletion lib/razorpay/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def self.create(subscription_id, options)
# POST /addons is not supported
# Addon creation endpoint is:
# POST subscriptions/{sub_id}/addons
r.request :post, "/subscriptions/#{subscription_id}/addons", options
r.request :post, "/v1/subscriptions/#{subscription_id}/addons", options
end

def self.delete(id)
Expand Down
2 changes: 1 addition & 1 deletion lib/razorpay/constants.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Version and other constants are defined here
module Razorpay
BASE_URI = 'https://api.razorpay.com/v1/'.freeze
BASE_URI = 'https://api.razorpay.com'.freeze
TEST_URL = 'https://api.razorpay.com/'.freeze
VERSION = '3.0.1'.freeze
end
2 changes: 1 addition & 1 deletion lib/razorpay/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.all(options = {})

def payments(options = {})
r = self.class.request
r.request :get, "/orders/#{id}/payments", options
r.request :get, "/v1/orders/#{id}/payments", options
end

def self.edit(id, options = {})
Expand Down
32 changes: 16 additions & 16 deletions lib/razorpay/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,36 @@ def initialize(entity_name = nil)
}
end

def fetch(id)
request :get, "/#{@entity_name}/#{id}"
def fetch(id, version="v1")
request :get, "/#{version}/#{@entity_name}/#{id}"
end

def all(options)
request :get, "/#{@entity_name}", options
def all(options, version="v1")
request :get, "/#{version}/#{@entity_name}", options
end

def post(url, data = {})
request :post, "/#{@entity_name}/#{url}", data
def post(url, data = {}, version="v1")
request :post, "/#{version}/#{@entity_name}/#{url}", data
end

def get(url, data = {})
request :get, "/#{@entity_name}/#{url}", data
def get(url, data = {}, version="v1")
request :get, "/#{version}/#{@entity_name}/#{url}", data
end

def delete(url)
request :delete, "/#{@entity_name}/#{url}"
def delete(url, version="v1")
request :delete, "/#{version}/#{@entity_name}/#{url}"
end

def put(id, data = {})
request :put, "/#{@entity_name}/#{id}", data
def put(id, data = {}, version="v1")
request :put, "/#{version}/#{@entity_name}/#{id}", data
end

def patch(id, data = {})
request :patch, "/#{@entity_name}/#{id}", data
def patch(id, data = {}, version="v1")
request :patch, "/#{version}/#{@entity_name}/#{id}", data
end

def create(data)
request :post, "/#{@entity_name}", data
def create(data, version="v1")
request :post, "/#{version}/#{@entity_name}", data
end

def request(method, url, data = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/razorpay/virtual_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def close!

def payments(options = {})
r = self.class.request
r.request :get, "/virtual_accounts/#{id}/payments", options
r.request :get, "/v1/virtual_accounts/#{id}/payments", options
end

def self.add_receiver(id, options = {})
Expand Down
1 change: 1 addition & 0 deletions razorpay-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
# rubocop is only run in the latest ruby build
# so we use the latest version and don't switch to a
# older version for 1.9.3
spec.add_development_dependency 'simplecov-cobertura'
spec.add_development_dependency 'rubocop', '~> 0.49'
spec.add_development_dependency 'webmock', '~> 3.0'
else
Expand Down
2 changes: 1 addition & 1 deletion test/razorpay/test_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_edit_order
end

def test_fetch_order_transfers
stub_get("#{BASE_URI}orders/#{@order_id}/?expand[]=transfers&status", 'fake_order_transfers')
stub_get("#{BASE_URI}/v1/orders/#{@order_id}/?expand[]=transfers&status", 'fake_order_transfers')
order = Razorpay::Order.fetch_transfer_order(@order_id)
assert_instance_of Razorpay::Order, order, 'order not an instance of Razorpay::Order class'
assert_equal @order_id, order.id, 'order IDs do not match'
Expand Down
2 changes: 1 addition & 1 deletion test/razorpay/test_settlement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_settlement_reports
"year": 2022,
"month":12
}
stub_get("#{BASE_URI}settlements/recon/combined?month=12&year=2022", 'settlement_report_collection')
stub_get("#{BASE_URI}/v1/settlements/recon/combined?month=12&year=2022", 'settlement_report_collection')
settlement = Razorpay::Settlement.reports(para_attr)
assert_instance_of Razorpay::Collection, settlement, 'Settlement not an instance of Settlement class'
refute_empty settlement.items, 'Settlement should be more than one'
Expand Down
2 changes: 1 addition & 1 deletion test/razorpay/test_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_transfer_fetch
end

def test_transfer_fetch_settlement_details
stub_get("#{BASE_URI}transfers/?expand[]=recipient_settlement", 'transfers_collection')
stub_get("#{BASE_URI}/v1/transfers/?expand[]=recipient_settlement", 'transfers_collection')
transfer = Razorpay::Transfer.fetch_settlements
assert_instance_of Razorpay::Collection, transfer , 'Transfer should be an array'
refute_empty transfer.items , 'Transfer should be more than one'
Expand Down
Loading