Recurring payment stuff fixes, forgot ITransact.pm in last commit.
This commit is contained in:
parent
74b3d3def6
commit
dc30ecccbe
3 changed files with 109 additions and 43 deletions
|
|
@ -383,6 +383,32 @@ sub getPrice {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 getRecurInterval
|
||||||
|
|
||||||
|
Returns the duration of this subscription in a format used by the commerce system.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub getRecurInterval {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return $self->get('duration');
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 isRecurring
|
||||||
|
|
||||||
|
Tells the commerce system this Sku is recurring.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub isRecurring {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 onCompletePurchase
|
=head2 onCompletePurchase
|
||||||
|
|
||||||
Applies the first term of the subscription. This method is called when the payment is successful.
|
Applies the first term of the subscription. This method is called when the payment is successful.
|
||||||
|
|
|
||||||
|
|
@ -519,12 +519,19 @@ A reference to a WebGUI::Shop::Address object that should be attached as payment
|
||||||
|
|
||||||
sub processTransaction {
|
sub processTransaction {
|
||||||
my ($self, $paymentAddress) = @_;
|
my ($self, $paymentAddress) = @_;
|
||||||
|
|
||||||
my $cart = $self->getCart;
|
my $cart = $self->getCart;
|
||||||
my $transaction = WebGUI::Shop::Transaction->create($self->session,{
|
|
||||||
paymentMethod => $self,
|
# Setup tranasction properties
|
||||||
paymentAddress => $paymentAddress,
|
my $transactionProperties;
|
||||||
cart => $cart,
|
$transactionProperties->{ paymentMethod } = $self;
|
||||||
});
|
$transactionProperties->{ cart } = $cart;
|
||||||
|
$transactionProperties->{ paymentAddress } = $paymentAddress if defined $paymentAddress;
|
||||||
|
|
||||||
|
# Create a transaction...
|
||||||
|
my $transaction = WebGUI::Shop::Transaction->create( $self->session, $transactionProperties );
|
||||||
|
|
||||||
|
# And handle the payment for it
|
||||||
my ($success, $transactionCode, $statusCode, $statusMessage) = $self->processPayment( $transaction );
|
my ($success, $transactionCode, $statusCode, $statusMessage) = $self->processPayment( $transaction );
|
||||||
if ($success) {
|
if ($success) {
|
||||||
$transaction->completePurchase($transactionCode, $statusCode, $statusMessage);
|
$transaction->completePurchase($transactionCode, $statusCode, $statusMessage);
|
||||||
|
|
|
||||||
|
|
@ -2,34 +2,10 @@ package WebGUI::Shop::PayDriver::ITransact;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use XML::Simple;
|
use XML::Simple;
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
use base qw/WebGUI::Shop::PayDriver/;
|
use base qw/WebGUI::Shop::PayDriver/;
|
||||||
|
|
||||||
sub _monthYear {
|
|
||||||
my $session = shift;
|
|
||||||
my $form = $session->form;
|
|
||||||
|
|
||||||
tie my %months, "Tie::IxHash";
|
|
||||||
tie my %years, "Tie::IxHash";
|
|
||||||
%months = map { sprintf( '%02d', $_ ) => sprintf( '%02d', $_ ) } 1 .. 12;
|
|
||||||
%years = map { $_ => $_ } 2004 .. 2099;
|
|
||||||
|
|
||||||
my $monthYear =
|
|
||||||
WebGUI::Form::selectBox( $session, {
|
|
||||||
name => 'expMonth',
|
|
||||||
options => \%months,
|
|
||||||
value => [ $form->process("expMonth") ]
|
|
||||||
})
|
|
||||||
. " / "
|
|
||||||
. WebGUI::Form::selectBox( $session, {
|
|
||||||
name => 'expYear',
|
|
||||||
options => \%years,
|
|
||||||
value => [ $form->process("expYear") ]
|
|
||||||
});
|
|
||||||
|
|
||||||
return $monthYear;
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
sub _generateCancelRecurXml {
|
sub _generateCancelRecurXml {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
@ -63,6 +39,52 @@ sub _generateCancelRecurXml {
|
||||||
return $xml;
|
return $xml;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
sub _monthYear {
|
||||||
|
my $session = shift;
|
||||||
|
my $form = $session->form;
|
||||||
|
|
||||||
|
tie my %months, "Tie::IxHash";
|
||||||
|
tie my %years, "Tie::IxHash";
|
||||||
|
%months = map { sprintf( '%02d', $_ ) => sprintf( '%02d', $_ ) } 1 .. 12;
|
||||||
|
%years = map { $_ => $_ } 2004 .. 2099;
|
||||||
|
|
||||||
|
my $monthYear =
|
||||||
|
WebGUI::Form::selectBox( $session, {
|
||||||
|
name => 'expMonth',
|
||||||
|
options => \%months,
|
||||||
|
value => [ $form->process("expMonth") ]
|
||||||
|
})
|
||||||
|
. " / "
|
||||||
|
. WebGUI::Form::selectBox( $session, {
|
||||||
|
name => 'expYear',
|
||||||
|
options => \%years,
|
||||||
|
value => [ $form->process("expYear") ]
|
||||||
|
});
|
||||||
|
|
||||||
|
return $monthYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
sub _resolveRecurRecipe {
|
||||||
|
my $self = shift;
|
||||||
|
my $duration = shift;
|
||||||
|
|
||||||
|
my %resolve = (
|
||||||
|
Weekly => 'weekly',
|
||||||
|
BiWeekly => 'biweekly',
|
||||||
|
FourWeekly => 'fourweekly',
|
||||||
|
Monthly => 'monthly',
|
||||||
|
Quarterly => 'quarterly',
|
||||||
|
HalfYearly => 'halfyearly',
|
||||||
|
Yearly => 'yearly',
|
||||||
|
);
|
||||||
|
|
||||||
|
# TODO: Throw exception
|
||||||
|
return $resolve{ $duration };
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 doXmlRequest ( xml [ isAdministrative ] )
|
=head2 doXmlRequest ( xml [ isAdministrative ] )
|
||||||
|
|
@ -264,24 +286,23 @@ sub _generatePaymentRequestXML {
|
||||||
# Since recur recipes are based on intervals defined in days, the first term will payed NOW. Since the
|
# Since recur recipes are based on intervals defined in days, the first term will payed NOW. Since the
|
||||||
# subscription start NOW too, we never need an initial amount for recurring payments.
|
# subscription start NOW too, we never need an initial amount for recurring payments.
|
||||||
if ( $sku->isRecurring ) {
|
if ( $sku->isRecurring ) {
|
||||||
$recurringData->{ RecurRecipe } = $self->resolveRecurRecipe( $sku->getRecurInterval );
|
$recurringData->{ RecurRecipe } = $self->_resolveRecurRecipe( $sku->getRecurInterval );
|
||||||
$recurringData->{ RecurReps } = 99999;
|
$recurringData->{ RecurReps } = 99999;
|
||||||
$recurringData->{ RecurTotal } =
|
$recurringData->{ RecurTotal } =
|
||||||
$item->get('price') + $transaction->get('taxes') + $transaction->get('shippingPrice');
|
$item->get('price') + $transaction->get('taxes') + $transaction->get('shippingPrice');
|
||||||
$recurringData->{ RecurDesc } = $item->get('configuredTitle');
|
$recurringData->{ RecurDesc } = $item->get('configuredTitle');
|
||||||
}
|
}
|
||||||
else {
|
# else {
|
||||||
push @{ $orderItems->{ Item } }, {
|
push @{ $orderItems->{ Item } }, {
|
||||||
Description => $item->get('configuredTitle'),
|
Description => $item->get('configuredTitle'),
|
||||||
Cost => $item->get('price'),
|
Cost => $item->get('price'),
|
||||||
Qty => $item->get('quantity'),
|
Qty => $item->get('quantity'),
|
||||||
}
|
}
|
||||||
}
|
# }
|
||||||
}
|
}
|
||||||
|
|
||||||
# taxes, shipping, etc
|
# taxes, shipping, etc
|
||||||
my $i18n = WebGUI::International->new($session, "Shop");
|
my $i18n = WebGUI::International->new($session, "Shop");
|
||||||
#### TODO: Don't add this if the transaction is recurring
|
|
||||||
if ( $transaction->get('taxes') > 0 ) {
|
if ( $transaction->get('taxes') > 0 ) {
|
||||||
push @{ $orderItems->{ Item } }, {
|
push @{ $orderItems->{ Item } }, {
|
||||||
Description => $i18n->get('taxes'),
|
Description => $i18n->get('taxes'),
|
||||||
|
|
@ -289,7 +310,6 @@ sub _generatePaymentRequestXML {
|
||||||
Qty => 1,
|
Qty => 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#### TODO: Don't add this if the transaction is recurring
|
|
||||||
if ($transaction->get('shippingPrice') > 0) {
|
if ($transaction->get('shippingPrice') > 0) {
|
||||||
push @{ $orderItems->{ Item } }, {
|
push @{ $orderItems->{ Item } }, {
|
||||||
Description => $i18n->get('shipping'),
|
Description => $i18n->get('shipping'),
|
||||||
|
|
@ -316,7 +336,7 @@ sub _generatePaymentRequestXML {
|
||||||
$transactionData->{ HomePage } = $self->session->setting->get("companyURL");
|
$transactionData->{ HomePage } = $self->session->setting->get("companyURL");
|
||||||
$transactionData->{ RecurringData } = $recurringData if $recurringData;
|
$transactionData->{ RecurringData } = $recurringData if $recurringData;
|
||||||
$transactionData->{ EmailText } = $emailText if $emailText;
|
$transactionData->{ EmailText } = $emailText if $emailText;
|
||||||
$transactionData->{ OrderItems } = $orderItems;
|
$transactionData->{ OrderItems } = $orderItems if $orderItems;
|
||||||
|
|
||||||
# --- The XML structure ---
|
# --- The XML structure ---
|
||||||
my $xmlStructure = {
|
my $xmlStructure = {
|
||||||
|
|
@ -407,6 +427,17 @@ sub processCredentials {
|
||||||
return \@error;
|
return \@error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 handlesRecurring
|
||||||
|
|
||||||
|
Tells the commerce system that this payment plugin can handle recurring payments.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub handlesRecurring {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
sub processPayment {
|
sub processPayment {
|
||||||
|
|
@ -460,7 +491,7 @@ sub processPayment {
|
||||||
my $gatewayCode = $transactionData->{ XID };
|
my $gatewayCode = $transactionData->{ XID };
|
||||||
my $isSuccess = $status eq 'OK';
|
my $isSuccess = $status eq 'OK';
|
||||||
|
|
||||||
return ( $isSuccess, $gatewayCode, $status, "$errorMessage Category: $errorCategory" );
|
return ( $isSuccess, $gatewayCode, $status, "" );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
# Connection Error
|
# Connection Error
|
||||||
|
|
@ -477,10 +508,10 @@ sub www_processRecurringTransactionPostback {
|
||||||
my $form = $session->form;
|
my $form = $session->form;
|
||||||
|
|
||||||
# Get posted data of interest
|
# Get posted data of interest
|
||||||
my $originatingXid = $form->process( 'orig_xid' );
|
my $originatingXid = $form->process( 'orig_xid' );
|
||||||
my $status = $form->process( 'status' );
|
my $status = $form->process( 'status' );
|
||||||
my $xid = $form->process( 'xid' );
|
my $xid = $form->process( 'xid' );
|
||||||
my $errorMessage = $form->process( 'error_message' );
|
my $errorMessage = $form->process( 'error_message' );
|
||||||
|
|
||||||
# Fetch the original transaction
|
# Fetch the original transaction
|
||||||
my $baseTransaction = WebGUI::Shop::Transaction->newByGatewayId( $session, $originatingXid, $self->getId );
|
my $baseTransaction = WebGUI::Shop::Transaction->newByGatewayId( $session, $originatingXid, $self->getId );
|
||||||
|
|
@ -499,6 +530,8 @@ sub www_processRecurringTransactionPostback {
|
||||||
# The term has not been payed succesfully
|
# The term has not been payed succesfully
|
||||||
$transaction->denyPurchase( $xid, $status, $errorMessage );
|
$transaction->denyPurchase( $xid, $status, $errorMessage );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue