Skip to content

Commit

Permalink
implemented Twint and Swish payins
Browse files Browse the repository at this point in the history
  • Loading branch information
Iulian Masar committed Nov 15, 2024
1 parent dc8e5b0 commit 866b00f
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/mangopay/pay_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,26 @@ def self.url(*)
end
end

module Twint
class Web < Resource
include HTTPCalls::Create

def self.url(*)
"#{MangoPay.api_path}/payins/payment-methods/twint"
end
end
end

module Swish
class Web < Resource
include HTTPCalls::Create

def self.url(*)
"#{MangoPay.api_path}/payins/payment-methods/swish"
end
end
end

module RecurringPayments
class Recurring < Resource
include HTTPCalls::Create
Expand Down
30 changes: 30 additions & 0 deletions spec/mangopay/payin_swish_web_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe MangoPay::PayIn::Swish::Web, type: :feature do
include_context 'wallets'
include_context 'payins'

def check_type_and_status(payin)
expect(payin['Type']).to eq('PAYIN')
expect(payin['Nature']).to eq('REGULAR')
expect(payin['PaymentType']).to eq('SWISH')
expect(payin['ExecutionType']).to eq('WEB')
expect(payin['Status']).to eq('CREATED')
end

describe 'CREATE' do
it 'creates a swish web payin' do
created = new_payin_swish_web
expect(created['Id']).not_to be_nil
check_type_and_status(created)
end
end

describe 'FETCH' do
it 'fetches a payin' do
created = new_payin_swish_web
fetched = MangoPay::PayIn.fetch(created['Id'])
expect(fetched['Id']).to eq(created['Id'])
check_type_and_status(created)
check_type_and_status(fetched)
end
end
end
30 changes: 30 additions & 0 deletions spec/mangopay/payin_twint_web_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe MangoPay::PayIn::Twint::Web, type: :feature do
include_context 'wallets'
include_context 'payins'

def check_type_and_status(payin)
expect(payin['Type']).to eq('PAYIN')
expect(payin['Nature']).to eq('REGULAR')
expect(payin['PaymentType']).to eq('TWINT')
expect(payin['ExecutionType']).to eq('WEB')
expect(payin['Status']).to eq('CREATED')
end

describe 'CREATE' do
it 'creates a twint web payin' do
created = new_payin_twint_web
expect(created['Id']).not_to be_nil
check_type_and_status(created)
end
end

describe 'FETCH' do
it 'fetches a payin' do
created = new_payin_twint_web
fetched = MangoPay::PayIn.fetch(created['Id'])
expect(fetched['Id']).to eq(created['Id'])
check_type_and_status(created)
check_type_and_status(fetched)
end
end
end
39 changes: 39 additions & 0 deletions spec/mangopay/shared_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ def create_new_wallet(user)
)
end

def create_new_custom_wallet(user, currency)
MangoPay::Wallet.create(
Owners: [user['Id']],
Description: 'A test wallet',
Currency: currency,
Tag: 'Test wallet'
)
end

def wallets_check_amounts(wlt1, amnt1, wlt2 = nil, amnt2 = nil)
expect(wlt1['Balance']['Amount']).to eq amnt1
expect(wlt2['Balance']['Amount']).to eq amnt2 if wlt2
Expand Down Expand Up @@ -570,6 +579,36 @@ def create_new_document(user)
)
end

###############################################
# Twint/web
###############################################
let(:new_payin_twint_web) do
MangoPay::PayIn::Twint::Web.create(
AuthorId: new_natural_user['Id'],
CreditedWalletId: create_new_custom_wallet(new_natural_user, 'CHF')['Id'],
DebitedFunds: { Currency: 'CHF', Amount: 50 },
Fees: { Currency: 'CHF', Amount: 10 },
ReturnURL: 'http://www.my-site.com/returnURL',
StatementDescriptor: "test",
Tag: 'Test PayIn/Twint/Web'
)
end

###############################################
# Swish/web
###############################################
let(:new_payin_swish_web) do
MangoPay::PayIn::Swish::Web.create(
AuthorId: new_natural_user['Id'],
CreditedWalletId: create_new_custom_wallet(new_natural_user, 'SEK')['Id'],
DebitedFunds: { Currency: 'SEK', Amount: 400 },
Fees: { Currency: 'SEK', Amount: 10 },
ReturnURL: 'http://www.my-site.com/returnURL',
StatementDescriptor: "test",
Tag: 'Test PayIn/Swish/Web'
)
end

###############################################
# PAYPAL/web V2
###############################################
Expand Down

0 comments on commit 866b00f

Please sign in to comment.