From 601486d33c4b3266b51838a7fc051a4832c8582e Mon Sep 17 00:00:00 2001 From: Mihai Moiseanu Date: Thu, 29 Feb 2024 15:26:10 +0200 Subject: [PATCH 1/4] Fix typo in conversion endpoint --- lib/mangopay/instant_conversion.rb | 6 +++--- spec/mangopay/instant_conversion_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/mangopay/instant_conversion.rb b/lib/mangopay/instant_conversion.rb index a437059..67bdda1 100644 --- a/lib/mangopay/instant_conversion.rb +++ b/lib/mangopay/instant_conversion.rb @@ -6,17 +6,17 @@ class InstantConversion < Resource class << self def get_rate(debited_currency, credited_currency, params) - url = "#{MangoPay.api_path}/conversion/rate/#{debited_currency}/#{credited_currency}" + url = "#{MangoPay.api_path}/conversions/rate/#{debited_currency}/#{credited_currency}" MangoPay.request(:get, url, params) end def create(params) - url = "#{MangoPay.api_path}/instant-conversion" + url = "#{MangoPay.api_path}/conversions/instant-conversion" MangoPay.request(:post, url, params) end def get(id, params) - url = "#{MangoPay.api_path}/instant-conversion/#{id}" + url = "#{MangoPay.api_path}/conversions/#{id}" MangoPay.request(:get, url, params) end end diff --git a/spec/mangopay/instant_conversion_spec.rb b/spec/mangopay/instant_conversion_spec.rb index 0daf2f2..7080f94 100644 --- a/spec/mangopay/instant_conversion_spec.rb +++ b/spec/mangopay/instant_conversion_spec.rb @@ -15,7 +15,7 @@ conversion = create_instant_conversion expect(conversion['DebitedFunds']['Amount']).not_to be_nil - expect(conversion['CreditedFunds']['Amount']).not_to be_nil + expect(conversion['CreditedFunds']).not_to be_nil expect(conversion['Status']).equal? 'SUCCEEDED' end end @@ -26,7 +26,7 @@ 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['CreditedFunds']).not_to be_nil expect(returned_conversion['Status']).equal? 'SUCCEEDED' end end From 387ec304a30404858ad0db45dea7e270c3c9aa1a Mon Sep 17 00:00:00 2001 From: Mihai Moiseanu Date: Thu, 29 Feb 2024 15:33:27 +0200 Subject: [PATCH 2/4] Add fees param to instant conversion --- spec/mangopay/instant_conversion_spec.rb | 4 +++- spec/mangopay/shared_resources.rb | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/mangopay/instant_conversion_spec.rb b/spec/mangopay/instant_conversion_spec.rb index 0daf2f2..9a35c2a 100644 --- a/spec/mangopay/instant_conversion_spec.rb +++ b/spec/mangopay/instant_conversion_spec.rb @@ -15,7 +15,9 @@ conversion = create_instant_conversion expect(conversion['DebitedFunds']['Amount']).not_to be_nil - expect(conversion['CreditedFunds']['Amount']).not_to be_nil + expect(conversion['CreditedFunds']).not_to be_nil + expect(conversion['Fees']).not_to be_nil + expect(conversion['Fees']['Amount']).equal? 9 expect(conversion['Status']).equal? 'SUCCEEDED' end end diff --git a/spec/mangopay/shared_resources.rb b/spec/mangopay/shared_resources.rb index e23193f..8e8353f 100644 --- a/spec/mangopay/shared_resources.rb +++ b/spec/mangopay/shared_resources.rb @@ -921,6 +921,10 @@ def create_instant_conversion() Currency: 'EUR', Amount: 79 }, + Fees: { + Currency: 'EUR', + Amount: 9 + }, Tag: 'Instant conversion test' ) end From b174e276afe28e28ed47cca0ee95580d01d2f893 Mon Sep 17 00:00:00 2001 From: Mihai Moiseanu Date: Thu, 29 Feb 2024 16:43:36 +0200 Subject: [PATCH 3/4] 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 From 62997d6ad16020c4b9985cb7a2ee598d782a0c82 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Fri, 8 Mar 2024 11:26:38 +0200 Subject: [PATCH 4/4] updated conversion endpoints --- lib/mangopay/conversion.rb | 7 ++++- spec/mangopay/conversion_spec.rb | 20 +++++++++++--- spec/mangopay/instant_conversion_spec.rb | 35 ------------------------ spec/mangopay/shared_resources.rb | 23 ++++++++++++++-- 4 files changed, 43 insertions(+), 42 deletions(-) delete mode 100644 spec/mangopay/instant_conversion_spec.rb diff --git a/lib/mangopay/conversion.rb b/lib/mangopay/conversion.rb index 5331c15..19c6a3c 100644 --- a/lib/mangopay/conversion.rb +++ b/lib/mangopay/conversion.rb @@ -10,11 +10,16 @@ def get_rate(debited_currency, credited_currency, params) MangoPay.request(:get, url, params) end - def create(params) + def create_instant_conversion(params) url = "#{MangoPay.api_path}/conversions/instant-conversion" MangoPay.request(:post, url, params) end + def create_quoted_conversion(params) + url = "#{MangoPay.api_path}/conversions/quoted-conversion" + MangoPay.request(:post, url, params) + end + def get(id, params) url = "#{MangoPay.api_path}/conversions/#{id}" MangoPay.request(:get, url, params) diff --git a/spec/mangopay/conversion_spec.rb b/spec/mangopay/conversion_spec.rb index a9518d2..2aaa15f 100644 --- a/spec/mangopay/conversion_spec.rb +++ b/spec/mangopay/conversion_spec.rb @@ -10,9 +10,20 @@ end end - describe 'CREATE CONVERSION' do - it 'creates a new conversion' do - conversion = create_conversion + describe 'CREATE INSTANT CONVERSION' do + it 'creates a new instant conversion' do + conversion = create_instant_conversion + + expect(conversion['DebitedFunds']['Amount']).not_to be_nil + expect(conversion['CreditedFunds']['Amount']).not_to be_nil + expect(conversion['Fees']['Amount']).not_to be_nil + expect(conversion['Status']).equal? 'SUCCEEDED' + end + end + + describe 'CREATE QUOTED CONVERSION' do + it 'creates a new quoted conversion' do + conversion = create_quoted_conversion expect(conversion['DebitedFunds']['Amount']).not_to be_nil expect(conversion['CreditedFunds']['Amount']).not_to be_nil @@ -22,11 +33,12 @@ describe 'GET EXISTING CONVERSION' do it 'get an existing conversion' do - conversion = create_conversion + conversion = create_instant_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(conversion['Fees']['Amount']).not_to be_nil expect(returned_conversion['Status']).equal? 'SUCCEEDED' end end diff --git a/spec/mangopay/instant_conversion_spec.rb b/spec/mangopay/instant_conversion_spec.rb deleted file mode 100644 index 7cfcdbf..0000000 --- a/spec/mangopay/instant_conversion_spec.rb +++ /dev/null @@ -1,35 +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']).not_to be_nil - expect(conversion['Fees']).not_to be_nil - expect(conversion['Fees']['Amount']).equal? 9 - 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']).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 c0a240e..0af611d 100644 --- a/spec/mangopay/shared_resources.rb +++ b/spec/mangopay/shared_resources.rb @@ -901,7 +901,7 @@ def get_conversion_rate(debited_currency, credited_currency) MangoPay::Conversion.get_rate(debited_currency, credited_currency, params = {}) end - def create_conversion() + def create_instant_conversion() user = new_natural_user credited_wallet = MangoPay::Wallet.create( Owners: [user['Id']], @@ -910,7 +910,7 @@ def create_conversion() Tag: 'Test wallet' ) - MangoPay::Conversion.create( + MangoPay::Conversion.create_instant_conversion( AuthorId: user['Id'], CreditedWalletId: credited_wallet['Id'], DebitedWalletId: new_wallet_with_money['Id'], @@ -929,6 +929,25 @@ def create_conversion() ) end + def create_quoted_conversion() + user = new_natural_user + credited_wallet = MangoPay::Wallet.create( + Owners: [user['Id']], + Description: 'A test wallet', + Currency: 'GBP', + Tag: 'Test wallet' + ) + quote = create_conversion_quote + + MangoPay::Conversion.create_quoted_conversion( + AuthorId: user['Id'], + QuoteId: quote['Id'], + CreditedWalletId: credited_wallet['Id'], + DebitedWalletId: new_wallet_with_money['Id'], + Tag: 'Quoted conversion test' + ) + end + def create_conversion_quote MangoPay::Conversion.create_quote( CreditedFunds: { Currency: 'GBP' },