From d9d1dc730d13b443f2c83bf1b00aee317702613b Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Thu, 31 Aug 2023 17:10:56 +0300 Subject: [PATCH 1/6] added card validation function --- lib/mangopay/card.rb | 5 +++++ spec/mangopay/card_registration_spec.rb | 10 ++++++++++ spec/mangopay/shared_resources.rb | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/lib/mangopay/card.rb b/lib/mangopay/card.rb index 41bcd2c..70de843 100644 --- a/lib/mangopay/card.rb +++ b/lib/mangopay/card.rb @@ -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 diff --git a/spec/mangopay/card_registration_spec.rb b/spec/mangopay/card_registration_spec.rb index cec43f2..5080a51 100644 --- a/spec/mangopay/card_registration_spec.rb +++ b/spec/mangopay/card_registration_spec.rb @@ -92,4 +92,14 @@ 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 + expect(validated['Validity']).to be('VALID') + end + end end diff --git a/spec/mangopay/shared_resources.rb b/spec/mangopay/shared_resources.rb index c23401c..768a8bf 100644 --- a/spec/mangopay/shared_resources.rb +++ b/spec/mangopay/shared_resources.rb @@ -584,6 +584,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 ############################################### From bd013416379ecbe98aba93de4a745442be2162fa Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Mon, 4 Sep 2023 09:33:48 +0300 Subject: [PATCH 2/6] removed check --- spec/mangopay/card_registration_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/mangopay/card_registration_spec.rb b/spec/mangopay/card_registration_spec.rb index 5080a51..4ed50da 100644 --- a/spec/mangopay/card_registration_spec.rb +++ b/spec/mangopay/card_registration_spec.rb @@ -99,7 +99,6 @@ validated = create_card_validation(created['UserId'], created['CardId']) expect(validated).to_not be_nil - expect(validated['Validity']).to be('VALID') end end end From 63ab8f177032ecef29822827fa056ef7ce74066a Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Mon, 4 Sep 2023 09:36:04 +0300 Subject: [PATCH 3/6] removed old function --- lib/mangopay/client.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/mangopay/client.rb b/lib/mangopay/client.rb index bb546fc..018566c 100644 --- a/lib/mangopay/client.rb +++ b/lib/mangopay/client.rb @@ -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 From 99a58f8220a8dc3e2d791d841f4c2c92c61ab945 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Mon, 4 Sep 2023 09:55:46 +0300 Subject: [PATCH 4/6] added multibanco web payin --- lib/mangopay/pay_in.rb | 10 +++++++ spec/mangopay/payin_multibanco_web_spec.rb | 32 ++++++++++++++++++++++ spec/mangopay/shared_resources.rb | 17 +++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 spec/mangopay/payin_multibanco_web_spec.rb diff --git a/lib/mangopay/pay_in.rb b/lib/mangopay/pay_in.rb index 42f22e5..6384d7e 100644 --- a/lib/mangopay/pay_in.rb +++ b/lib/mangopay/pay_in.rb @@ -157,6 +157,16 @@ 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 RecurringPayments class Recurring < Resource include HTTPCalls::Create diff --git a/spec/mangopay/payin_multibanco_web_spec.rb b/spec/mangopay/payin_multibanco_web_spec.rb new file mode 100644 index 0000000..aef7d85 --- /dev/null +++ b/spec/mangopay/payin_multibanco_web_spec.rb @@ -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 diff --git a/spec/mangopay/shared_resources.rb b/spec/mangopay/shared_resources.rb index c23401c..de712ee 100644 --- a/spec/mangopay/shared_resources.rb +++ b/spec/mangopay/shared_resources.rb @@ -441,7 +441,7 @@ def create_new_document(user) let(:new_payin_card_direct) { create_new_payin_card_direct(new_wallet) } ############################################### - # MBWAY/direct + # MBWAY/web ############################################### let(:new_payin_mbway_web) do MangoPay::PayIn::Mbway::Web.create( @@ -455,6 +455,21 @@ 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 + ############################################### # PAYPAL/direct ############################################### From 174a477673d01a514b0ffe99834a517ccd44e531 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Mon, 4 Sep 2023 10:06:21 +0300 Subject: [PATCH 5/6] added blik web payin --- lib/mangopay/pay_in.rb | 10 +++++++++ spec/mangopay/payin_blik_web_spec.rb | 32 ++++++++++++++++++++++++++++ spec/mangopay/shared_resources.rb | 24 ++++++++++++++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 spec/mangopay/payin_blik_web_spec.rb diff --git a/lib/mangopay/pay_in.rb b/lib/mangopay/pay_in.rb index 42f22e5..a7106c8 100644 --- a/lib/mangopay/pay_in.rb +++ b/lib/mangopay/pay_in.rb @@ -157,6 +157,16 @@ def self.url(*) end end + module Blik + class Web < Resource + include HTTPCalls::Create + + def self.url(*) + "#{MangoPay.api_path}/payins/payment-methods/blik" + end + end + end + module RecurringPayments class Recurring < Resource include HTTPCalls::Create diff --git a/spec/mangopay/payin_blik_web_spec.rb b/spec/mangopay/payin_blik_web_spec.rb new file mode 100644 index 0000000..87db0e7 --- /dev/null +++ b/spec/mangopay/payin_blik_web_spec.rb @@ -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 diff --git a/spec/mangopay/shared_resources.rb b/spec/mangopay/shared_resources.rb index c23401c..cf6ed12 100644 --- a/spec/mangopay/shared_resources.rb +++ b/spec/mangopay/shared_resources.rb @@ -441,7 +441,7 @@ def create_new_document(user) let(:new_payin_card_direct) { create_new_payin_card_direct(new_wallet) } ############################################### - # MBWAY/direct + # MBWAY/web ############################################### let(:new_payin_mbway_web) do MangoPay::PayIn::Mbway::Web.create( @@ -455,6 +455,28 @@ def create_new_document(user) ) 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 + ############################################### # PAYPAL/direct ############################################### From 4ab8389cbac572e97a97f01ae0b7fa38f6af7310 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Mon, 4 Sep 2023 13:00:09 +0300 Subject: [PATCH 6/6] small refactoring --- lib/mangopay/pay_in.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mangopay/pay_in.rb b/lib/mangopay/pay_in.rb index 42f22e5..1f221aa 100644 --- a/lib/mangopay/pay_in.rb +++ b/lib/mangopay/pay_in.rb @@ -102,7 +102,7 @@ module PayPal # See https://docs.mangopay.com/api-references/payins/paypal-payin/ # # DEPRECATED: '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(*)