Skip to content

Commit

Permalink
Merge branch 'master' into feature/satispay-payin
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/mangopay/pay_in.rb
#	spec/mangopay/shared_resources.rb
  • Loading branch information
Iulian Masar committed Sep 4, 2023
2 parents 67ff480 + 94ea0b6 commit 0ca0a37
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 6 deletions.
5 changes: 5 additions & 0 deletions lib/mangopay/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def fingerprint_url(fingerprint)
def get_pre_authorizations(card_id, filters = {})
MangoPay.request(:get, "#{MangoPay.api_path}/cards/#{card_id}/preauthorizations")
end

def validate(card_id, params)
url = "#{MangoPay.api_path}/cards/#{card_id}/validation"
MangoPay.request(:post, url, params)
end
end
end
end
5 changes: 0 additions & 5 deletions lib/mangopay/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ def fetch_wallet_transactions(funds_type, currency_iso_code, filters = {})
MangoPay.request(:get, url() + "/wallets/#{funds_type}/#{currency_iso_code}/transactions", {}, filters)
end

def validate(client_id, card_id)
url = "#{MangoPay.api_path}/cards/#{card_id}/validate"
MangoPay.request(:post, url)
end

def create_bank_account(params)
MangoPay.request(:post, url() + "/bankaccounts/iban", params)
end
Expand Down
22 changes: 21 additions & 1 deletion lib/mangopay/pay_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module PayPal

# See https://docs.mangopay.com/api-references/payins/paypal-payin/
# # <b>DEPRECATED</b>: 'create' function is now deprecated.
# Please use the 'create_new' function - MangoPay::PayIn::PayPal::Web.create_new(params)
# Please use the 'create_v2' function - MangoPay::PayIn::PayPal::Web.create_new(params)
class Web < Resource
include HTTPCalls::Create
def self.url(*)
Expand Down Expand Up @@ -157,6 +157,26 @@ def self.url(*)
end
end

module Multibanco
class Web < Resource
include HTTPCalls::Create

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

module Blik
class Web < Resource
include HTTPCalls::Create

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

module Satispay
class Web < Resource
include HTTPCalls::Create
Expand Down
9 changes: 9 additions & 0 deletions spec/mangopay/card_registration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@
expect(transactions).to be_an(Array)
end
end

describe 'VALIDATE CARD' do
it "validates a card" do
created = new_card_registration_completed
validated = create_card_validation(created['UserId'], created['CardId'])

expect(validated).to_not be_nil
end
end
end
32 changes: 32 additions & 0 deletions spec/mangopay/payin_blik_web_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
describe MangoPay::PayIn::Blik::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('BLIK')
expect(payin['ExecutionType']).to eq('WEB')
expect(payin['Status']).to eq('CREATED')
end

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

describe 'FETCH' do
it 'fetches a payin' do
created = new_payin_blik_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
32 changes: 32 additions & 0 deletions spec/mangopay/payin_multibanco_web_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
describe MangoPay::PayIn::Multibanco::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('MULTIBANCO')
expect(payin['ExecutionType']).to eq('WEB')
expect(payin['Status']).to eq('CREATED')
end

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

describe 'FETCH' do
it 'fetches a payin' do
created = new_payin_multibanco_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
58 changes: 58 additions & 0 deletions spec/mangopay/shared_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,43 @@ def create_new_document(user)
)
end

###############################################
# MULTIBANCO/web
###############################################
let(:new_payin_multibanco_web) do
MangoPay::PayIn::Multibanco::Web.create(
AuthorId: new_natural_user['Id'],
DebitedFunds: {Currency: 'EUR', Amount: 199},
Fees: {Currency: 'EUR', Amount: 1},
CreditedWalletId: new_wallet['Id'],
StatementDescriptor: "ruby",
Tag: 'Test PayIn/Multibanco/Web',
ReturnURL: 'http://www.my-site.com/returnURL'
)
end

###############################################
# BLIK/web
###############################################
let(:new_payin_blik_web) do
user = new_natural_user
wallet = MangoPay::Wallet.create(
Owners: [user['Id']],
Description: 'A test wallet',
Currency: 'PLN',
Tag: 'Test wallet'
)
MangoPay::PayIn::Blik::Web.create(
AuthorId: user['Id'],
CreditedWalletId: wallet['Id'],
DebitedFunds: {Currency: 'PLN', Amount: 199},
Fees: {Currency: 'PLN', Amount: 1},
StatementDescriptor: "ruby",
Tag: 'Test PayIn/Blik/Web',
ReturnURL: 'https://example.com'
)
end

###############################################
# SATISPAY/web
###############################################
Expand Down Expand Up @@ -600,6 +637,27 @@ def create_new_payin_preauthorized_direct(to_wallet, amnt = 1000)
)
end

def create_card_validation(author_id, card_id)
params = {
AuthorId: author_id,
SecureModeReturnURL: "https://mangopay.com",
IpAddress: "2001:0620:0000:0000:0211:24FF:FE80:C12C",
Tag: "custom meta",
BrowserInfo: {
AcceptHeader: "text/html, application/xhtml+xml, application/xml;q=0.9, /;q=0.8",
JavaEnabled: true,
Language: "FR-FR",
ColorDepth: 4,
ScreenHeight: 1800,
ScreenWidth: 400,
JavascriptEnabled: true,
TimeZoneOffset: "+60",
UserAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
}
}
MangoPay::Card.validate(card_id, params)
end

###############################################
# pre-authorized direct deposit
###############################################
Expand Down

0 comments on commit 0ca0a37

Please sign in to comment.