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

[GOLF-12242] adds externalPaymentProvider resource endpoints #38

Merged
merged 8 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/lightspeed_restaurant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'lightspeed_restaurant/customer_establishment_order'
require 'lightspeed_restaurant/customer_loyalty_card'
require 'lightspeed_restaurant/customer'
require 'lightspeed_restaurant/external_payment_provider'
lindseytruong marked this conversation as resolved.
Show resolved Hide resolved
require 'lightspeed_restaurant/inventory_product'
require 'lightspeed_restaurant/payment_type'
require 'lightspeed_restaurant/product_group_product'
Expand Down
22 changes: 22 additions & 0 deletions lib/lightspeed_restaurant/external_payment_provider.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'lightspeed_restaurant/base'
require 'lightspeed_restaurant/operations/list'
require 'lightspeed_restaurant/operations/find'
require 'lightspeed_restaurant/operations/create'

module LightspeedRestaurantClient
class ExternalPaymentProvider < LightspeedRestaurantClient::Base
extend Operations::Create
extend Operations::Find
extend Operations::List

def self.resource_name
'externalPaymentProvider'
olimart marked this conversation as resolved.
Show resolved Hide resolved
end

def self.default_resource_path
"/rest/partner/v1/#{resource_name}/"
end
end
end
5 changes: 3 additions & 2 deletions lib/lightspeed_restaurant/operations/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def create(attributes, configuration = nil)
private

def handle_create_response(response, attributes)
case response
when Numeric
if response.is_a?(Numeric)
attributes.merge(id: response)
elsif self == LightspeedRestaurantClient::ExternalPaymentProvider
response.merge(id: response['data']['id'])
else
response
end
Expand Down
10 changes: 9 additions & 1 deletion lib/lightspeed_restaurant/operations/find.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ module LightspeedRestaurantClient
module Operations
module Find
def find(id, configuration = nil)
response = JSON.parse(LightspeedRestaurantClient.get(default_resource_path + "/#{id}", {}, configuration))
response = JSON.parse(LightspeedRestaurantClient.get(default_resource_path + id_path(id), {}, configuration))
new(response)
end

private

def id_path(id)
return id.to_s if self == LightspeedRestaurantClient::ExternalPaymentProvider

"/#{id}"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/lightspeed_restaurant/operations/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def resource_path
def handle_list_response(response)
case response
when Hash
response['results']
self == LightspeedRestaurantClient::ExternalPaymentProvider ? response['data'] : response['results']
else
response
end
Expand Down
31 changes: 31 additions & 0 deletions spec/fixtures/vcr_cassettes/externalPaymentProvider/create.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions spec/fixtures/vcr_cassettes/externalPaymentProvider/find.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions spec/fixtures/vcr_cassettes/externalPaymentProvider/list.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions spec/lightspeed_restaurant/external_payment_provider_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# frozen_string_literal: true

require 'spec_helper'

module LightspeedRestaurantClient
describe ExternalPaymentProvider do
setup_api_token

let(:resource_name) { 'externalPaymentProvider' }
let(:fake_logger) { FakeLogger.new }

before { LightspeedRestaurantClient.logger = fake_logger }

context 'when listing' do
it_behaves_like 'a list operation' do
let(:results_count) { 1 }
end
end

context 'when finding' do
it_behaves_like 'a find operation' do
let(:resource_id) { 1 }

it 'includes external payment providers' do
result = described_class.find(resource_id)
expect(result.data).to eq({
'companyID' => 1,
'creationDate' => '2024-11-17:28:02.467Z',
'id' => 1,
'name' => 'House Account (External)',
'updateDate' => '2024-11-17:28:02.467Z',
'url' => 'https://dummy-payment-url.com'
})
end
end
end

context 'when creating' do
let(:valid_params) do
{
companyId: 123,
name: 'House Account (External)',
url: 'https://dummy-payment-url.com',
username: 'username',
password: 'abc123'
}
end

it_behaves_like 'a create operation' do
let(:invalid_params) { { companyId: '' } }
end

context 'when the creation is successful' do
around do |test|
VCR.use_cassette("#{resource_name}/create", allow_playback_repeats: true) { test.run }
end

it 'returns the external payment provider id' do
resource = described_class.create(valid_params)
expect(resource.id).to eq 1
end
end
end
end
end