Finance-Card-Discover

 view release on metacpan or  search on metacpan

lib/Finance/Card/Discover/Account.pm  view on Meta::CPAN

    }

    return @transactions;
}

sub _ofx_request {
    my ($self, %params) = @_;

    my $dt = _dt_to_ofx(DateTime::Tiny->now);

    my ($trans, $start, $end);
    if ($trans = $params{transactions}) {
        ($start, $end) = @params{qw(start end)};
        $_ &&= _dt_to_ofx($_) for ($start, $end);
    }

    my $xml = <<"    __EOF__";
<?xml version="1.0"?>
<?OFX OFXHEADER="200" VERSION="211" SECURITY="NONE" OLDFILEUID="NONE"
  NEWFILEUID="NONE"?>
<OFX>
  <SIGNONMSGSRQV1>
    <SONRQ>
      <DTCLIENT>$dt</DTCLIENT>
      <USERID>@{[ $self->card->{username } ]}</USERID>
      <USERPASS>@{[ $self->card->{password} ]}</USERPASS>
      <LANGUAGE>ENG</LANGUAGE>
      <FI><ORG>Discover Financial Services</ORG><FID>7101</FID></FI>
      <APPID>QWIN</APPID><APPVER>1800</APPVER>
    </SONRQ>
  </SIGNONMSGSRQV1>
  <CREDITCARDMSGSRQV1>
    <CCSTMTTRNRQ>
      <TRNUID>${$}_$dt</TRNUID>
      <CCSTMTRQ>
        <CCACCTFROM><ACCTID>@{[ $self->number ]}</ACCTID></CCACCTFROM>
        <INCTRAN>
          @{[ $start ? "<DTSTART>$start</DTSTART>" : '' ]}
          @{[ $end ? "<DTEND>$end</DTEND>" : '' ]}
          <INCLUDE>@{[ $trans ? 'Y' : 'N' ]}</INCLUDE>
        </INCTRAN>
      </CCSTMTRQ>
    </CCSTMTTRNRQ>
  </CREDITCARDMSGSRQV1>
</OFX>
    __EOF__

    my $ua = $self->card->ua;
    my $uri = URI->new('https://ofx.discovercard.com/');
    my $res = $self->card->{response} = $ua->post(
        $uri,
        if_ssl_cert_subject => "/CN=(?i)\Q@{[$uri->host]}\E\$",
        content_type        => 'application/x-ofx',
        content             => $xml,
    );
    return unless $res->is_success;

    require XML::LibXML;
    $XML_PARSER ||= XML::LibXML->new;
    my $dom = eval {
        $XML_PARSER->parse_string($res->decoded_content);
    } or croak "Failed to parse response XML: $@";
    return $dom;
}

sub _dt_to_ofx {
    my ($dt) = @_;
    sprintf '%d%02d%02d%02d%02d%02d.000', $dt->year, $dt->month,
        $dt->day, $dt->hour, $dt->minute, $dt->second;
}

sub profile {
    my ($self) = @_;

    my $data = $self->card->_request(
        cardsubid   => $self->id,
        cardtype    => $self->type,
        msgnumber   => 0,
        profilename => 'billing',
        request     => 'getprofile',
    );
    return unless $data;

    require Finance::Card::Discover::Account::Profile;
    return Finance::Card::Discover::Account::Profile->new(
        $data, account => $self
    );
}

sub soan {
    my ($self) = @_;

    my $data = $self->card->_request(
        cardsubid  => $self->id,
        cardtype   => $self->type,
        clienttype => 'thin',
        cpntype    => 'MA',  # ?
        latched    => 'Y',   # ?
        msgnumber  => 2,
        request    => 'ocode',

        # TODO: test to see if this setting alters the expiration from the
        # default value. Currently, a user must call or send a message to
        # DiscoverCard to cancel a SOAN.
        validfor   => undef,
    );
    return unless $data;

    require Finance::Card::Discover::Account::SOAN;
    return Finance::Card::Discover::Account::SOAN->new(
        $data, account => $self
    );
}

sub soan_transactions {
    my ($self) = @_;

    my $data = $self->card->_request(
        cardtype  => $self->type,
        cardsubid => $self->id,
        msgnumber => 1,



( run in 1.995 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )