Business-OnlinePayment-InternetSecure

 view release on metacpan or  search on metacpan

t/30parse.t  view on Meta::CPAN

# vim:set syntax=perl:

use constant FIELDS => qw(
			result_code authorization error_message
			receipt_number order_number
			date
			card_type
			avs_code cvv2_response
			total_amount tax_amounts
			);

use constant RESULTS => (
				{
					is_success	=> 1,
					result_code	=> '2000',
					authorization	=> 'T00000',
					error_message	=> undef,
					receipt_number	=> '1096019995.5012',
					order_number	=> 0,
					date		=> '2003/12/17 09:59:58',
					card_type	=> undef,
					avs_code	=> undef,
					cvv2_response	=> undef,
					total_amount	=> 3.88,
					tax_amounts	=> { GST => 0.25 },
					uuid		=> 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
					guid		=> 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6',
				},
				{
					is_success	=> 0,
					result_code	=> '98e05',
					authorization	=> undef,
					error_message	=> 'Real error message',
					receipt_number	=> '1096021915.5853',
					order_number	=> 729,
					date		=> '2003/12/17 10:31:58',
					card_type	=> 'Visa',
					avs_code	=> undef,
					cvv2_response	=> undef,
					total_amount	=> 3.88,
					tax_amounts	=> { GST => 0.25,
								PST => 0.27 },
					uuid		=> undef,
					guid		=> undef,
				},
			);


use Test::More tests => 1 + scalar(RESULTS) * (1 + 1 + scalar(FIELDS));

BEGIN { use_ok('Business::OnlinePayment') };



my $txn = new Business::OnlinePayment 'InternetSecure', merchant_id => '0000';

$/ = '';
foreach my $results (RESULTS) {
	my $xml = <DATA>;
	$txn->parse_response($xml);

	is($txn->server_response, $xml, 'server_response');

	if ($results->{is_success}) {
		ok($txn->is_success, 'expecting success');
	} else {
		ok(!$txn->is_success, 'expecting failure');
	}

	foreach (FIELDS) {
		no strict 'refs';
		is_deeply($txn->$_, $results->{$_}, $_);
	}
}


__DATA__
<?xml version="1.0" encoding="UTF-8"?>
<TranxResponse>
  <MerchantNumber>4994</MerchantNumber>
  <ReceiptNumber>1096019995.5012</ReceiptNumber>
  <SalesOrderNumber>0</SalesOrderNumber>
  <xxxName>John Smith</xxxName>
  <Date>2003/12/17 09:59:58</Date>
  <CardType>Test Card Number</CardType>
  <Page>2000</Page>
  <ApprovalCode>T00000</ApprovalCode>
  <Verbiage>Test Approved</Verbiage>
  <TotalAmount>3.88</TotalAmount>
  <Products>
    <product>
      <code>001</code>
      <description>Test Product 1</description>
      <quantity>1</quantity>
      <price>3.10</price>
      <subtotal>3.10</subtotal>
      <flags>
        <flag>{USD}</flag>
	<flag>{GST}</flag>
	<flag>{TEST}</flag>
      </flags>
    </product>
    <product>
      <code>010</code>
      <description>Test Product 2</description>
      <quantity>1</quantity>
      <price>0.20</price>
      <subtotal>0.20</subtotal>
      <flags>
	<flag>{GST}</flag>
	<flag>{TEST}</flag>
      </flags>
    </product>
    <product>
      <code>020</code>
      <description>Test Product 3</description>
      <quantity>1</quantity>

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.044 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )