Skip to content

Commit

Permalink
Merge pull request #222 from Mangopay/feature/paypal-v2
Browse files Browse the repository at this point in the history
added paypal DIRECT
  • Loading branch information
iulian03 committed Jul 7, 2023
2 parents b5f0e3e + 836212f commit 68b928e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/mangopay/pay_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,21 @@ def self.url(*)
module PayPal

# See https://docs.mangopay.com/api-references/payins/paypal-payin/
# <b>DEPRECATED</b>: Please use the Direct payment method. Web will be removed in a future version.
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"
end
end

end

module Payconiq
Expand Down
2 changes: 1 addition & 1 deletion spec/mangopay/payin_mbway_direct_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions spec/mangopay/payin_paypal_direct_spec.rb
Original file line number Diff line number Diff line change
@@ -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
46 changes: 45 additions & 1 deletion spec/mangopay/shared_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 68b928e

Please sign in to comment.