From af478f796dede889f5e5cffaeb6f178723c8ddcc Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Thu, 2 Apr 2015 14:46:20 -0500 Subject: [PATCH] Switched to standard fieldnames for username/password, added documentation --- BillBuddy.pm | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 94 insertions(+), 15 deletions(-) diff --git a/BillBuddy.pm b/BillBuddy.pm index 3704c84..d080aa0 100644 --- a/BillBuddy.pm +++ b/BillBuddy.pm @@ -2,13 +2,93 @@ package Business::BatchPayment::BillBuddy; use strict; +=head1 NAME + +Business::BatchPayment::BillBuddy - BillBuddy batch payment format and transport + +=head1 USAGE + +See L for general usage notes. + +=head2 SYNOPSIS + + use Business::BatchPayment; + + # Upload batch + my @items = Business::BatchPayment::Item->new( ... ); + my $batch = Business::BatchPayment->create(Batch => + batch_id => $self->batchnum, + items => \@items + ); + + my $processor = Business::BatchPayment->processor('BillBuddy', + login => 'USER_ID', + password => 'API_KEY', + host => 'xmlrpc.billbuddy.com', + path => 'v1_sandbox', + #optional... + port => 443, + debug => 1, + ); + + my $result = $processor->submit($batch); + + # this gets set by submit, and is needed for receive + my $processor_id = $batch->processor_id; + + # Download results + my @reply = $processor->receive(@process_ids); + +=head2 PROCESSOR ATTRIBUTES + +=over 4 + +=item username - the user_id provided to you by BillBuddy + +=item password - the api_key (NOT the web portal password) provided to you by BillBuddy + +=item host - the domain name for BillBuddy XMLRPC requests + +=item path - the path for BillBuddy XMLRPC requests + +=item port - the port for BillBuddy XMLRPC requests (optional, default 443) + +=item debug - print debug warnings if true, including XML requests and responses + +=back + +=head1 AUTHOR + +Jonathan Prykop, jonathan@freeside.biz + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc Business::BatchPayment::BillBuddy + +Commercial support is available from Freeside Internet Services, +L + +=head1 LICENSE AND COPYRIGHT + +Copyright 2015 Freeside Internet Services + +This program is free software; you can redistribute it and/or modify it +under the terms of either: the GNU General Public License as published +by the Free Software Foundation; or the Artistic License. + +See http://dev.perl.org/licenses/ for more information. + +=cut + use Business::BatchPayment; use Moose; with 'Business::BatchPayment::Processor'; our $VERSION = '0.01'; -has [ qw(user_id api_key host) ] => ( +has [ qw(username password host) ] => ( is => 'ro', isa => 'Str', required => 1, @@ -29,8 +109,8 @@ has 'port' => ( sub default_transport { my $self = shift; Business::BatchPayment->create('BillBuddy::Transport', - user_id => $self->user_id, - api_key => $self->api_key, + username => $self->username, + password => $self->password, host => $self->host, port => $self->port, path => $self->path, @@ -101,7 +181,6 @@ sub submit { my $self = shift; my $batch = shift; my $request = $self->format_request($batch); - warn $request if $self->debug >= 2; $self->transport->upload($request,$batch); } @@ -120,7 +199,7 @@ use XML::Writer; use Moose; extends 'Business::BatchPayment::Transport::HTTPS'; -has [ qw(user_id api_key) ] => ( +has [ qw(username password) ] => ( is => 'ro', isa => 'Str', required => 1, @@ -189,24 +268,24 @@ sub upload { # get date from batch my ($date) = $batch->process_date =~ /^(....-..-..)/; # login - my $resp = $self->xmlrpc_post('xmlrpc_tp_Login.asp','',$self->user_id,$self->api_key); + my $resp = $self->xmlrpc_post('xmlrpc_tp_Login.asp','',$self->username,$self->password); my $sid = $resp->{'ResponseData'}->{'sessionID'}; die "Could not parse sessionid from gateway response" unless $sid; # start a payment batch - $resp = $self->xmlrpc_post('xmlrpc_tp_DDRBatch_Open.asp',$sid,$self->user_id,$date); + $resp = $self->xmlrpc_post('xmlrpc_tp_DDRBatch_Open.asp',$sid,$self->username,$date); my $batchno = $resp->{'ResponseData'}->{'batchno'}; die "Could not parse batchno from gateway response" unless $batchno; $batch->processor_id($batchno); # post a payment transaction foreach my $line (split(/\n/,$request)) { - $self->xmlrpc_post('xmlrpc_tp_DDRTransaction_Add.asp',$sid,$self->user_id,$batchno,['cdataElement',$line]); + $self->xmlrpc_post('xmlrpc_tp_DDRTransaction_Add.asp',$sid,$self->username,$batchno,['cdataElement',$line]); } # close payment batch - $self->xmlrpc_post('xmlrpc_tp_DDRBatch_Close.asp',$sid,$self->user_id,$batchno); + $self->xmlrpc_post('xmlrpc_tp_DDRBatch_Close.asp',$sid,$self->username,$batchno); # submit payment batch - $self->xmlrpc_post('xmlrpc_tp_DDRBatch_Submit.asp',$sid,$self->user_id,$batchno); + $self->xmlrpc_post('xmlrpc_tp_DDRBatch_Submit.asp',$sid,$self->username,$batchno); # logout - $self->xmlrpc_post('xmlrpc_tp_Logout.asp',$sid,$self->user_id); + $self->xmlrpc_post('xmlrpc_tp_Logout.asp',$sid,$self->username); return ''; } @@ -217,20 +296,20 @@ sub download { my @processor_ids = @_; return () unless @processor_ids; # login - my $resp = $self->xmlrpc_post('xmlrpc_tp_Login.asp','',$self->user_id,$self->api_key); + my $resp = $self->xmlrpc_post('xmlrpc_tp_Login.asp','',$self->username,$self->password); my $sid = $resp->{'ResponseData'}->{'sessionID'}; die "Could not parse sessionid from gateway response" unless $sid; my @batches = (); foreach my $batchno (@processor_ids) { #get BillBuddy transaction ids for batch - $resp = $self->xmlrpc_post('xmlrpc_tp_DDRBatch_getTranList.asp',$sid,$self->user_id,$batchno); + $resp = $self->xmlrpc_post('xmlrpc_tp_DDRBatch_getTranList.asp',$sid,$self->username,$batchno); my $tids = $resp->{'ResponseData'}->{'id'}; next unless $tids; #error/die instead? my @batchitems = (); $tids = ref($tids) ? $tids : [ $tids ]; #get status by individual transaction foreach my $tid (@$tids) { - $resp = $self->xmlrpc_post('xmlrpc_tp_DDRBatch_getTranStatus.asp',$sid,$self->user_id,$tid); + $resp = $self->xmlrpc_post('xmlrpc_tp_DDRBatch_getTranStatus.asp',$sid,$self->username,$tid); my $status = lc($resp->{'ResponseData'}->{'bankprocessstatus'}); my $error = ''; next if grep(/^$status$/,('submitted','processing','scheduled')); @@ -255,7 +334,7 @@ sub download { } } # logout - $self->xmlrpc_post('xmlrpc_tp_Logout.asp',$sid,$self->user_id); + $self->xmlrpc_post('xmlrpc_tp_Logout.asp',$sid,$self->username); return @batches; } -- 2.11.0