Skip to content

Commit

Permalink
Merge pull request #241 from Mangopay/feature/bin_metadata_endpoint
Browse files Browse the repository at this point in the history
feature / Integrated bin metadata endpoint
  • Loading branch information
iulian03 authored Feb 8, 2024
2 parents c311369 + 11c4103 commit 80ae8d2
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 56 deletions.
1 change: 1 addition & 0 deletions lib/mangopay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module MangoPay
autoload :Regulatory, 'mangopay/regulatory'
autoload :Deposit, 'mangopay/deposit'
autoload :InstantConversion, 'mangopay/instant_conversion'
autoload :PaymentMethodMetadata, 'mangopay/payment_method_metadata'

# temporary
autoload :Temp, 'mangopay/temp'
Expand Down
13 changes: 13 additions & 0 deletions lib/mangopay/payment_method_metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module MangoPay
class PaymentMethodMetadata < Resource
include HTTPCalls::Fetch
include HTTPCalls::Update

class << self
def get_metadata(metadata)
url = "#{MangoPay.api_path}/payment-methods/metadata"
MangoPay.request(:post, url, metadata)
end
end
end
end
5 changes: 2 additions & 3 deletions spec/mangopay/deposit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe 'CREATE' do
it 'creates a new deposit' do
author = new_natural_user
card_registration = new_card_registration_completed_for_deposit
card_registration = new_card_registration_completed
deposit = create_new_deposit(card_registration['CardId'], author['Id'])

assert_deposit(deposit, card_registration['CardId'], author["Id"])
Expand All @@ -15,7 +15,7 @@
describe 'GET' do
it 'get an existing deposit' do
author = new_natural_user
card_registration = new_card_registration_completed_for_deposit
card_registration = new_card_registration_completed
deposit = create_new_deposit(card_registration['CardId'], author['Id'])

assert_deposit(deposit, card_registration['CardId'], author["Id"])
Expand Down Expand Up @@ -64,7 +64,6 @@ def assert_deposit(deposit, card_reg_id, author_id)
expect(deposit['CardId']).to eq(card_reg_id)
expect(deposit['AuthorId']).to eq(author_id)
expect(deposit['SecureModeReturnURL']).not_to be_nil
expect(deposit['SecureModeRedirectURL']).not_to be_nil
expect(deposit['PaymentType']).not_to be_nil
expect(deposit['ExecutionType']).not_to be_nil
expect(deposit['StatementDescriptor']).not_to be_nil
Expand Down
2 changes: 2 additions & 0 deletions spec/mangopay/payin_preauthorized_direct_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def check_type_and_status(payin)
describe 'CREATE' do
it 'creates a preauthorized direct payin' do
created = new_payin_preauthorized_direct
# wait for the transactions to be created
sleep(2)
transactions = MangoPay::PreAuthorization.transactions(created['PreauthorizationId'])
expect(created['Id']).not_to be_nil
expect(transactions[0]['Status']).to eq('SUCCEEDED')
Expand Down
15 changes: 15 additions & 0 deletions spec/mangopay/payment_method_metadata_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe MangoPay::PaymentMethodMetadata, type: :feature do
include_context 'payment_method_metadata'

describe 'GET PAYMENT METHOD METADATA' do
it 'gets a new payment method metadata' do
metadata = get_payment_method_metadata

expect(metadata).not_to be_nil
expect(metadata['IssuerCountryCode']).not_to be_nil
expect(metadata['IssuingBank']).not_to be_nil
expect(metadata['BinData']).not_to be_nil
expect(metadata['CardType']).not_to be_nil
end
end
end
2 changes: 1 addition & 1 deletion spec/mangopay/recurring_payin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe 'CREATE' do
it 'creates a recurring payment' do
cardreg = new_card_registration_3dsecure_completed
cardreg = new_card_registration_completed
wallet = new_wallet
recurring = MangoPay::PayIn::RecurringPayments::Recurring.create(
AuthorId: new_natural_user['Id'],
Expand Down
79 changes: 27 additions & 52 deletions spec/mangopay/shared_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,51 +379,7 @@ def create_new_document(user)
data = {
data: cardreg['PreregistrationData'],
accessKeyRef: cardreg['AccessKey'],
cardNumber: 4970105191923460,
cardExpirationDate: 1226,
cardCvx: 123 }

res = Net::HTTP.post_form(URI(cardreg['CardRegistrationURL']), data)
raise Exception, [res, res.body] unless res.is_a?(Net::HTTPOK) && res.body.start_with?('data=')

cardreg['RegistrationData'] = res.body

# 3rd step: update (fills-in CardId) and return it
MangoPay::CardRegistration.update(cardreg['Id'],
RegistrationData: cardreg['RegistrationData'])
end

let(:new_card_registration_3dsecure_completed) do
# 1st step: create
cardreg = new_card_registration

# 2nd step: tokenize by payline (fills-in RegistrationData)
data = {
data: cardreg['PreregistrationData'],
accessKeyRef: cardreg['AccessKey'],
cardNumber: 4970105191923460,
cardExpirationDate: 1224,
cardCvx: 123 }

res = Net::HTTP.post_form(URI(cardreg['CardRegistrationURL']), data)
raise Exception, [res, res.body] unless res.is_a?(Net::HTTPOK) && res.body.start_with?('data=')

cardreg['RegistrationData'] = res.body

# 3rd step: update (fills-in CardId) and return it
MangoPay::CardRegistration.update(cardreg['Id'],
RegistrationData: cardreg['RegistrationData'])
end

let(:new_card_registration_completed_for_deposit) do
# 1st step: create
cardreg = new_card_registration

# 2nd step: tokenize by payline (fills-in RegistrationData)
data = {
data: cardreg['PreregistrationData'],
accessKeyRef: cardreg['AccessKey'],
cardNumber: 4970105181818183,
cardNumber: 4970107111111119,
cardExpirationDate: 1226,
cardCvx: 123 }

Expand Down Expand Up @@ -514,8 +470,8 @@ def create_new_document(user)
MangoPay::PayIn::Klarna::Web.create(
AuthorId: new_natural_user['Id'],
CreditedWalletId: new_wallet['Id'],
DebitedFunds: {Currency: 'EUR', Amount: 400},
Fees: {Currency: 'EUR', Amount: 10},
DebitedFunds: { Currency: 'EUR', Amount: 400 },
Fees: { Currency: 'EUR', Amount: 10 },
ReturnURL: 'http://www.my-site.com/returnURL',
LineItems: [
{
Expand Down Expand Up @@ -574,8 +530,8 @@ def create_new_document(user)
MangoPay::PayIn::Ideal::Web.create(
AuthorId: new_natural_user['Id'],
CreditedWalletId: new_wallet['Id'],
DebitedFunds: {Currency: 'EUR', Amount: 400},
Fees: {Currency: 'EUR', Amount: 10},
DebitedFunds: { Currency: 'EUR', Amount: 400 },
Fees: { Currency: 'EUR', Amount: 10 },
ReturnURL: 'http://www.my-site.com/returnURL',
Bic: 'REVOLT21',
StatementDescriptor: "test",
Expand All @@ -590,8 +546,8 @@ def create_new_document(user)
MangoPay::PayIn::Giropay::Web.create(
AuthorId: new_natural_user['Id'],
CreditedWalletId: new_wallet['Id'],
DebitedFunds: {Currency: 'EUR', Amount: 400},
Fees: {Currency: 'EUR', Amount: 10},
DebitedFunds: { Currency: 'EUR', Amount: 400 },
Fees: { Currency: 'EUR', Amount: 10 },
ReturnURL: 'http://www.my-site.com/returnURL',
StatementDescriptor: "test",
Tag: 'Test PayIn/Giropay/Web'
Expand Down Expand Up @@ -785,7 +741,7 @@ def create_new_payin_bankwire_direct(to_wallet, amnt = 1000)
# wallet with money
###############################################
#
let(:new_wallet_with_money){ create_new_wallet_with_money(new_natural_user) }
let(:new_wallet_with_money) { create_new_wallet_with_money(new_natural_user) }

def create_new_wallet_with_money(user)
wallet = MangoPay::Wallet.create(
Expand Down Expand Up @@ -940,6 +896,7 @@ def create_new_deposit(card_registration_id, author_id)
###############################################
shared_context 'instant_conversion' do
include_context 'payins'

def get_conversion_rate(debited_currency, credited_currency)
MangoPay::InstantConversion.get_rate(debited_currency, credited_currency, params = {})
end
Expand Down Expand Up @@ -971,4 +928,22 @@ def create_instant_conversion()
def get_instant_conversion(id)
MangoPay::InstantConversion.get(id, params = {})
end
end

###############################################
# payment methods metadata
###############################################
shared_context 'payment_method_metadata' do
include_context 'payins'

def get_payment_method_metadata

wlt = new_wallet
pay_in = create_new_payin_card_direct(wlt, 1000)

MangoPay::PaymentMethodMetadata.get_metadata(
Type: 'BIN',
Bin: pay_in['CardInfo']['BIN']
)
end
end
5 changes: 5 additions & 0 deletions spec/mangopay/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
it 'fetches list with two transactions after payin and payout done' do
payin = new_payin_card_direct
payout = create_new_payout_bankwire(payin)
# wait for the transactions to be created
sleep(2)
transactions = MangoPay::Transaction.fetch(new_wallet['Id'])

expect(transactions).to be_kind_of(Array)
Expand All @@ -37,6 +39,9 @@
payout = create_new_payout_bankwire(payin)
wallet_id = new_wallet['Id']

# wait for the transactions to be created
sleep(2)

by_nature_reg = MangoPay::Transaction.fetch(wallet_id, {'Nature' => 'REGULAR'})
by_nature_ref = MangoPay::Transaction.fetch(wallet_id, {'Nature' => 'REFUND'})
expect(by_nature_reg.count).to eq 2
Expand Down
2 changes: 2 additions & 0 deletions spec/mangopay/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
it 'fetches list with two transactions after payin and payout done' do
payin = new_payin_card_direct
payout = create_new_payout_bankwire(payin)
# wait for the transactions to be created
sleep(2)
transactions = MangoPay::User.transactions(new_natural_user['Id'])

expect(transactions).to be_kind_of(Array)
Expand Down
5 changes: 5 additions & 0 deletions spec/mangopay/wallet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
it 'fetches list with two transactions after payin and payout done' do
payin = new_payin_card_direct
payout = create_new_payout_bankwire(payin)
# wait for the transactions to be created
sleep(2)
transactions = MangoPay::Wallet.transactions(new_wallet['Id'])

expect(transactions).to be_kind_of(Array)
Expand All @@ -63,6 +65,9 @@
payout = create_new_payout_bankwire(payin)
wallet_id = new_wallet['Id']

# wait for the transactions to be created
sleep(2)

by_nature_reg = MangoPay::Wallet.transactions(wallet_id, {'Nature' => 'REGULAR'})
by_nature_ref = MangoPay::Wallet.transactions(wallet_id, {'Nature' => 'REFUND'})
expect(by_nature_reg.count).to eq 2
Expand Down

0 comments on commit 80ae8d2

Please sign in to comment.