public function testValidationFailsWithBadMemberCodes() { $this->transaction->setMemberCode(12345); $this->assertSame(12345, $this->transaction->getMemberCode()); $violations = Validator::validateMoneyTransferTransaction($this->transaction); $this->assertTrue(count($violations) === 0); //10 digits is ok. $this->transaction->setMemberCode(1234567890); $this->assertSame(1234567890, $this->transaction->getMemberCode()); $violations = Validator::validateMoneyTransferTransaction($this->transaction); $this->assertTrue(count($violations) === 0); //11 digits is too many. $this->transaction->setMemberCode(12345678900); $this->assertSame(12345678900, $this->transaction->getMemberCode()); $violations = Validator::validateMoneyTransferTransaction($this->transaction); $this->assertTrue(count($violations) === 1); $this->assertTrue(count($violations->get('memberCode')) === 1); }
private function generateTransactionLine(MoneyTransferTransaction $transaction) { $items = array(); $items[] = array('%1d', self::RECORD_DATA); $items[] = array('%04d', $transaction->getDestinationBankAccount()->getBankCode()); $bankName = $transaction->getDestinationBankAccount()->getBankName(); $bankNameHalfWidth = StringUtil::convertFullWidthToHalfWidthKana($bankName); $items[] = array('%s', StringUtil::stringPadRight($bankNameHalfWidth, 15, ' ')); $items[] = array('%03d', $transaction->getDestinationBankAccount()->getBranchCode()); $branchName = $transaction->getDestinationBankAccount()->getBranchName(); $branchNameHalfWidth = StringUtil::convertFullWidthToHalfWidthKana($branchName); $items[] = array('%s', StringUtil::stringPadRight($branchNameHalfWidth, 15, ' ')); //Clearing-house number $items[] = array('%04d', 0); $items[] = array('%1d', self::resolveBankAccountType($transaction->getDestinationBankAccount()->getType())); $items[] = array('%07d', $transaction->getDestinationBankAccount()->getNumber()); $holderName = $transaction->getDestinationBankAccount()->getHolderName(); $holderNameHalfWidth = StringUtil::convertFullWidthToHalfWidthKana($holderName); $items[] = array('%s', StringUtil::stringPadRight($holderNameHalfWidth, 30, ' ')); $items[] = array('%010d', $transaction->getAmount()); //New Code: 1 (new), 2 (change), 0 (other) $items[] = array('%d', 0); if ($transaction->getMemberCode()) { $items[] = array('%010d', $transaction->getMemberCode()); } else { $items[] = array('%s', str_repeat(' ', 10)); } if ($transaction->getAffiliationCode()) { $items[] = array('%010d', $transaction->getAffiliationCode()); } else { $items[] = array('%s', str_repeat(' ', 10)); } //Transfer designation classification: 7 (Tele-Exchange) $items[] = array('%d', 7); //Identification $items[] = array('%s', ' '); $items[] = array('%s', str_repeat(' ', 7)); return StringUtil::sprintfItemGroupsToString($items); }