fixed several ems badge related bugs. a couple upgrade bugs for ems and transaction. and jury rigged a fix for recurring transaction postback.

This commit is contained in:
JT Smith 2008-06-13 21:54:43 +00:00
parent f482c079d7
commit 75208339fc
4 changed files with 51 additions and 177 deletions

View file

@ -20,6 +20,7 @@ use Tie::IxHash;
use WebGUI::HTMLForm;
use JSON;
use Digest::MD5;
use WebGUI::Exception;
use WebGUI::Workflow::Instance;
use WebGUI::Cache;
use WebGUI::International;
@ -845,7 +846,7 @@ sub www_getRegistrantsAsJson {
if ($keywords ne "") {
$db->buildSearchQuery(\$sql, \@params, $keywords, [qw{badgeNumber name address1 address2 address3 city state country email notes zipcode phoneNumber organization}])
}
# limit
$sql .= ' limit ?,?';
push(@params, $startIndex, $numberOfResults);
@ -858,6 +859,10 @@ sub www_getRegistrantsAsJson {
$results{'totalRecords'} = $db->quickScalar('select found_rows()') + 0; ##Convert to numeric
while (my $badgeInfo = $badges->hashRef) {
my $badge = WebGUI::Asset::Sku::EMSBadge->new($session, $badgeInfo->{badgeAssetId});
unless (defined $badge) {
$session->log->error('badge '.$badgeInfo->{badgeAssetId}.' does not exist.');
next;
}
$badgeInfo->{title} = $badge->getTitle;
$badgeInfo->{sku} = $badge->get('sku');
$badgeInfo->{assetId} = $badge->getId;
@ -1456,7 +1461,11 @@ sub www_refundItem {
return $session->privilege->insufficient() unless $self->canView;
my @itemIds = $session->form->param("transactionItemId");
foreach my $id (@itemIds) {
my $item = WebGUI::Shop::TransactionItem->newByDynamicTransaction($session, $id);
my $item = eval{WebGUI::Shop::TransactionItem->newByDynamicTransaction($session, $id)};
if (WebGUI::Error->caught('WebGUI::Error::InvalidParam')) {
$session->log->warn('Got "'.$@.'" which probably means we are working on a registrant that was migrated, and cannot be refunded.');
$self->www_manageRegistrant();
}
if (defined $item) {
$item->issueCredit;
}

View file

@ -7,17 +7,6 @@ use Data::Dumper;
use base qw/WebGUI::Shop::PayDriver/;
#-------------------------------------------------------------------
=head2 _generateCancelRecurXml ( transaction )
Generates the XML that cancels a recurring payment. Includes the xml header.
=head3 transaction
The instantiated WebGUI::Shop::Transaction object for the transaction the recurring payment should be stopped.
=cut
sub _generateCancelRecurXml {
my $self = shift;
my $transaction = shift;
@ -51,17 +40,6 @@ sub _generateCancelRecurXml {
}
#-------------------------------------------------------------------
=head2 _generatePaymentRequestXML ( transaction )
Generates the XML that will perform the payment transaction.
=head3 transaction
The instantiated WebGUI::Shop::Transaction object for the transaction that should be payed.
=cut
sub _generatePaymentRequestXML {
my $self = shift;
my $transaction = shift;
@ -188,13 +166,6 @@ sub _generatePaymentRequestXML {
}
#-------------------------------------------------------------------
=head _monthYear ()
Returns the HTML for month/year combo box as is used for the credit card expiration date in the checkout form.
=cut
sub _monthYear {
my $session = shift;
my $form = $session->form;
@ -221,19 +192,6 @@ sub _monthYear {
}
#-------------------------------------------------------------------
=head2 _resolveRecurRecipe ( duration )
Returns the ITransact recipe name tied to one of the allowed recurring payment term durations as used within the
commerce system.
=head3 duration
The idenntifier for the term of the recurring transaction. May be either 'Weekly', 'BiWeekly', 'FourWeekly',
'Monthly', 'BiMonthly', 'Quarterly', 'HalfYearly' or 'Yearly'.
=cut
sub _resolveRecurRecipe {
my $self = shift;
my $duration = shift;
@ -252,6 +210,8 @@ sub _resolveRecurRecipe {
return $resolve{ $duration };
}
#-------------------------------------------------------------------
=head2 cancelRecurringPayment ( transaction )
@ -316,22 +276,6 @@ sub cancelRecurringPayment {
}
#-------------------------------------------------------------------
=head2 checkRecurringTransaction ( xid, expectedAmount )
Does a request to ITransact to check the amount tied to a transaction. This is maily used to check whether a
postback result is an actual post back from ITransact and not a falsified post back by a malicious user.
=head3 xid
The id ITranscat to the transaction. Make sure not to use the orig_xid.
=head3 expectedAmount
The amount the transaction should be.
=cut
sub checkRecurringTransaction {
my $self = shift;
my $xid = shift;
@ -399,21 +343,6 @@ sub checkRecurringTransaction {
}
#-------------------------------------------------------------------
=head2 definition ( session, definition )
The defintion method of the plugin. See WebGUI::Shop::PayDriver->definition for more information.
=head3 session
An instantiated WebGUI::Session object.
=head3 definition
Arrayref. Used to let every subclass add its properties to the definition.
=cut
sub definition {
my $class = shift;
my $session = shift;
@ -425,29 +354,29 @@ sub definition {
%fields = (
vendorId => {
fieldType => 'text',
label => $i18n->get('vendorId'),
hoverHelp => $i18n->get('vendorId help'),
label => $i18n->echo('vendorId'),
hoverHelp => $i18n->echo('vendorId help'),
},
password => {
fieldType => 'password',
label => $i18n->get('password'),
hoverHelp => $i18n->get('password help'),
label => $i18n->echo('password'),
hoverHelp => $i18n->echo('password help'),
},
useCVV2 => {
fieldType => 'yesNo',
label => $i18n->get('use cvv2'),
hoverHelp => $i18n->get('use cvv2 help'),
label => $i18n->echo('use cvv2'),
hoverHelp => $i18n->echo('use cvv2 help'),
},
emailMessage => {
fieldType => 'textarea',
label => $i18n->get('emailMessage'),
hoverHelp => $i18n->get('emailMessage help'),
label => $i18n->echo('emailMessage'),
hoverHelp => $i18n->echo('emailMessage help'),
},
# readonly stuff from old plugin here?
);
push @{ $definition }, {
name => $i18n->get('Itransact'),
name => $i18n->echo('Itransact'),
properties => \%fields,
};
@ -498,35 +427,20 @@ sub doXmlRequest {
}
#-------------------------------------------------------------------
=head2 getButton ( )
Return the HTML for a button inside a form that, when clicked, will take the user to the checkout screen for this
plugin.
=cut
sub getButton {
my $self = shift;
my $session = $self->session;
my $i18n = WebGUI::International->new($session, 'PayDriver_ITransact');
my $i18n = WebGUI::International->new($session, 'PayDriver_ITansact');
my $payForm = WebGUI::Form::formHeader($session)
. $self->getDoFormTags('getCredentials')
. WebGUI::Form::submit($session, {value => $i18n->get('ITransact') })
. WebGUI::Form::submit($session, {value => $i18n->echo('ITransact') })
. WebGUI::Form::formFooter($session);
return $payForm;
}
#-------------------------------------------------------------------
=head2 getEditForm ( )
Adds account setup information to the edit form for this plugin. Returns an instantiated WebGUI::HTMLForm obejct.
=cut
sub getEditForm {
my $self = shift;
my $session = $self->session;
@ -566,15 +480,6 @@ sub handlesRecurring {
}
#-------------------------------------------------------------------
=head2 processCredentials ( )
Checks and processes the data submitted by the user to the checkout form. Returns an array ref containing error messages if an
error occurred. If everything is okay, undef will be returned. Since this method stores the redentials in this
object instance you must execute this method before attempting a payment request.
=cut
sub processCredentials {
my $self = shift;
my $session = $self->session;
@ -631,26 +536,6 @@ sub processCredentials {
}
#-------------------------------------------------------------------
=head2 processPayment ( transaction )
Sends a payment request to ITransact, parses the result and depending on the outcome returns either:
On a succesfull request:
(1, GatewayCode, Status, Message)
On a failed request:
(0, GatewayCode, Status, Message)
Note that in the former case Message can be empty, while in the latter case GatewayCode may not be available (for
instance on a connection error) and wil be undef.
See also WebGUI::Shop::PayDriver->processPayment.
=cut
sub processPayment {
my $self = shift;
my $transaction = shift;
@ -703,17 +588,6 @@ sub processPayment {
}
#-------------------------------------------------------------------
=head2 www_getCredentials ( errors )
Displays the checkout form where users who want to pay can enter their address and credit card data.
=head3 errors
Arrayref containing error messages for errors that the user made in entering his data.
=cut
sub www_getCredentials {
my $self = shift;
my $errors = shift;
@ -733,7 +607,8 @@ sub www_getCredentials {
# Process form errors
if ( $errors ) {
$output .= $i18n->get('error occurred message')
#### TODO: i18n
$output .= $i18n->echo('The following errors occurred:')
. '<ul><li>' . join( '</li><li>', @{ $errors } ) . '</li></ul>';
}
@ -817,16 +692,6 @@ sub www_getCredentials {
}
#-------------------------------------------------------------------
=head2 www_pay
The actual payment.
Checks the credentials, returns the credentials input screen with errors if there are any. Otherwise tries to do
the actual payment.
=cut
sub www_pay {
my $self = shift;
my $session = $self->session;
@ -849,17 +714,10 @@ sub www_pay {
}
#-------------------------------------------------------------------
=head2 www_processRecurringTransactionPostback ( )
This is the method that the postback from ITransact should go to. It processes the post back form data and verifies
it is a legit request.
=cut
sub www_processRecurringTransactionPostback {
my $self = shift;
my $session = $self->session;
$session->http->setMimeType('text/plain');
my $form = $session->form;
# Get posted data of interest
@ -875,7 +733,7 @@ sub www_processRecurringTransactionPostback {
# First check whether the original transaction actualy exists
unless ( $baseTransaction ) {
$session->errorHandler->warn->("Check recurring postback: No base transction for XID: [$originatingXid]");
return;
return "Check recurring postback: No base transction for XID: [$originatingXid]";
}
# Secondly check if the postback is coming from secure.paymentclearing.com
@ -886,13 +744,13 @@ sub www_processRecurringTransactionPostback {
# }
# Third, check if the new xid exists and if the amount is correct.
my $expectedAmount = sprintf("%.2f",
$baseTransaction->get('amount') + $baseTransaction->get('taxes') + $baseTransaction->get('shippingPrice') );
# my $expectedAmount = sprintf("%.2f",
# $baseTransaction->get('amount') + $baseTransaction->get('taxes') + $baseTransaction->get('shippingPrice') );
unless ( $self->checkRecurringTransaction( $xid, $expectedAmount ) ) {
$session->errorHandler->warn('Check recurring postback: transaction check failed.');
#return;
}
# unless ( $self->checkRecurringTransaction( $xid, $expectedAmount ) ) {
# $session->errorHandler->warn('Check recurring postback: transaction check failed.');
# return 'Check recurring postback: transaction check failed.';
# }
#---- Passed all test, continue ---------------
# Create a new transaction for this term
@ -910,7 +768,7 @@ sub www_processRecurringTransactionPostback {
$transaction->denyPurchase( $xid, $status, $errorMessage );
}
return undef;
return "OK";
}
1;