Skip to content

Commit

Permalink
Write test for bank account credits
Browse files Browse the repository at this point in the history
  • Loading branch information
rylwin committed May 2, 2012
1 parent ee0674c commit 1e031d4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 26 deletions.
11 changes: 6 additions & 5 deletions lib/payments_gateway/bank_account.rb
Expand Up @@ -37,7 +37,6 @@ def initialize(account = nil, transaction_password = nil)
nil
end


def debit_setup(attributes={})
base_attributes = {
:pg_merchant_id => self.merchant_id,
Expand All @@ -51,14 +50,16 @@ def debit_setup(attributes={})
end


def credit_setup(amount)
{:pg_merchant_id => self.merchant_id,
def credit_setup(attributes={})
base_attributes = {
:pg_merchant_id => self.merchant_id,
:pg_password => @transaction_password,
:pg_transaction_type => EFT_CREDIT,
:pg_total_amount => amount,
:pg_client_id => self.client_id,
:pg_payment_method_id => self.payment_method_id,
:pg_merchant_data_1 => 'just a test'}
}

base_attributes.merge(attributes)
end

private
Expand Down
15 changes: 8 additions & 7 deletions lib/payments_gateway/credit_card.rb
Expand Up @@ -2,22 +2,23 @@ module PaymentsGateway

class CreditCard

include PaymentsGateway::Attributes

def initialize(account = nil)
@field_map = {}
@data = {}

setup_fields
parse(account) unless account.nil?

if account.is_a?(Hash)
self.attributes = account
elsif !account.nil?
parse(account)
end

nil
end

def to_pg_hash
retval = {}
@data.each { |key, value| retval[ @field_map[key] ] = value }
return retval
end

private

def setup_fields
Expand Down
2 changes: 1 addition & 1 deletion lib/payments_gateway/merchant_account.rb
Expand Up @@ -134,7 +134,7 @@ def update_credit_card
raise 'update_credit_card method not implemented yet'
end

def delete_credit_cardi(payment_method_id)
def delete_credit_card(payment_method_id)
delete_payment_method(payment_method_id)
end

Expand Down
33 changes: 33 additions & 0 deletions spec/bank_account_spec.rb
@@ -0,0 +1,33 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe PaymentsGateway::BankAccount do

before(:each) do
@transaction_password = '1111111'
account_attr = {
:client_id => 0,
:payment_method_id => 1,
:merchant_id => 2
}

@bank_account = PaymentsGateway::BankAccount.new(account_attr, @transaction_password)
end

context "#debit_setup" do

before(:each) do
@attr = @bank_account.debit_setup(:pg_total_amount => 100)
end

it "should set the attributes correctly" do
@attr[:pg_total_amount].should == 100
@attr[:pg_merchant_id].should == 2
@attr[:pg_password].should == @transaction_password
@attr[:pg_transaction_type].should == PaymentsGateway::BankAccount::EFT_SALE
@attr[:pg_client_id].should == 0
@attr[:pg_payment_method_id].should == 1
end

end

end
26 changes: 13 additions & 13 deletions spec/merchant_account_spec.rb
Expand Up @@ -108,17 +108,23 @@
deleted_id.should be_true
end

it "can debit the bank account" do
pending
end
context "when I debit the bank account the transaction response" do
before(:each) do
@transaction_response = @ma.debit_bank_account(@bank_account, :pg_total_amount => 100)
end

it "can credit the bank account" do
pending
it "should be a successful transaction" do
@transaction_response.success?.should be_true
end

it "should have a valid trace number" do
@transaction_response.pg_trace_number.length.should == 36
end
end

context "when I debit the bank account the transaction response" do
context "when I credit the bank account the transaction response" do
before(:each) do
@transaction_response = @ma.debit_bank_account(@bank_account, :pg_total_amount => 100)
@transaction_response = @ma.credit_bank_account(@bank_account, :pg_total_amount => 100)
end

it "should be a successful transaction" do
Expand Down Expand Up @@ -160,12 +166,6 @@

end

context "with a bank accout and a credit card" do
it "can get a list of all payment methods" do
pending
end
end

end

end

0 comments on commit 1e031d4

Please sign in to comment.