our $VERSION = '0.01';
+use constant SUCCESS_CODES => qw(2000 90000 900P1);
+
use constant CARD_TYPES => {
VI => 'Visa',
MC => 'MasterCard',
receipt_number sales_number uuid guid
date
card_type cardholder
- total_amount
+ total_amount taxes
avs_response cvv2_response
));
+
+ # Just in case someone tries to call taxes() *before* submit()
+ $self->taxes( {} );
}
# OnlinePayment's get_fields now filters out undefs in 3.x. :(
$data{MerchantNumber} = $self->merchant_id;
- $data{xxxCard_Number} =~ tr/ //d;
+ $data{xxxCard_Number} =~ tr/- //d;
$data{xxxCard_Number} =~ s/^[^3-6]/4/ if $self->test_transaction;
my ($y, $m) = $self->parse_expdate($content{exp_date});
}
}
+sub extract_taxes {
+ my ($self, $response) = @_;
+
+ my %taxes;
+
+ my $products = $response->{Products};
+ return unless $products;
+
+ foreach my $node (@$products) {
+ my $flags = $node->{flags};
+ if ($flags &&
+ grep($_ eq '{TAX}', @$flags) &&
+ grep($_ eq '{CALCULATED}', @$flags))
+ {
+ $taxes{ $node->{code} } = $node->{subtotal};
+ }
+ }
+
+ return %taxes;
+}
+
# Parse the server's response and set various fields
#
sub parse_response {
SuppressEmpty => undef,
);
- my $code = $self->result_code($response->{Page});
- $self->is_success($code eq '2000' || $code eq '90000' || $code eq '900P1');
-
$self->infuse($response,
result_code => 'Page',
error_message => 'Verbiage',
total_amount => 'TotalAmount',
);
+ $self->is_success(scalar grep $self->result_code eq $_, SUCCESS_CODES);
+
# Completely undocumented field that sometimes override <Verbiage>
$self->error_message($response->{Error}) if $response->{Error};
+
+ # Delete error_message if transaction was successful
+ $self->error_message(undef) if $self->is_success;
$self->card_type(CARD_TYPES->{$self->card_type});
- $self->{products_raw} = $response->{Products};
+ $self->taxes( { $self->extract_taxes($response) } );
return $self;
}
$txn->content(
action => 'Normal Authorization',
- type => 'Visa',
- card_number => '0000000000000000',
+ type => 'Visa', # Optional
+ card_number => '4111 1111 1111 1111',
exp_date => '2004-07',
- cvv2 => '000', # Optional
+ cvv2 => '000', # Optional
name => "Fr\x{e9}d\x{e9}ric Bri\x{e8}re",
company => '',
phone => '(555) 555-1212',
email => 'fbriere@fbriere.net',
- description => 'Online purchase',
amount => 49.95,
currency => 'CAD',
taxes => 'GST PST',
+ description => 'Test transaction',
);
$txn->submit;
=head1 DESCRIPTION
-Business::OnlinePayment::InternetSecure is an implementation of
-L<Business::OnlinePayment> that allows for processing online credit card
+C<Business::OnlinePayment::InternetSecure> is an implementation of
+C<Business::OnlinePayment> that allows for processing online credit card
payments through InternetSecure.
See L<Business::OnlinePayment> for more information about the generic
=head1 CREATOR
-Object creation is done via L<Business::OnlinePayment>; see its manpage for
-details. The I<merchant_id> processor option is required, and corresponds
+Object creation is done via C<Business::OnlinePayment>; see its manpage for
+details. The B<merchant_id> processor option is required, and corresponds
to the merchant ID assigned to you by InternetSecure.
=head1 METHODS
-(Other methods are also available -- see L<Business::OnlinePayment> for more
-details.)
-
-=head2 Before order submission
+=head2 Transaction setup and transmission
=over 4
=item content( CONTENT )
-Sets up the data prior to a transaction (overwriting any previous data by the
-same occasion). CONTENT is an associative array (hash), containing some of
-the following fields:
+Sets up the data prior to a transaction. CONTENT is an associative array
+(hash), containing some of the following fields:
=over 4
=item action (required)
What to do with the transaction. Only C<Normal Authorization> is supported
-for the moment.
+at the moment.
=item type
=item card_number (required)
-Credit card number. Spaces are allowed, and will be automatically removed.
+Credit card number. Spaces and dashes are automatically removed.
=item exp_date (required)
-Credit card expiration date. Since L<Business::OnlinePayment> does not specify
+Credit card expiration date. Since C<Business::OnlinePayment> does not specify
any syntax, this module is rather lax regarding what it will accept. The
-recommended syntax is I<YYYY-MM>, but forms such as I<MM/YYYY> or I<MMYY> are
+recommended syntax is C<YYYY-MM>, but forms such as C<MM/YYYY> or C<MMYY> are
allowed as well.
=item cvv2
=item description
-A short description of the purchase. See L<"Products list syntax"> for
+A short description of the transaction. See L<"Products list syntax"> for
an alternate syntax that allows a list of products to be specified.
=item amount (usually required)
=item name / company / address / city / state / zip / country / phone / email
-Customer information. B<Country> should be a two-letter code taken from ISO
+Customer information. B<country> should be a two-letter code taken from ISO
3166-1.
=back
+=item submit()
+
+Submit the transaction to InternetSecure.
+
=back
-=head2 After order submission
+=head2 Post-submission methods
=over 4
+=item is_success()
+
+Returns true if the transaction was submitted successfully.
+
+=item result_code()
+
+Response code returned by InternetSecure.
+
+=item error_message()
+
+Error message if the transaction was unsuccessful; C<undef> otherwise. (You
+should not rely on this to test whether a transaction was successful; use
+B<is_success>() instead.)
+
=item receipt_number()
-Receipt number of this transaction; this is actually a string, unique to all
+Receipt number (a string, actually) of this transaction, unique to all
InternetSecure transactions.
=item sales_number()
B<guid>() is provided as an alias to this method.
+=item authorization()
+
+Authorization code for this transaction.
+
+=item avs_response() / cvv2_response()
+
+Results of the AVS and CVV2 checks. See the InternetSecure documentation for
+the list of possible values.
+
=item date()
Date and time of the transaction. Format is C<YYYY/MM/DD hh:mm:ss>.
Total amount billed for this order, including taxes.
+=item taxes()
+
+Returns a I<reference> to a hash that maps tax names (such as C<GST>) to the
+amount that was billed for each.
+
=item cardholder()
Cardholder's name. This is currently a mere copy of the B<name> field passed
-to B<submit()>.
+to B<submit>().
=item card_type()
=back
-=item avs_response() / cvv2_response()
-
-Results of the AVS and CVV2 checks. See the InternetSecure documentation for
-the list of possible values.
-
-=item products_raw()
-
-...
-
=back
=head2 Products list syntax
-Optionally, the B<description> field of B<content()> can contain a reference
+Optionally, the B<description> field of B<content>() can contain a reference
to an array of products, instead of a simple string. Each element of this
array represents a different product, and must be a reference to a hash with
the following fields:
=item taxes
Taxes that should be automatically added to this product. If specified, this
-overrides the B<taxes> field passed to B<content()>.
+overrides the B<taxes> field passed to B<content>().
=back
-When using a products list, the B<amount> field passed to B<content()> should
+When using a products list, the B<amount> field passed to B<content>() should
be left undefined.
Since communication to/from InternetSecure is encoded with UTF-8, all Unicode
characters are theoretically available when submitting information via
-B<submit()>. (Further restrictions may be imposed by InternetSecure itself.)
+B<submit>(). (Further restrictions may be imposed by InternetSecure itself.)
-When using non-ASCII characters, all data provided to B<submit()> should either
+When using non-ASCII characters, all data provided to B<submit>() should either
be in the current native encoding (typically latin-1, unless it was modified
via the C<encoding> pragma), or be decoded via the C<Encode> module.
-Conversely, all data returned after calling B<submit()> will be automatically
+Conversely, all data returned after calling B<submit>() will be automatically
decoded.