diff --git a/lib/mangopay/pay_in.rb b/lib/mangopay/pay_in.rb index ee2c7bf..1f221aa 100644 --- a/lib/mangopay/pay_in.rb +++ b/lib/mangopay/pay_in.rb @@ -101,18 +101,16 @@ def self.url(*) module PayPal # See https://docs.mangopay.com/api-references/payins/paypal-payin/ - # DEPRECATED: Please use the Direct payment method. Web will be removed in a future version. + # # DEPRECATED: 'create' function is now deprecated. + # Please use the 'create_v2' function - MangoPay::PayIn::PayPal::Web.create_new(params) class Web < Resource include HTTPCalls::Create def self.url(*) "#{MangoPay.api_path}/payins/paypal/#{CGI.escape(class_name.downcase)}" end - end - class Direct < Resource - include HTTPCalls::Create - def self.url(*) - "#{MangoPay.api_path}/payins/payment-methods/paypal" + def self.create_v2(params, idempotency_key = nil) + MangoPay.request(:post, "#{MangoPay.api_path}/payins/payment-methods/paypal", params, {}, idempotency_key) end end @@ -150,7 +148,7 @@ def self.url(*) end module Mbway - class Direct < Resource + class Web < Resource include HTTPCalls::Create def self.url(*) diff --git a/spec/mangopay/payin_mbway_direct_spec.rb b/spec/mangopay/payin_mbway_web_spec.rb similarity index 74% rename from spec/mangopay/payin_mbway_direct_spec.rb rename to spec/mangopay/payin_mbway_web_spec.rb index 948f361..7314e61 100644 --- a/spec/mangopay/payin_mbway_direct_spec.rb +++ b/spec/mangopay/payin_mbway_web_spec.rb @@ -1,4 +1,4 @@ -describe MangoPay::PayIn::Mbway::Direct, type: :feature do +describe MangoPay::PayIn::Mbway::Web, type: :feature do include_context 'wallets' include_context 'payins' @@ -6,13 +6,13 @@ def check_type_and_status(payin) expect(payin['Type']).to eq('PAYIN') expect(payin['Nature']).to eq('REGULAR') expect(payin['PaymentType']).to eq('MBWAY') - expect(payin['ExecutionType']).to eq('DIRECT') + expect(payin['ExecutionType']).to eq('WEB') expect(payin['Status']).to eq('CREATED') end describe 'CREATE' do - it 'creates a mbway direct payin' do - created = new_payin_mbway_direct + it 'creates a mbway web payin' do + created = new_payin_mbway_web expect(created['Id']).not_to be_nil expect(created['Phone']).not_to be_nil check_type_and_status(created) @@ -21,7 +21,7 @@ def check_type_and_status(payin) describe 'FETCH' do it 'fetches a payin' do - created = new_payin_mbway_direct + created = new_payin_mbway_web fetched = MangoPay::PayIn.fetch(created['Id']) expect(fetched['Id']).to eq(created['Id']) check_type_and_status(created) diff --git a/spec/mangopay/payin_paypal_direct_spec.rb b/spec/mangopay/payin_paypal_direct_spec.rb deleted file mode 100644 index 5aa552c..0000000 --- a/spec/mangopay/payin_paypal_direct_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -describe MangoPay::PayIn::PayPal::Direct, type: :feature do - 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('PAYPAL') - expect(payin['ExecutionType']).to eq('DIRECT') - - # not SUCCEEDED yet: waiting for processing - expect(payin['Status']).to eq('CREATED') - expect(payin['ResultCode']).to be_nil - expect(payin['ResultMessage']).to be_nil - expect(payin['ExecutionDate']).to be_nil - end - - describe 'CREATE' do - it 'creates a paypal direct payin' do - created = new_payin_paypal_direct - 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_paypal_direct - fetched = MangoPay::PayIn.fetch(created['Id']) - expect(fetched['Id']).to eq(created['Id']) - expect(fetched['CreationDate']).to eq(created['CreationDate']) - expect(fetched['CreditedFunds']).to eq(created['CreditedFunds']) - expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId']) - check_type_and_status(created) - check_type_and_status(fetched) - end - end - -end diff --git a/spec/mangopay/payin_paypal_web_spec.rb b/spec/mangopay/payin_paypal_web_spec.rb index 811541f..c96222b 100644 --- a/spec/mangopay/payin_paypal_web_spec.rb +++ b/spec/mangopay/payin_paypal_web_spec.rb @@ -22,6 +22,14 @@ def check_type_and_status(payin) end end + describe 'CREATE V2' do + it 'creates a paypal web v2 payin' do + created = new_payin_paypal_web_v2 + expect(created['Id']).not_to be_nil + check_type_and_status(created) + end + end + describe "FETCH" do it 'FETCHES a payIn with PayPal account email' do payin_id = "54088959" @@ -47,4 +55,17 @@ def check_type_and_status(payin) end end + describe 'FETCH V2' do + it 'fetches a payin' do + created = new_payin_paypal_web_v2 + fetched = MangoPay::PayIn.fetch(created['Id']) + expect(fetched['Id']).to eq(created['Id']) + expect(fetched['CreationDate']).to eq(created['CreationDate']) + expect(fetched['CreditedFunds']).to eq(created['CreditedFunds']) + expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId']) + 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 ac8ea46..c23401c 100644 --- a/spec/mangopay/shared_resources.rb +++ b/spec/mangopay/shared_resources.rb @@ -443,14 +443,14 @@ def create_new_document(user) ############################################### # MBWAY/direct ############################################### - let(:new_payin_mbway_direct) do - MangoPay::PayIn::Mbway::Direct.create( + let(:new_payin_mbway_web) do + MangoPay::PayIn::Mbway::Web.create( AuthorId: new_natural_user['Id'], CreditedWalletId: new_wallet['Id'], DebitedFunds: {Currency: 'EUR', Amount: 199}, Fees: {Currency: 'EUR', Amount: 1}, StatementDescriptor: "ruby", - Tag: 'Test PayIn/Mbway/Direct', + Tag: 'Test PayIn/Mbway/Web', Phone: '351#269458236' ) end @@ -458,8 +458,8 @@ def create_new_document(user) ############################################### # PAYPAL/direct ############################################### - let(:new_payin_paypal_direct) do - MangoPay::PayIn::PayPal::Direct.create( + let(:new_payin_paypal_web_v2) do + MangoPay::PayIn::PayPal::Web.create_v2( AuthorId: new_natural_user['Id'], DebitedFunds: { Currency: 'EUR', Amount: 400 }, Fees: { Currency: 'EUR', Amount: 0 },