Skip to content

Commit

Permalink
Merge pull request #227 from Mangopay/improvement/mbway-paypal-execut…
Browse files Browse the repository at this point in the history
…ion-type

updated execution type for PayPal and mbway payins; added 'create_v2' PayPal payin function
  • Loading branch information
iulian03 committed Sep 4, 2023
2 parents 95f260c + 4ab8389 commit bb296db
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 55 deletions.
12 changes: 5 additions & 7 deletions lib/mangopay/pay_in.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,16 @@ 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.
# # <b>DEPRECATED</b>: '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

Expand Down Expand Up @@ -150,7 +148,7 @@ def self.url(*)
end

module Mbway
class Direct < Resource
class Web < Resource
include HTTPCalls::Create

def self.url(*)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
describe MangoPay::PayIn::Mbway::Direct, type: :feature do
describe MangoPay::PayIn::Mbway::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('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)
Expand All @@ -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)
Expand Down
38 changes: 0 additions & 38 deletions spec/mangopay/payin_paypal_direct_spec.rb

This file was deleted.

21 changes: 21 additions & 0 deletions spec/mangopay/payin_paypal_web_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
10 changes: 5 additions & 5 deletions spec/mangopay/shared_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,23 +443,23 @@ 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

###############################################
# 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 },
Expand Down

0 comments on commit bb296db

Please sign in to comment.