diff --git a/lib/mangopay.rb b/lib/mangopay.rb index fb1a794..337e7af 100644 --- a/lib/mangopay.rb +++ b/lib/mangopay.rb @@ -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' diff --git a/lib/mangopay/payment_method_metadata.rb b/lib/mangopay/payment_method_metadata.rb new file mode 100644 index 0000000..fc6d9ac --- /dev/null +++ b/lib/mangopay/payment_method_metadata.rb @@ -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 \ No newline at end of file diff --git a/spec/mangopay/deposit_spec.rb b/spec/mangopay/deposit_spec.rb index edd01cb..1e85900 100644 --- a/spec/mangopay/deposit_spec.rb +++ b/spec/mangopay/deposit_spec.rb @@ -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"]) @@ -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"]) @@ -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 diff --git a/spec/mangopay/payin_preauthorized_direct_spec.rb b/spec/mangopay/payin_preauthorized_direct_spec.rb index 4052732..caace2e 100644 --- a/spec/mangopay/payin_preauthorized_direct_spec.rb +++ b/spec/mangopay/payin_preauthorized_direct_spec.rb @@ -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') diff --git a/spec/mangopay/payment_method_metadata_spec.rb b/spec/mangopay/payment_method_metadata_spec.rb new file mode 100644 index 0000000..7d903f0 --- /dev/null +++ b/spec/mangopay/payment_method_metadata_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/mangopay/recurring_payin_spec.rb b/spec/mangopay/recurring_payin_spec.rb index 497f1d8..a6eef32 100644 --- a/spec/mangopay/recurring_payin_spec.rb +++ b/spec/mangopay/recurring_payin_spec.rb @@ -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'], diff --git a/spec/mangopay/shared_resources.rb b/spec/mangopay/shared_resources.rb index 1c50c03..e23193f 100644 --- a/spec/mangopay/shared_resources.rb +++ b/spec/mangopay/shared_resources.rb @@ -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 } @@ -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: [ { @@ -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", @@ -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' @@ -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( @@ -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 @@ -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 \ No newline at end of file diff --git a/spec/mangopay/transaction_spec.rb b/spec/mangopay/transaction_spec.rb index f0a6a6a..34b6fe0 100644 --- a/spec/mangopay/transaction_spec.rb +++ b/spec/mangopay/transaction_spec.rb @@ -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) @@ -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 diff --git a/spec/mangopay/user_spec.rb b/spec/mangopay/user_spec.rb index 8e30f1a..b42c089 100644 --- a/spec/mangopay/user_spec.rb +++ b/spec/mangopay/user_spec.rb @@ -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) diff --git a/spec/mangopay/wallet_spec.rb b/spec/mangopay/wallet_spec.rb index aa441b6..cdac452 100644 --- a/spec/mangopay/wallet_spec.rb +++ b/spec/mangopay/wallet_spec.rb @@ -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) @@ -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