From b174e276afe28e28ed47cca0ee95580d01d2f893 Mon Sep 17 00:00:00 2001 From: Mihai Moiseanu Date: Thu, 29 Feb 2024 16:43:36 +0200 Subject: [PATCH] added quote endpoints rename InstantConversion to Conversions --- lib/mangopay.rb | 2 +- .../{instant_conversion.rb => conversion.rb} | 12 ++++- spec/mangopay/conversion_spec.rb | 52 +++++++++++++++++++ spec/mangopay/instant_conversion_spec.rb | 33 ------------ spec/mangopay/shared_resources.rb | 23 ++++++-- 5 files changed, 82 insertions(+), 40 deletions(-) rename lib/mangopay/{instant_conversion.rb => conversion.rb} (65%) create mode 100644 spec/mangopay/conversion_spec.rb delete mode 100644 spec/mangopay/instant_conversion_spec.rb diff --git a/lib/mangopay.rb b/lib/mangopay.rb index 337e7af..4e3cc22 100644 --- a/lib/mangopay.rb +++ b/lib/mangopay.rb @@ -44,7 +44,7 @@ module MangoPay autoload :Ubo, 'mangopay/ubo' autoload :Regulatory, 'mangopay/regulatory' autoload :Deposit, 'mangopay/deposit' - autoload :InstantConversion, 'mangopay/instant_conversion' + autoload :Conversion, 'mangopay/conversion' autoload :PaymentMethodMetadata, 'mangopay/payment_method_metadata' # temporary diff --git a/lib/mangopay/instant_conversion.rb b/lib/mangopay/conversion.rb similarity index 65% rename from lib/mangopay/instant_conversion.rb rename to lib/mangopay/conversion.rb index a437059..7e53807 100644 --- a/lib/mangopay/instant_conversion.rb +++ b/lib/mangopay/conversion.rb @@ -1,6 +1,6 @@ module MangoPay - class InstantConversion < Resource + class Conversion < Resource include HTTPCalls::Fetch include HTTPCalls::Update @@ -19,6 +19,16 @@ def get(id, params) url = "#{MangoPay.api_path}/instant-conversion/#{id}" MangoPay.request(:get, url, params) end + + def create_quote(params) + url = "#{MangoPay.api_path}/conversions/quote" + MangoPay.request(:post, url, params) + end + + def get_quote(id, params) + url = "#{MangoPay.api_path}/conversions/quote/#{id}" + MangoPay.request(:get, url, params) + end end end end \ No newline at end of file diff --git a/spec/mangopay/conversion_spec.rb b/spec/mangopay/conversion_spec.rb new file mode 100644 index 0000000..a9518d2 --- /dev/null +++ b/spec/mangopay/conversion_spec.rb @@ -0,0 +1,52 @@ +describe MangoPay::Conversion, type: :feature do + include_context 'instant_conversion' + + describe 'GET CONVERSION RATE' do + it 'get a conversion rate' do + conversion_rate = get_conversion_rate('EUR','GBP') + + expect(conversion_rate['ClientRate']).not_to be_nil + expect(conversion_rate['MarketRate']).not_to be_nil + end + end + + describe 'CREATE CONVERSION' do + it 'creates a new conversion' do + conversion = create_conversion + + expect(conversion['DebitedFunds']['Amount']).not_to be_nil + expect(conversion['CreditedFunds']['Amount']).not_to be_nil + expect(conversion['Status']).equal? 'SUCCEEDED' + end + end + + describe 'GET EXISTING CONVERSION' do + it 'get an existing conversion' do + conversion = create_conversion + returned_conversion = get_conversion(conversion['Id']) + + expect(returned_conversion['DebitedFunds']['Amount']).not_to be_nil + expect(returned_conversion['CreditedFunds']['Amount']).not_to be_nil + expect(returned_conversion['Status']).equal? 'SUCCEEDED' + end + end + + describe 'CREATE CONVERSION QUOTE' do + it 'create a conversion quote' do + conversion_quote = create_conversion_quote + expect(conversion_quote['DebitedFunds']).not_to be_nil + expect(conversion_quote['CreditedFunds']).not_to be_nil + expect(conversion_quote['Duration']).equal? 90 + end + end + + describe 'GET CONVERSION QUOTE' do + it 'get a conversion quote' do + conversion_quote = create_conversion_quote + returned_conversion_quote = get_conversion_quote(conversion_quote['Id']) + expect(returned_conversion_quote['DebitedFunds']).not_to be_nil + expect(returned_conversion_quote['CreditedFunds']).not_to be_nil + expect(returned_conversion_quote['Duration']).equal? 90 + end + end +end \ No newline at end of file diff --git a/spec/mangopay/instant_conversion_spec.rb b/spec/mangopay/instant_conversion_spec.rb deleted file mode 100644 index 0daf2f2..0000000 --- a/spec/mangopay/instant_conversion_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -describe MangoPay::InstantConversion, type: :feature do - include_context 'instant_conversion' - - describe 'GET CONVERSION RATE' do - it 'get a conversion rate' do - conversion_rate = get_conversion_rate('EUR','GBP') - - expect(conversion_rate['ClientRate']).not_to be_nil - expect(conversion_rate['MarketRate']).not_to be_nil - end - end - - describe 'CREATE CONVERSION' do - it 'creates a new conversion' do - conversion = create_instant_conversion - - expect(conversion['DebitedFunds']['Amount']).not_to be_nil - expect(conversion['CreditedFunds']['Amount']).not_to be_nil - expect(conversion['Status']).equal? 'SUCCEEDED' - end - end - - describe 'GET EXISTING CONVERSION' do - it 'get an existing conversion' do - conversion = create_instant_conversion - returned_conversion = get_instant_conversion(conversion['Id']) - - expect(returned_conversion['DebitedFunds']['Amount']).not_to be_nil - expect(returned_conversion['CreditedFunds']['Amount']).not_to be_nil - expect(returned_conversion['Status']).equal? 'SUCCEEDED' - end - end -end \ No newline at end of file diff --git a/spec/mangopay/shared_resources.rb b/spec/mangopay/shared_resources.rb index e23193f..03d8da8 100644 --- a/spec/mangopay/shared_resources.rb +++ b/spec/mangopay/shared_resources.rb @@ -898,10 +898,10 @@ def create_new_deposit(card_registration_id, author_id) include_context 'payins' def get_conversion_rate(debited_currency, credited_currency) - MangoPay::InstantConversion.get_rate(debited_currency, credited_currency, params = {}) + MangoPay::Conversion.get_rate(debited_currency, credited_currency, params = {}) end - def create_instant_conversion() + def create_conversion() user = new_natural_user credited_wallet = MangoPay::Wallet.create( Owners: [user['Id']], @@ -910,7 +910,7 @@ def create_instant_conversion() Tag: 'Test wallet' ) - MangoPay::InstantConversion.create( + MangoPay::Conversion.create( AuthorId: user['Id'], CreditedWalletId: credited_wallet['Id'], DebitedWalletId: new_wallet_with_money['Id'], @@ -925,8 +925,21 @@ def create_instant_conversion() ) end - def get_instant_conversion(id) - MangoPay::InstantConversion.get(id, params = {}) + def create_conversion_quote + MangoPay::Conversion.create_quote( + CreditedFunds: { Currency: 'GBP' }, + DebitedFunds: { Currency: 'EUR', Amount: 50 }, + Duration: 90, + Tag: 'Created using the Mangopay Ruby SDK' + ) + end + + def get_conversion(id) + MangoPay::Conversion.get(id, params = {}) + end + + def get_conversion_quote(id) + MangoPay::Conversion.get_quote(id, params = {}) end end