- Fixed recurring payment cancelation and added error handling
- Made transactions with recurring items recurring - Fixed some bugs in the email receipt code - Added email receipt template to migrated plugins
This commit is contained in:
parent
2c57721e20
commit
b4a45c6ada
4 changed files with 36 additions and 15 deletions
|
|
@ -1420,6 +1420,7 @@ sub migratePaymentPlugins {
|
|||
print "\tMigrating WebGUI default commerce plugins..." unless $quiet;
|
||||
|
||||
foreach my $namespace (qw{ Cash ITransact }) {
|
||||
# Get properties from old plugin
|
||||
my $properties = $session->db->buildHashRef(
|
||||
'select fieldName, fieldValue from commerceSettings where type=\'Payment\' and namespace=?',
|
||||
[
|
||||
|
|
@ -1427,8 +1428,11 @@ sub migratePaymentPlugins {
|
|||
]
|
||||
);
|
||||
|
||||
$properties->{ groupToUse } = $properties->{ whoCanUse };
|
||||
# And set new properties
|
||||
$properties->{ groupToUse } = $properties->{ whoCanUse };
|
||||
$properties->{ receiptEmailTemplateId } = 'BMzuE91-XB8E-XGll1zpvA';
|
||||
|
||||
# Create paydriver instance
|
||||
my $plugin = eval {
|
||||
WebGUI::Pluggable::instanciate("WebGUI::Shop::PayDriver::$namespace", 'create', [
|
||||
$session,
|
||||
|
|
@ -1437,13 +1441,13 @@ sub migratePaymentPlugins {
|
|||
])
|
||||
};
|
||||
|
||||
# Print warning message for ITransact users that they must change their postback url
|
||||
if ( $namespace eq 'ITransact' && $properties->{ vendorId } ) {
|
||||
print "\n\t\t!!CAUTION!!: The postback url for ITransact has changed. Please log in to your virtual "
|
||||
."terminal and change the postback url to:\n\n\t\t"
|
||||
.'https://'.$session->config->get("sitename")->[0]
|
||||
.'/?shop=pay;method=do;do=processRecurringTransactionPostback;paymentGatewayId='.$plugin->getId."\n\t";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
print "Done\n" unless $quiet;
|
||||
|
|
|
|||
|
|
@ -578,6 +578,7 @@ sub processTransaction {
|
|||
$transactionProperties->{ paymentMethod } = $self;
|
||||
$transactionProperties->{ cart } = $cart;
|
||||
$transactionProperties->{ paymentAddress } = $paymentAddress if defined $paymentAddress;
|
||||
$transactionProperties->{ isRecurring } = $cart->requiresRecurringPayment;
|
||||
|
||||
# Create a transaction...
|
||||
my $transaction = WebGUI::Shop::Transaction->create( $self->session, $transactionProperties );
|
||||
|
|
@ -678,25 +679,25 @@ sub sendNotifications {
|
|||
$var{items} = \@items;
|
||||
|
||||
# render
|
||||
my $template = WebGUI::Asset::Template->new($session, $session->setting->get("receiptEmailTemplateId"));
|
||||
my $template = WebGUI::Asset::Template->new( $session, $self->get("receiptEmailTemplateId") );
|
||||
my $inbox = WebGUI::Inbox->new($session);
|
||||
|
||||
# purchase receipt
|
||||
$inbox->addMessage(
|
||||
$inbox->addMessage( {
|
||||
message => $template->process(\%var),
|
||||
subject => $i18n->get('receipt subject').' '.$transaction->get('orderNumber'),
|
||||
userId => $transaction->get('userId'),
|
||||
status => 'completed',
|
||||
);
|
||||
} );
|
||||
|
||||
# shop owner notification
|
||||
$var{viewDetailUrl} = $url->page('shop=transaction;method=view;transactionId='.$transaction->getId,1);
|
||||
$inbox->addMessage(
|
||||
$inbox->addMessage( {
|
||||
message => $template->process(\%var),
|
||||
subject => $i18n->get('a sale has been made').' '.$transaction->get('orderNumber'),
|
||||
groupId => $self->get('saleNotificationGroupId'),
|
||||
status => 'unread',
|
||||
);
|
||||
} );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ sub _generateCancelRecurXml {
|
|||
$vendorIdentification->{ HomePage } = $self->session->setting->get("companyURL");
|
||||
|
||||
my $recurUpdate;
|
||||
$recurUpdate->{ OperationXID } = $transaction->get('gatewayId');
|
||||
$recurUpdate->{ OperationXID } = $transaction->get('transactionCode');
|
||||
$recurUpdate->{ RemReps } = 0;
|
||||
|
||||
my $xmlStructure = {
|
||||
|
|
@ -247,8 +247,9 @@ sub cancelRecurringPayment {
|
|||
$session->errorHandler->info( "GatewayFailureResponse: result: [" . $response->content . "]" );
|
||||
return(
|
||||
0,
|
||||
$transactionResult->{ Status },
|
||||
$transactionResult->{ ErrorMessage } . ' Category: ' . $transactionResult->{ ErrorCategory }
|
||||
"Status: " . $transactionResult->{ Status }
|
||||
." Message: " . $transactionResult->{ ErrorMessage }
|
||||
." Category: " . $transactionResult->{ ErrorCategory }
|
||||
);
|
||||
} else {
|
||||
# RecurUpdateResponse: We have succesfully sent the XML and it was correct. Note that this doesn't mean
|
||||
|
|
@ -264,7 +265,7 @@ sub cancelRecurringPayment {
|
|||
# Uppercase the status b/c the documentation is not clear on the case.
|
||||
my $isSuccess = uc( $status ) eq 'OK' && $remainingTerms == 0;
|
||||
|
||||
return ( $isSuccess, $status, "$errorMessage Category: $errorCategory" );
|
||||
return ( $isSuccess, "Status: $status Message: $errorMessage Category: $errorCategory" );
|
||||
}
|
||||
} else {
|
||||
# Connection Error
|
||||
|
|
|
|||
|
|
@ -72,17 +72,28 @@ sub addItem {
|
|||
|
||||
=head2 cancelRecurring ( )
|
||||
|
||||
Cancel a recurring transaction, and calls onCancelRecurring in whatever sku is attached to this transaction.
|
||||
Cancel a recurring transaction, and calls onCancelRecurring in whatever sku is attached to this transaction. If the
|
||||
cancelation fails, returns an error message.
|
||||
|
||||
=cut
|
||||
|
||||
sub cancelRecurring {
|
||||
my ($self) = @_;
|
||||
$self->getPaymentGateway->cancelRecurringPayment($self);
|
||||
my ($item) = $self->getItems;
|
||||
my ($success, $message) = $self->getPaymentGateway->cancelRecurringPayment($self);
|
||||
|
||||
# Handle failed cancelation.
|
||||
unless ($success) {
|
||||
return
|
||||
"Canceling recurring transaction failed. The following response was received from the payment gateway:<br/>"
|
||||
. $message;
|
||||
}
|
||||
|
||||
my ($item) = @{ $self->getItems };
|
||||
$item->getSku->onCancelRecurring($item);
|
||||
my $recurringId = ($self->get('originatingTransactionId') || $self->getId);
|
||||
$self->session->db->write("update transaction set isRecurring=0 where transactionId=? or originatingTransactionId=?",[$recurringId,$recurringId]);
|
||||
|
||||
return undef;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -606,7 +617,11 @@ sub www_cancelRecurring {
|
|||
my ($class, $session) = @_;
|
||||
my $self = $class->new($session, $session->form->get("transactionId"));
|
||||
return $session->privilege->insufficient unless (WebGUI::Shop::Admin->new($session)->canManage || $session->user->userId eq $self->get('userId'));
|
||||
$self->cancelRecurring;
|
||||
my $error = $self->cancelRecurring;
|
||||
|
||||
# TODO: Needs to be templated or included in www_view.
|
||||
return $error if $error;
|
||||
|
||||
return $class->www_view($session);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue