Skip to content

Commit

Permalink
updated conversion endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
iulian03 committed Mar 8, 2024
1 parent 19c07c4 commit 62997d6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 42 deletions.
7 changes: 6 additions & 1 deletion lib/mangopay/conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 16 additions & 4 deletions spec/mangopay/conversion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
35 changes: 0 additions & 35 deletions spec/mangopay/instant_conversion_spec.rb

This file was deleted.

23 changes: 21 additions & 2 deletions spec/mangopay/shared_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']],
Expand All @@ -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'],
Expand All @@ -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' },
Expand Down

0 comments on commit 62997d6

Please sign in to comment.