diff --git a/lib/mangopay/pay_in.rb b/lib/mangopay/pay_in.rb index 2d56701..98b176f 100644 --- a/lib/mangopay/pay_in.rb +++ b/lib/mangopay/pay_in.rb @@ -101,6 +101,7 @@ 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. class Web < Resource include HTTPCalls::Create def self.url(*) @@ -108,6 +109,13 @@ def self.url(*) end end + class Direct < Resource + include HTTPCalls::Create + def self.url(*) + "#{MangoPay.api_path}/payins/payment-methods/paypal" + end + end + end module Payconiq diff --git a/spec/mangopay/payin_mbway_direct_spec.rb b/spec/mangopay/payin_mbway_direct_spec.rb index e52cf88..948f361 100644 --- a/spec/mangopay/payin_mbway_direct_spec.rb +++ b/spec/mangopay/payin_mbway_direct_spec.rb @@ -14,7 +14,7 @@ def check_type_and_status(payin) it 'creates a mbway direct payin' do created = new_payin_mbway_direct expect(created['Id']).not_to be_nil - expect(created['PhoneNumber']).not_to be_nil + expect(created['Phone']).not_to be_nil check_type_and_status(created) end end diff --git a/spec/mangopay/payin_paypal_direct_spec.rb b/spec/mangopay/payin_paypal_direct_spec.rb new file mode 100644 index 0000000..5aa552c --- /dev/null +++ b/spec/mangopay/payin_paypal_direct_spec.rb @@ -0,0 +1,38 @@ +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/shared_resources.rb b/spec/mangopay/shared_resources.rb index a26ebf6..aa760bd 100644 --- a/spec/mangopay/shared_resources.rb +++ b/spec/mangopay/shared_resources.rb @@ -428,7 +428,51 @@ def create_new_document(user) Fees: {Currency: 'EUR', Amount: 1}, StatementDescriptor: "ruby", Tag: 'Test PayIn/Mbway/Direct', - PhoneNumber: '351#269458236' + Phone: '351#269458236' + ) + end + + ############################################### + # PAYPAL/direct + ############################################### + let(:new_payin_paypal_direct) do + MangoPay::PayIn::PayPal::Direct.create( + AuthorId: new_natural_user['Id'], + DebitedFunds: { Currency: 'EUR', Amount: 400 }, + Fees: { Currency: 'EUR', Amount: 0 }, + CreditedWalletId: new_wallet['Id'], + ReturnUrl: "http://example.com", + LineItems: [ + { + Name: "running shoes", + Quantity: 1, + UnitAmount: 200, + TaxAmount: 0, + Description: "seller1 ID" + }, + { + Name: "running shoes", + Quantity: 1, + UnitAmount: 200, + TaxAmount: 0, + Description: "seller2 ID" + } + ], + Shipping: { + Address: { + AddressLine1: 'AddressLine1', + AddressLine2: 'AddressLine2', + City: 'City', + Region: 'Region', + PostalCode: 'PostalCode', + Country: 'FR' + }, + FirstName: 'Joe', + LastName: 'Blogs' + }, + StatementDescriptor: "ruby", + Tag: 'Test', + # Culture: 'FR' ) end