mostly working transaction manager

fixed many bugs
This commit is contained in:
JT Smith 2008-05-19 22:17:08 +00:00
parent 6174d6995e
commit ca9278190e
10 changed files with 211 additions and 89 deletions

View file

@ -63,7 +63,9 @@ The content handler for this package.
sub handler {
my ($session) = @_;
my $output = undef;
my $function = "www_".$session->form->get("shop");
my $shop = $session->form->get("shop");
return $output unless ($shop);
my $function = "www_".$shop;
if ($function ne "www_" && (my $sub = __PACKAGE__->can($function))) {
$output = $sub->($session);
}

View file

@ -773,9 +773,7 @@ sub www_viewItem {
if (WebGUI::Error->caught()) {
return $self->www_view;
}
my $sku = $item->getSku;
$sku->applyOptions($item->get("options"));
return $sku->www_view;
return $item->getSku->www_view;
}

View file

@ -160,7 +160,6 @@ Returns the WebGUI::Shop::Address object that is attached to this item for shipp
sub getShippingAddress {
my $self = shift;
my $addressId = $self->get("shippingAddressId") || $self->cart->get("shippingAddressId");
$self->cart->session->errorHandler->warn("address id: ". $addressId);
return $self->cart->getAddressBook->getAddress($addressId);
}

View file

@ -496,7 +496,7 @@ sub processTransaction {
my $cart = $self->getCart;
my $transaction = WebGUI::Shop::Transaction->create($self->session,{
paymentMethod => $self,
# paymentAddress => $paymentAddress,
paymentAddress => $paymentAddress,
cart => $cart,
});
my ($success, $transactionCode, $statusCode, $statusMessage) = $self->processPayment( $transaction );

View file

@ -18,15 +18,6 @@ sub canCheckoutCart {
return 1;
}
#-------------------------------------------------------------------
sub credentialsOkay {
my $self = shift;
return 0 unless $self->getBillingAddress;
return 1;
}
#-------------------------------------------------------------------
sub definition {
@ -73,15 +64,11 @@ sub definition {
}
#-------------------------------------------------------------------
sub getBillingAddress {
my $self = shift;
my $session = $self->session;
my $addressId = $session->scratch->get('ShopPayDriverCash_billingAddress');
sub getAddress {
my ($self, $addressId) = @_;
if ($addressId) {
return $self->getCart->getAddressBook->getAddress( $addressId );
}
# No billing address selected yet so return undef.
return undef;
}
@ -154,9 +141,9 @@ sub www_displayStatus {
#-------------------------------------------------------------------
sub www_getCredentials {
my $self = shift;
my ($self, $addressId) = @_;
my $session = $self->session;
$addressId = $session->form->process('addressId') if ($addressId eq "");
# Generate the json string that defines where the address book posts the selected address
my $callbackParams = {
url => $session->url->page,
@ -178,11 +165,7 @@ sub www_getCredentials {
. WebGUI::Form::formFooter( $session);
# Get billing address
my $billingAddress = eval { $self->getBillingAddress };
if ( WebGUI::Error->caught('WebGUI::Error::ObjectNotFound') ) {
# The stored address id is invalid, so remove it
$session->scratch->delete('ShopPayDriverCash_billingAddress');
}
my $billingAddress = eval { $self->getAddress($addressId) };
my $billingAddressHtml;
if ($billingAddress) {
@ -192,6 +175,7 @@ sub www_getCredentials {
# Generate 'Proceed' button
my $proceedButton = WebGUI::Form::formHeader( $session )
. $self->getDoFormTags('pay')
. WebGUI::Form::hidden($session, {name=>"addressId", value=>$addressId})
. WebGUI::Form::submit( $session, { value => 'Pay' } )
. WebGUI::Form::formFooter( $session);
@ -211,7 +195,8 @@ sub www_pay {
return "" unless $self->canCheckoutCart;
# Make sure all required credentials have been supplied
return $self->www_getCredentials unless $self->credentialsOkay;
my $billingAddress = $self->getAddress( $session->form->process('addressId') );
return $self->www_getCredentials unless $billingAddress;
# Generate a receipt and send it if enabled.
if ( $self->get('sendReceipt') ) {
@ -233,7 +218,6 @@ sub www_pay {
$receipt->queue;
}
my $billingAddress = $self->getBillingAddress( $session->scratch->get( 'ShopPayDriverCash_billingAddressId' ) );
# Complete the transaction
my $transaction = $self->processTransaction( $billingAddress );
@ -246,10 +230,7 @@ sub www_pay {
sub www_setBillingAddress {
my $self = shift;
my $session = $self->session;
$session->scratch->set( 'ShopPayDriverCash_billingAddress', $session->form->process('addressId') );
return $self->www_getCredentials;
return $self->www_getCredentials($session->form->process('addressId'));
}
1;

View file

@ -124,22 +124,22 @@ sub _generatePaymentRequestXML {
# Check if recurring payments have a unique transaction
#### TODO: Throw the correct Exception Class
WebGUI::Error::InvalidParam->throw( error => 'Recurring transaction mixed with other transactions' )
if ( (scalar @{ $items } > 1) && (grep { $_->get('isRecurring') } @{ $items }) );
if ( (scalar @{ $items } > 1) && (grep { $_->getSku->isRecurring } @{ $items }) );
foreach my $item (@{ $transaction->getItems }) {
foreach my $item (@{ $items }) {
my $sku = $item->getSku;
####TODO: How to handle intial payment?
if ( $item->get('isRecurring') ) {
$recurringData->{ RecurRecipe } = $self->resolveRecurRecipe( $sku->get('recurInterval') );
if ( $sku->isRecurring ) {
$recurringData->{ RecurRecipe } = $self->resolveRecurRecipe( $sku->getRecurInterval );
$recurringData->{ RecurReps } = 99999;
$recurringData->{ RecurTotal } = $sku->getPrice;
$recurringData->{ RecurDesc } = $sku->get('title');
$recurringData->{ RecurTotal } = $item->get('price');
$recurringData->{ RecurDesc } = $item->get('configuredTitle');
}
push @{ $orderItems->{ Item } }, {
Description => $sku->get('title'),
Cost => $sku->getPrice,
Description => $item->get('configuredTitle'),
Cost => $item->get('price'),
Qty => $item->get('quantity'),
}
}

View file

@ -649,8 +649,11 @@ sub www_view {
#render page
my $output = q{
<style type="text/css">
#transactionDetail th { vertical-align: top; margin-right: 10px; border-right: 1px solid #eeeeee; text-align: left;}
.smallAddress { font-size: 60%; }
.transactionDetail {float: left; margin-right: 25px;}
.transactionDetail th { vertical-align: top; margin-right: 10px; border-right: 1px solid #eeeeee; text-align: left;}
.smallAddress { font-size: 50%; }
.successfulTransaction { color: #008000; };
.failedTransaction { color: #800000; };
</style>};
unless ($print) {
$output .= q{
@ -658,13 +661,36 @@ sub www_view {
};
}
$output .= q{
<table id="transactionDetail">
<table class="transactionDetail">
<tr>
<th>}. $i18n->get("transaction id") .q{</th><td>}. $transaction->getId .q{</td>
<th>}. $i18n->get("transaction id") .q{</th><td>}. $transaction->getId . '<br />'. $transaction->get('transactionCode').q{</td>
</tr>
<tr>
<th>}. $i18n->get("order number") .q{</th><td>}. $transaction->get('orderNumber') .q{</td>
</tr>
<tr>
<th>}. $i18n->get("date") .q{</th><td>}. $transaction->get('dateOfPurchase') .q{</td>
</tr>
<tr>
<th>}. $i18n->get("username") .q{</th><td><a href="}.$url->page('op=editUser;uid='.$transaction->get('userId')).q{">}. $transaction->get('username') .q{</a></td>
</tr>
<tr>
<th>}. $i18n->get("price") .q{</th><td><b>}. sprintf("%.2f", $transaction->get('amount')) .q{</b></td>
</tr>
<tr>
<th>}. $i18n->get("in shop credit used") .q{</th><td>}. sprintf("%.2f", $transaction->get('shopCreditDeduction')) .q{</td>
</tr>
<tr>
<th>}. $i18n->get("taxes") .q{</th><td>}. sprintf("%.2f", $transaction->get('taxes')) .q{</td>
</tr>
</table>
<table class="transactionDetail">
<tr>
<th>}. $i18n->get("shipping method") .q{</th><td><a href="}.$url->page('shop=ship;method=do;do=edit;driverId='.$transaction->get('shippingDriverId')).q{">}. $transaction->get('shippingDriverLabel') .q{</a></td>
</tr>
<tr>
<th>}. $i18n->get("shipping amount") .q{</th><td>}. sprintf("%.2f", $transaction->get('shippingPrice')) .q{</td>
</tr>
<tr>
<th>}. $i18n->get("shipping address") .q{</th><td>}. $transaction->formatAddress({
name => $transaction->get('shippingAddressName'),
@ -678,6 +704,14 @@ sub www_view {
phoneNumber => $transaction->get('shippingPhoneNumber'),
}) .q{</td>
</tr>
</table>
<table class="transactionDetail">
<tr>
<th>}. $i18n->get("payment method") .q{</th><td><a href="}.$url->page('shop=pay;method=do;do=edit;paymentGatewayId='.$transaction->get('paymentDriverId')).q{">}. $transaction->get('paymentDriverLabel') .q{</a></td>
</tr>
<tr>
<th>}. $i18n->get("status message") .q{</th><td class="}.(($transaction->get("isSuccessful")) ? 'successfulTransaction' : 'failedTransaction' ).q{">}. $transaction->get('statusCode') .': '.$transaction->get('statusMessage').q{</td>
</tr>
<tr>
<th>}. $i18n->get("payment address") .q{</th><td>}. $transaction->formatAddress({
name => $transaction->get('paymentAddressName'),
@ -691,10 +725,8 @@ sub www_view {
phoneNumber => $transaction->get('paymentPhoneNumber'),
}) .q{</td>
</tr>
<tr>
<th>}. $i18n->get("price") .q{</th><td>}. sprintf("%.2f", $transaction->get('amount')) .q{</td>
</tr>
</table>
<div style="clear:both;"></div>
};
# item detail
@ -702,13 +734,14 @@ sub www_view {
<div id="transactionItemWrapper" class=" yui-skin-sam"> <table id="transactionItems">
<thead>
<tr>
<th>Item</th>
<th>Price</th>
<th>Quantity</th>
<th>Status</th>
<th>Address</th>
<th>Date</th>
<th>Tracking #</th>
<th>}.$i18n->get('date').q{</th>
<th>}.$i18n->get('item').q{</th>
<th>}.$i18n->get('price').q{</th>
<th>}.$i18n->get('quantity').q{</th>
<th>}.$i18n->get('shipping address').q{</th>
<th>}.$i18n->get('order status').q{</th>
<th>}.$i18n->get('tracking number').q{</th>
<th>}.$i18n->get('manage').q{</th>
</tr>
</thead>
<tbody>
@ -717,10 +750,11 @@ sub www_view {
my $sku = $item->getSku;
$output .= q{
<tr>
<form>
<td>}.$item->get('lastUpdated').q{</td>
<td><a href="}.$sku->getUrl('shop=transaction;method=viewItem;transactionId='.$transaction->getId.';itemId='.$item->getId).q{">}.$item->get('configuredTitle').q{</a></td>
<td>}.$transaction->formatCurrency($item->get('price')).q{</td>
<td>}.$item->get('quantity').q{</td>
<td>}.$item->get('shippingStatus').q{</td>
};
if ($item->get('shippingAddressId') eq $transaction->get('shippingAddressId')) {
$output .= q{<td></td>};
@ -740,9 +774,26 @@ sub www_view {
}) .q{</td>
};
}
if ($item->get('orderStatus') eq 'Cancelled') {
$output .= q{<td>}.$i18n->get($item->get('orderStatus')).q{</td>};
}
else {
$output .= q{<td>}.WebGUI::Form::selectBox($session, {
name => "orderStatus",
value => $item->get('orderStatus'),
options => {
NotShipped => $i18n->get('NotShipped'),
Shipped => $i18n->get('Shipped'),
Backordered => $i18n->get('Backordered'),
},
}).q{</td>};
}
$output .= q{
<td>}.$item->get('shippingDate').q{</td>
<td>}.$item->get('shippingTrackingNumber').q{</td>
<td>}.WebGUI::Form::text($session, {name=>"shippingTrackingNumber", size=>15, value=>$item->get('shippingTrackingNumber')}).q{</td>
<td>}.WebGUI::Form::submit($session, {value=>$i18n->get('update'), extras=>' '})
.WebGUI::Form::submit($session, {value=>$i18n->get('refund'), extras=>q|onclick="this.form.method.value='refundItem'"|})
.q{</td>
</form>
</tr>
};
}
@ -752,40 +803,41 @@ sub www_view {
};
# render data table
$output .= <<STOP;
$output .= q|
<script type="text/javascript">
YAHOO.util.Event.addListener(window, "load", function() {
YAHOO.example.EnhanceFromMarkup = new function() {
var myColumnDefs = [
{key:"item",sortable:true},
{key:"price",sortable:true},
{key:"quantity",formatter:YAHOO.widget.DataTable.formatNumber,sortable:true},
{key:"status",sortable:true},
{key:"address"},
{key:"date",sortable:true,formatter:YAHOO.widget.DataTable.formatDate},
{key:"tracking"}
{key:"date",sortable:true,label:'|.$i18n->get('date').q|'},
{key:"item",sortable:true,label:'|.$i18n->get('item').q|'},
{key:"price",sortable:true,label:'|.$i18n->get('price').q|'},
{key:"quantity",formatter:YAHOO.widget.DataTable.formatNumber,sortable:true,label:'|.$i18n->get('quantity').q|'},
{key:"address",label:'|.$i18n->get('shipping address').q|'},
{key:"status",sortable:true,label:'|.$i18n->get('order status').q|'},
{key:"tracking",label:'|.$i18n->get('tracking number').q|'},
{key:"manage",label:'|.$i18n->get('manage').q|'}
];
this.myDataSource = new YAHOO.util.DataSource(YAHOO.util.Dom.get("transactionItems"));
this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
this.myDataSource.responseSchema = {
fields: [
{key:"date"},
{key:"item"},
{key:"price", parser:this.parseNumberFromCurrency},
{key:"quantity", parser:YAHOO.util.DataSource.parseNumber},
{key:"status"},
{key:"address"},
{key:"date", parser:YAHOO.util.DataSource.parseDate},
{key:"tracking"}
{key:"status"},
{key:"tracking"},
{key:"manage"}
]
};
this.myDataTable = new YAHOO.widget.DataTable("transactionItemWrapper", myColumnDefs, this.myDataSource,{});
};
});
</script>
STOP
});
</script>
|;
# send output
if ($print) {
@ -794,4 +846,23 @@ STOP
return $admin->getAdminConsole->render($output, $i18n->get('transactions'));
}
#-------------------------------------------------------------------
=head2 www_viewItem ( )
Displays the configured item.
=cut
sub www_viewItem {
my ($class, $session) = @_;
my $self = __PACKAGE__->new($session, $session->form->get("transactionId"));
my $item = eval { $self->getItem($session->form->get("itemId")) };
if (WebGUI::Error->caught()) {
return $class->www_view($session);
}
return $item->getSku->www_view;
}
1;

View file

@ -149,7 +149,7 @@ sub issueCredit {
my $credit = WebGUI::Shop::Credit->new($self->transaction->session, $self->transaction->get('userId'));
$credit->adjust($self->get('price'), "Issued credit on sku ".$self->get('assetId')." for transaction item ".$self->getId." on transaction ".$self->transaction->getId);
$self->getSku->onRefund($self);
$self->update({shippingStatus=>'Cancelled'});
$self->update({orderStatus=>'Cancelled'});
}
#-------------------------------------------------------------------
@ -251,9 +251,9 @@ shippingCode shippingPhoneNumber quantity price vendorId
A tracking number that is used by the shipping method for this transaction.
=head4 shippingStatus
=head4 orderStatus
The status of this item. The default is 'NotShipped'. Other statuses include: Cancelled, BackOrdered, Shipped
The status of this item. The default is 'NotShipped'. Other statuses include: Cancelled, Backordered, Shipped
=cut
@ -266,9 +266,8 @@ sub update {
$newProperties->{ options } = $sku->getOptions;
$newProperties->{ assetId } = $sku->getId;
$newProperties->{ price } = $sku->getPrice;
$newProperties->{ configuredTitle } = $sku->getConfiguredTitle;
$newProperties->{ isRecurring } = $sku->isRecurring;
$newProperties->{ recurInterval } = $sku->getRecurInterval if $sku->isRecurring;
$newProperties->{ configuredTitle } = $item->get('configuredTitle');
$newProperties->{ quantity } = $item->get('quantity');
my $address = $item->getShippingAddress;
$newProperties->{ shippingAddressId } = $address->getId;
$newProperties->{ shippingAddressName } = $address->get('name');
@ -280,9 +279,11 @@ sub update {
$newProperties->{ shippingCountry } = $address->get('country');
$newProperties->{ shippingCode } = $address->get('code');
$newProperties->{ shippingPhoneNumber } = $address->get('phoneNumber');
$newProperties->{ quantity } = $item->get('quantity');
unless ($sku->isShippingRequired) {
$newProperties->{orderStatus} = 'Shipped';
}
}
my @fields = (qw(assetId configuredTitle options shippingAddressId shippingTrackingNumber shippingStatus
my @fields = (qw(assetId configuredTitle options shippingAddressId shippingTrackingNumber orderStatus
shippingName shippingAddress1 shippingAddress2 shippingAddress3 shippingCity shippingState
shippingCountry shippingCode shippingPhoneNumber quantity price vendorId));
foreach my $field (@fields) {
@ -291,9 +292,7 @@ sub update {
if (exists $newProperties->{options} && ref($newProperties->{options}) eq "HASH") {
$properties{$id}{options} = JSON->new->utf8->encode($newProperties->{options});
}
if (exists $newProperties->{shippingStatus}) {
$properties{$id}{shippingDate} = WebGUI::DateTime->new($self->transaction->session,time())->toDatabase;
}
$properties{$id}{lastUpdated} = WebGUI::DateTime->new($self->transaction->session,time())->toDatabase;
$self->transaction->session->db->setRow("transactionItem","itemId",$properties{$id});
}

View file

@ -45,18 +45,72 @@ our $I18N = {
context => q|field label|
},
'tracking number' => {
message => q|Tracking #|,
lastUpdated => 0,
context => q|field label|
},
'order status' => {
message => q|Order Status|,
lastUpdated => 0,
context => q|field label|
},
'Shipped' => {
message => q|Shipped|,
lastUpdated => 0,
context => q|field label|
},
'NotShipped' => {
message => q|Not Shipped|,
lastUpdated => 0,
context => q|field label|
},
'Backordered' => {
message => q|Backordered|,
lastUpdated => 0,
context => q|field label|
},
'Cancelled' => {
message => q|Cancelled|,
lastUpdated => 0,
context => q|field label|
},
'vendors' => {
message => q|Vendors|,
lastUpdated => 0,
context => q|admin function label|
},
'update' => {
message => q|Update|,
lastUpdated => 0,
context => q|button label|
},
'refund' => {
message => q|Refund|,
lastUpdated => 0,
context => q|button label|
},
'date' => {
message => q|Date|,
lastUpdated => 0,
context => q|field label|
},
'manage' => {
message => q|Manage|,
lastUpdated => 0,
context => q|field label|
},
'order number' => {
message => q|Order #|,
lastUpdated => 0,
@ -81,6 +135,18 @@ our $I18N = {
context => q|field label|
},
'shipping method' => {
message => q|Shipping Method|,
lastUpdated => 0,
context => q|field label|
},
'shipping amount' => {
message => q|Shipping Amount|,
lastUpdated => 0,
context => q|field label|
},
'add shipper' => {
message => q|Add Shipping Method|,
lastUpdated => 0,
@ -213,6 +279,12 @@ our $I18N = {
context => q|a label in the cart|
},
'in shop credit used' => {
message => q|In-Shop Credit Used|,
lastUpdated => 0,
context => q|a label in the transaction|
},
'country' => {
message => q|Country|,
lastUpdated => 0,