From 55952b10a96cb53c195702fad76458897db4a2b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergiusz=20Wo=C5=BAnicki?= Date: Wed, 5 Mar 2014 12:08:58 +0100 Subject: [PATCH] Local bank accounts Local bank accounts : Evolution of the method to accept new formats - addition of 5 new types of BankAccounts available (IBAN,GB, US, CA, Other) - documentation: http://docs.mangopay.com/api-references/bank-accounts/ --- lib/mangopay/bank_account.rb | 6 ++- spec/lib/mangopay/bank_account_spec.rb | 63 +++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/lib/mangopay/bank_account.rb b/lib/mangopay/bank_account.rb index 0d754b0..3377c60 100644 --- a/lib/mangopay/bank_account.rb +++ b/lib/mangopay/bank_account.rb @@ -1,8 +1,12 @@ module MangoPay class BankAccount < Resource - include MangoPay::HTTPCalls::Create include MangoPay::HTTPCalls::Fetch + def self.create(user_id, params) + type = params.fetch(:Type) { |no_symbol_key| params.fetch('Type') } + MangoPay.request(:post, "#{url(user_id)}/#{type}", params) + end + # Fetches: # - list of bank accounts belonging to the given +user_id+ # - or single bank account belonging to the given +user_id+ with the given +bank_account_id+. diff --git a/spec/lib/mangopay/bank_account_spec.rb b/spec/lib/mangopay/bank_account_spec.rb index a94e3ff..9613145 100644 --- a/spec/lib/mangopay/bank_account_spec.rb +++ b/spec/lib/mangopay/bank_account_spec.rb @@ -2,11 +2,72 @@ describe MangoPay::BankAccount do include_context 'bank_accounts' + + def create(params) + params_fixed = { OwnerName: 'John', OwnerAddress: 'Here' }.merge(params) + MangoPay::BankAccount.create(new_natural_user['Id'], params_fixed) + end describe 'CREATE' do - it 'creates a new bank detail' do + + it 'creates a new IBAN bank detail' do expect(new_bank_account['Id']).not_to be_nil end + + it 'creates a new GB bank detail' do + created = create({ + Type: 'GB', + AccountNumber: '234234234234', + SortCode: '234334', + }) + expect(created['Id']).not_to be_nil + expect(created['Type']).to eq('GB') + expect(created['AccountNumber']).to eq('234234234234') + expect(created['SortCode']).to eq('234334') + end + + it 'creates a new US bank detail' do + created = create({ + Type: 'US', + AccountNumber: '234234234234', + ABA: '234334789', + }) + expect(created['Id']).not_to be_nil + expect(created['Type']).to eq('US') + expect(created['AccountNumber']).to eq('234234234234') + expect(created['ABA']).to eq('234334789') + end + + it 'creates a new CA bank detail' do + created = create({ + Type: 'CA', + BankName: 'TestBankName', + BranchCode: '12345', + AccountNumber: '234234234234', + InstitutionNumber: '123', + }) + expect(created['Id']).not_to be_nil + expect(created['Type']).to eq('CA') + expect(created['BankName']).to eq('TestBankName') + expect(created['BranchCode']).to eq('12345') + expect(created['AccountNumber']).to eq('234234234234') + expect(created['InstitutionNumber']).to eq('123') + end + + it 'creates a new OTHER bank detail' do + created = create({ + Type: 'OTHER', + Country: 'FR', + AccountNumber: '234234234234', + BIC: 'BINAADADXXX', + }) + expect(created['Id']).not_to be_nil + expect(created['Type']).to eq('OTHER') + expect(created['Country']).to eq('FR') + expect(created['AccountNumber']).to eq('234234234234') + expect(created['BIC']).to eq('BINAADADXXX') + end + end describe 'FETCH' do