Skip to content

Commit

Permalink
Merge pull request #247 from Mangopay/feature/conversion-updates
Browse files Browse the repository at this point in the history
Feature/conversion updates
  • Loading branch information
iulian03 authored Mar 8, 2024
2 parents 7adc800 + 62997d6 commit 7439e6d
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 62 deletions.
2 changes: 1 addition & 1 deletion lib/mangopay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions lib/mangopay/conversion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module MangoPay

class Conversion < Resource
include HTTPCalls::Fetch
include HTTPCalls::Update

class << self
def get_rate(debited_currency, credited_currency, params)
url = "#{MangoPay.api_path}/conversions/rate/#{debited_currency}/#{credited_currency}"
MangoPay.request(:get, url, params)
end

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)
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
24 changes: 0 additions & 24 deletions lib/mangopay/instant_conversion.rb

This file was deleted.

64 changes: 64 additions & 0 deletions spec/mangopay/conversion_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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 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
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_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

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
33 changes: 0 additions & 33 deletions spec/mangopay/instant_conversion_spec.rb

This file was deleted.

44 changes: 40 additions & 4 deletions spec/mangopay/shared_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ 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()
Expand All @@ -910,7 +910,7 @@ def create_instant_conversion()
Tag: 'Test wallet'
)

MangoPay::InstantConversion.create(
MangoPay::Conversion.create_instant_conversion(
AuthorId: user['Id'],
CreditedWalletId: credited_wallet['Id'],
DebitedWalletId: new_wallet_with_money['Id'],
Expand All @@ -921,12 +921,48 @@ def create_instant_conversion()
Currency: 'EUR',
Amount: 79
},
Fees: {
Currency: 'EUR',
Amount: 9
},
Tag: 'Instant conversion test'
)
end

def get_instant_conversion(id)
MangoPay::InstantConversion.get(id, params = {})
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' },
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

Expand Down

0 comments on commit 7439e6d

Please sign in to comment.