summaryrefslogtreecommitdiff
path: root/BatchPayment/Item.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-01-31 20:16:10 -0800
committerMark Wells <mark@freeside.biz>2013-01-31 20:16:10 -0800
commit1bd6506437d1329616ee97321187b1868f6a76de (patch)
treedbb84a141084d8f2ee5839b4124f5ae125d0afd3 /BatchPayment/Item.pm
parent0bf7a1ffc63873be09e848b900d89eb23cb99beb (diff)
changes for cardfortress
Diffstat (limited to 'BatchPayment/Item.pm')
-rw-r--r--BatchPayment/Item.pm67
1 files changed, 65 insertions, 2 deletions
diff --git a/BatchPayment/Item.pm b/BatchPayment/Item.pm
index d9a3ec7..8a203ac 100644
--- a/BatchPayment/Item.pm
+++ b/BatchPayment/Item.pm
@@ -106,6 +106,10 @@ Company name.
Billing address fields. Credit card processors may use these (especially
zip) for authentication.
+=item phone
+
+Customer phone number.
+
=cut
has [ qw(
@@ -119,6 +123,7 @@ has [ qw(
state
country
zip
+ phone
) ] => ( is => 'rw', isa => 'Str', default => '' );
=back
@@ -129,7 +134,9 @@ has [ qw(
=item process_date
-The date requested for processing.
+The date requested for processing. This is meaningful only if the
+processor allows different processing dates for items in the same
+batch.
=item invoice_number
@@ -193,7 +200,54 @@ Credit card expiration, MMYY format.
=cut
has card_number => ( is => 'rw', isa => 'Str' );
-has expiration => ( is => 'rw', isa => 'Str' );
+has ['expiration_month', 'expiration_year'] => ( is => 'rw', isa => 'Int' );
+
+sub expiration {
+ # gets/sets expiration_month and _year in MMYY format
+ my $self = shift;
+ my $arg = shift;
+ if ( $arg ) {
+ # well, we said it's in MMYY format
+ my ($m, $y) = _parse_expiration($arg);
+ $self->expiration_month($m);
+ $self->expiration_year($y);
+ }
+ return sprintf('%02d/%02d',
+ $self->expiration_month,
+ $self->expiration_year % 2000);
+}
+
+sub _parse_expiration {
+ my $arg = shift;
+ if ( $arg =~ /^(\d\d)(\d\d)$/ ) {
+ return ($1, 2000 + $2);
+ } elsif ( $arg =~ /^(\d\d?)\W(\d\d)$/ ) {
+ return ($1, 2000 + $2);
+ } elsif ( $arg =~ /^(\d\d?)\W(\d\d\d\d)$/ ) {
+ return ($1, $2);
+ } elsif ( $arg =~ /^(\d\d?)\W\d\d?\W(\d\d\d\d)$/) {
+ return ($1, $3);
+ } else {
+ die "can't parse expiration date '$arg'";
+ }
+}
+
+sub payinfo {
+ # gets/sets either the card number, or the account number + routing code
+ # depending on the payment type
+ my $self = shift;
+ if ( $self->payment_type eq 'CC' ) {
+ $self->card_number(@_);
+ } elsif ( $self->payment_type eq 'ECHECK' ) {
+ my $arg = shift;
+ if ( $arg ) {
+ $arg =~ /^(\d+)@(\d+)$/ or die "Validation failed for payinfo";
+ $self->account_number($1);
+ $self->routing_code($2);
+ }
+ return ($self->account_number . '@' . $self->routing_code);
+ }
+}
=back
@@ -273,6 +327,15 @@ has [qw(
has check_number => ( is => 'rw', isa => 'Int' );
+around 'BUILDARGS' => sub {
+ my ($orig, $self, %args) = @_;
+ if ( $args{expiration} ) {
+ @args{'expiration_month', 'expiration_year'} =
+ _parse_expiration($args{expiration});
+ }
+ $self->$orig(%args);
+};
+
__PACKAGE__->meta->make_immutable;
1;