Merge commit '41575d24bb' into webgui8. Some tests still failing.

Conflicts:
	docs/gotcha.txt
	lib/WebGUI.pm
	lib/WebGUI/Asset.pm
	lib/WebGUI/Asset/File/GalleryFile/Photo.pm
	lib/WebGUI/Asset/Post.pm
	lib/WebGUI/Asset/Template.pm
	lib/WebGUI/Asset/WikiPage.pm
	lib/WebGUI/Asset/Wobject/WikiMaster.pm
	lib/WebGUI/Cache.pm
	lib/WebGUI/Content/Setup.pm
	lib/WebGUI/Role/Asset/Subscribable.pm
	lib/WebGUI/Shop/Cart.pm
	lib/WebGUI/Shop/Pay.pm
	lib/WebGUI/Shop/PayDriver/ITransact.pm
	sbin/testEnvironment.pl
	t/Asset/WikiPage.t
	t/Shop/PayDriver.t
	t/Shop/PayDriver/ITransact.t
	t/Shop/PayDriver/Ogone.t
	t/Shop/TaxDriver/EU.t
	t/Shop/TaxDriver/Generic.t
	t/Workflow/Activity/RemoveOldCarts.t
	t/lib/WebGUI/Test.pm
This commit is contained in:
Colin Kuskie 2010-06-25 23:25:26 -07:00
commit 5febc0ebbc
258 changed files with 5528 additions and 2230 deletions

View file

@ -56,6 +56,15 @@ sub definition {
my $i18n = WebGUI::International->new($session, 'PayDriver_Cash');
tie my %fields, 'Tie::IxHash';
%fields = (
summaryTemplateId => {
fieldType => 'template',
label => $i18n->get('summary template'),
hoverHelp => $i18n->get('summary template help'),
namespace => 'Shop/Credentials',
defaultValue => '30h5rHxzE_Q0CyI3Gg7EJw',
},
);
push @{ $definition }, {
name => $i18n->get('label'),
@ -69,21 +78,21 @@ sub definition {
=head2 getButton ( )
Returns the HTML for a form containing a button that, when clicked, will take the user to the checkout screen of
this plugin.
Return a form with button to finalize checkout from the Shop.
=cut
sub getButton {
my $self = shift;
my ($self) = @_;
my $session = $self->session;
my $payForm = WebGUI::Form::formHeader($session)
. $self->getDoFormTags('getCredentials')
. WebGUI::Form::submit($session, {value => $self->get('label') })
. WebGUI::Form::formFooter($session);
return $payForm;
# Generate 'Proceed' button
my $i18n = WebGUI::International->new($session, 'PayDriver_Cash');
return WebGUI::Form::formHeader( $session )
. $self->getDoFormTags('pay')
. WebGUI::Form::submit( $session, { value => $i18n->get('Pay') } )
. WebGUI::Form::formFooter( $session)
;
}
#-------------------------------------------------------------------
@ -100,64 +109,6 @@ sub processPayment {
#-------------------------------------------------------------------
=head2 www_getCredentials ( [ addressId ] )
Displays the checkout form for this plugin.
=head3 addressId
Optionally supply this variable which will set the payment address to this addressId.
=cut
sub www_getCredentials {
my ($self, $addressId) = @_;
my $session = $self->session;
# Process address from address book if passed
$addressId = $session->form->process( 'addressId' );
my $address;
if ( $addressId ) {
$address = eval{ $self->getAddress( $addressId ) };
}
else {
$address = $self->getCart->getShippingAddress;
}
my $billingAddressHtml = $address->getHtmlFormatted;
# Generate the json string that defines where the address book posts the selected address
my $callbackParams = {
url => $session->url->page,
params => [
{ name => 'shop', value => 'pay' },
{ name => 'method', value => 'do' },
{ name => 'do', value => 'setBillingAddress' },
{ name => 'paymentGatewayId', value => $self->getId },
],
};
my $callbackJson = JSON::to_json( $callbackParams );
# Generate 'Choose billing address' button
my $addressButton = WebGUI::Form::formHeader( $session )
. WebGUI::Form::hidden( $session, { name => 'shop', value => 'address' } )
. WebGUI::Form::hidden( $session, { name => 'method', value => 'view' } )
. WebGUI::Form::hidden( $session, { name => 'callback', value => $callbackJson } )
. WebGUI::Form::submit( $session, { value => 'Choose billing address' } )
. WebGUI::Form::formFooter( $session);
# Generate 'Proceed' button
my $proceedButton = WebGUI::Form::formHeader( $session )
. $self->getDoFormTags('pay')
. WebGUI::Form::hidden($session, {name=>"addressId", value=>$address->getId})
. WebGUI::Form::submit( $session, { value => 'Pay' } )
. WebGUI::Form::formFooter( $session);
return $session->style->userStyle($addressButton.'<br />'.$billingAddressHtml.'<br />'.$proceedButton);
}
#-------------------------------------------------------------------
=head2 www_pay ( )
Checks credentials, and completes the transaction if those are correct.
@ -166,36 +117,14 @@ Checks credentials, and completes the transaction if those are correct.
sub www_pay {
my $self = shift;
my $session = $self->session;
my $cart = $self->getCart;
my $i18n = WebGUI::International->new($session, 'PayDriver_Cash');
my $var;
# Make sure we can checkout the cart
return "" unless $self->canCheckoutCart;
# Make sure all required credentials have been supplied
my $billingAddress = $self->getAddress( $session->form->process('addressId') );
return $self->www_getCredentials unless $billingAddress;
# Complete the transaction
my $transaction = $self->processTransaction( $billingAddress );
my $transaction = $self->processTransaction( );
return $transaction->thankYou();
}
#-------------------------------------------------------------------
=head2 www_setBillingAddress {
Stores the selected billing address in this instance.
=cut
sub www_setBillingAddress {
my $self = shift;
my $session = $self->session;
return $self->www_getCredentials($session->form->process('addressId'));
}
1;

View file

@ -61,7 +61,7 @@ sub _generatePaymentRequestXML {
my $self = shift;
my $transaction = shift;
my $session = $self->session;
my $paymentAddress = $self->{ _billingAddress };
my $paymentAddress = $self->getCart->getBillingAddress->get();
my $cardData = $self->{ _cardData };
# Set up the XML.
@ -472,27 +472,6 @@ sub doXmlRequest {
#-------------------------------------------------------------------
=head2 getButton
Return a form to select this payment driver and to accept credentials from those
who wish to use it.
=cut
sub getButton {
my $self = shift;
my $session = $self->session;
my $payForm = WebGUI::Form::formHeader($session)
. $self->getDoFormTags('getCredentials')
. WebGUI::Form::submit($session, {value => $self->get('label') })
. WebGUI::Form::formFooter($session);
return $payForm;
}
#-------------------------------------------------------------------
=head2 handlesRecurring
Tells the commerce system that this payment plugin can handle recurring payments.
@ -519,19 +498,6 @@ sub processCredentials {
my $i18n = WebGUI::International->new($session,'PayDriver_ITransact');
my @error;
# Check address data
push @error, $i18n->get( 'invalid firstName' ) unless $form->process( 'firstName' );
push @error, $i18n->get( 'invalid lastName' ) unless $form->process( 'lastName' );
push @error, $i18n->get( 'invalid address' ) unless $form->process( 'address' );
push @error, $i18n->get( 'invalid city' ) unless $form->process( 'city' );
push @error, $i18n->get( 'invalid email' ) unless $form->email ( 'email' );
push @error, $i18n->get( 'invalid zip' )
if ( !$form->zipcode( 'zipcode' ) && $form->process( 'country' ) eq 'United States' );
# Check credit card data
push @error, $i18n->get( 'invalid card number' ) unless $form->integer('cardNumber');
push @error, $i18n->get( 'invalid cvv2' ) if ($self->get('useCVV2') && !$form->integer('cvv2'));
# Check if expDate and expYear have sane values
my ($currentYear, $currentMonth) = $self->session->datetime->localtime;
my $expires = $form->integer( 'expYear' ) . sprintf '%02d', $form->integer( 'expMonth' );
@ -549,66 +515,11 @@ sub processCredentials {
cvv2 => $form->integer( 'cvv2' ),
};
$self->{ _billingAddress } = {
address1 => $form->process( 'address' ),
code => $form->zipcode( 'zipcode' ),
city => $form->process( 'city' ),
firstName => $form->process( 'firstName' ),
lastName => $form->process( 'lastName' ),
email => $form->email ( 'email' ),
state => $form->process( 'state' ),
country => $form->process( 'country' ),
phoneNumber => $form->process( 'phone' ),
};
return;
}
#-------------------------------------------------------------------
=head2 getBillingAddress ( $addressId )
The billing address is not handled by WebGUI::Shop::Address, it comes from
www_getCredentials. However, WebGUI::Shop::Transaction requires an
WebGUI::Shop::Address object. The billing address is seeded with information
from the shipping address. If this address info is different, then create
a new address to hand to Transaction.
=head3 $addressId
The id of a WebGUI::Shop::Address. If not present, then use the shipping
address instead.
=cut
sub getBillingAddress {
my ($self, $addressId) = @_;
my $address = $addressId
? $self->getAddress( $addressId )
: $self->getCart->getShippingAddress
;
##If the user made any changes to the default address, create a new billing address
##and use it instead
if( $address->get('firstName' ) ne $self->{_billingAddress}->{ 'firstName' }
|| $address->get('lastName' ) ne $self->{_billingAddress}->{ 'lastName' }
|| $address->get('address1' ) ne $self->{_billingAddress}->{ 'address1' }
|| $address->get('city' ) ne $self->{_billingAddress}->{ 'city' }
|| $address->get('state' ) ne $self->{_billingAddress}->{ 'state' }
|| $address->get('code' ) ne $self->{_billingAddress}->{ 'code' }
|| $address->get('country' ) ne $self->{_billingAddress}->{ 'country' }
|| $address->get('phoneNumber' ) ne $self->{_billingAddress}->{ 'phoneNumber' }
|| $address->get('email' ) ne $self->{_billingAddress}->{ 'email' }
) {
my $billingAddress = $self->getCart->getAddressBook->addAddress( $self->{_billingAddress} );
return $billingAddress;
}
return $address;
}
#-------------------------------------------------------------------
=head2 processPayment ($transaction)
Contact ITransact and submit the payment data to them for processing.
@ -725,18 +636,7 @@ sub www_getCredentials {
my $session = $self->session;
my $form = $session->form;
my $i18n = WebGUI::International->new($self->session, 'PayDriver_ITransact');
my $u = WebGUI::User->new($self->session,$self->session->user->userId);
# Process address from address book if passed
my $addressId = $session->form->process( 'addressId' );
my $addressData;
if ( $addressId ) {
$addressData = eval{ $self->getAddress( $addressId )->get() } || {};
}
else {
$addressData = $self->getCart->getShippingAddress->get;
}
my $var = {};
# Process form errors
@ -748,55 +648,11 @@ sub www_getCredentials {
}
}
$var->{getSelectAddressButton} = $self->getSelectAddressButton( 'getCredentials' );
$var->{formHeader} = WebGUI::Form::formHeader($session)
. $self->getDoFormTags('pay');
if ($var->{formHeader}) {
$var->{formHeader} .= WebGUI::Form::hidden($session, {name => 'addressId', value => $addressId});
}
$var->{formFooter} = WebGUI::Form::formFooter();
# Address data form
$var->{firstNameField} = WebGUI::Form::text($session, {
name => 'firstName',
value => $form->process("firstName") || $addressData->{ "firstName" } || $u->profileField('firstName'),
});
$var->{lastNameField} = WebGUI::Form::text($session, {
name => 'lastName',
value => $form->process("lastName") || $addressData->{ "lastName" } || $u->profileField('lastName'),
});
$var->{addressField} = WebGUI::Form::text($session, {
name => 'address',
value => $form->process("address") || $addressData->{ address1 } || $u->profileField('homeAddress'),
});
$var->{cityField} = WebGUI::Form::text($session, {
name => 'city',
value => $form->process("city") || $addressData->{ city } || $u->profileField('homeCity'),
});
$var->{stateField} = WebGUI::Form::text($session, {
name => 'state',
value => $form->process("state") || $addressData->{ state } || $u->profileField('homeState'),
});
$var->{codeField} = WebGUI::Form::zipcode($session, {
name => 'zipcode',
value => $form->process("zipcode") || $addressData->{ code } || $u->profileField('homeZip'),
});
$var->{countryField} = WebGUI::Form::country($session, {
name => 'country',
value => ($form->process("country",'country', '') || $addressData->{ country } || $u->profileField("homeCountry") || 'United States of A'),
});
$var->{phoneField} = WebGUI::Form::phone($session, {
name => 'phone',
value => $form->process("phone",'phone') || $addressData->{ phoneNumber } || $u->profileField("homePhone"),
});
$var->{emailField} = WebGUI::Form::email($session, {
name => 'email',
value => $form->process('email', 'email') || $addressData->{ email } || $u->profileField('email'),
});
# Credit card information
$var->{cardNumberField} = WebGUI::Form::text($session, {
name => 'cardNumber',
@ -814,17 +670,9 @@ sub www_getCredentials {
value => $i18n->get('checkout button', 'Shop'),
extras => 'onclick="this.disabled=true;this.form.submit(); return false;"',
});
$self->appendCartVariables($var);
my $template = eval { WebGUI::Asset::Template->newById($session, $self->get("credentialsTemplateId")); };
my $output;
if (! Exception::Class->caught()) {
$template->prepare;
$output = $template->process($var);
}
else {
$output = $i18n->get('template gone');
}
my $output = $self->processTemplate($self->get("credentialsTemplateId"), $var);
return $session->style->userStyle($output);
}
@ -847,16 +695,8 @@ sub www_pay {
# Go back to checkout form if credentials are not ok
return $self->www_getCredentials( $credentialsErrors ) if $credentialsErrors;
my $addressId = $session->form->process( 'addressId' );
my $billingAddress = $self->getBillingAddress($addressId);
# Payment time!
my $transaction = $self->processTransaction( $billingAddress );
## The billing address object is temporary, just to send to the transaction.
## Delete it if we don't need it.
if ($billingAddress->getId ne $addressId) {
$billingAddress->delete;
}
my $transaction = $self->processTransaction( );
if ($transaction->get('isSuccessful')) {
return $transaction->thankYou();
}

View file

@ -102,6 +102,13 @@ sub definition {
hoverHelp => $i18n->get('use test mode help'),
defaultValue => 1,
},
summaryTemplateId => {
fieldType => 'template',
label => $i18n->get('summary template'),
hoverHelp => $i18n->get('summary template help'),
namespace => 'Shop/Credentials',
defaultValue => 'jysVZeUR0Bx2NfrKs5sulg',
},
);
push @{ $definition }, {
@ -114,28 +121,6 @@ sub definition {
#-------------------------------------------------------------------
=head2 getButton ( )
Returns the HTML for a form containing a button that, when clicked, will take the user to the checkout screen of
this plugin.
=cut
sub getButton {
my $self = shift;
my $session = $self->session;
my $i18n = WebGUI::International->new($session, 'PayDriver_Ogone');
my $payForm = WebGUI::Form::formHeader($session)
. $self->getDoFormTags('getCredentials')
. WebGUI::Form::submit($session, {value => $i18n->get('Ogone') })
. WebGUI::Form::formFooter($session);
return $payForm;
}
#-------------------------------------------------------------------
=head2 getCart
Returns the cart for either the current user or the transaction passed back by Ogone.
@ -273,80 +258,6 @@ sub ogoneCheckoutButton {
#-------------------------------------------------------------------
=head2 www_getCredentials ( [ addressId ] )
Displays the checkout form for this plugin.
=head3 addressId
Optionally supply this variable which will set the payment address to this addressId.
=cut
sub www_getCredentials {
my ($self, $addressId) = @_;
my $session = $self->session;
my $i18n = WebGUI::International->new( $session, 'PayDriver_Ogone' );
# Process address from address book if passed
$addressId = $session->form->process( 'addressId' );
my $address;
if ( $addressId ) {
$address = eval{ $self->getAddress( $addressId ) };
}
else {
$address = $self->getCart->getShippingAddress;
}
my $billingAddressHtml = $address->getHtmlFormatted;
# Fetch transaction
my $transactionId = $session->form->process('transactionId');
my $transaction;
if ($transactionId) {
$transaction = WebGUI::Shop::Transaction->new( $session, $transactionId );
}
# Or generate a new one
unless ($transaction) {
$transaction = $self->processTransaction( $address );
}
# Set the billing address
$transaction->update( {
paymentAddress => $address,
} );
# Generate the json string that defines where the address book posts the selected address
my $callbackParams = {
url => $session->url->page,
params => [
{ name => 'shop', value => 'pay' },
{ name => 'method', value => 'do' },
{ name => 'do', value => 'getCredentials' },
{ name => 'paymentGatewayId', value => $self->getId },
],
};
my $callbackJson = JSON::to_json( $callbackParams );
# Generate 'Choose billing address' button
my $addressButton = WebGUI::Form::formHeader( $session )
. WebGUI::Form::hidden( $session, { name => 'shop', value => 'address' } )
. WebGUI::Form::hidden( $session, { name => 'method', value => 'view' } )
. WebGUI::Form::hidden( $session, { name => 'callback', value => $callbackJson } )
. WebGUI::Form::submit( $session, { value => $i18n->get('choose billing address') } )
. WebGUI::Form::formFooter( $session);
# Generate 'Proceed' button
my $proceedButton = $address
? $self->ogoneCheckoutButton( $transaction, $address )
: $i18n->get('please choose a billing address')
;
return $session->style->userStyle($addressButton.'<br />'.$billingAddressHtml.'<br />'.$proceedButton);
}
#-------------------------------------------------------------------
=head2 checkPostbackSHA ( )
Processes the postback data Ogone sends after a payment/cancelation. Figures out which transaction the data belongs
@ -547,6 +458,40 @@ sub www_edit {
#-------------------------------------------------------------------
=head2 www_getCredentials ( )
Displays the checkout form for this plugin.
=cut
sub www_getCredentials {
my ($self) = @_;
my $session = $self->session;
# Fetch transaction
my $transactionId = $session->form->process('transactionId');
my $transaction;
if ($transactionId) {
$transaction = WebGUI::Shop::Transaction->new( $session, $transactionId );
}
# Or generate a new one
unless ($transaction) {
$transaction = $self->processTransaction( );
}
# Generate 'Proceed' button
my $var = {
proceedButton => $self->ogoneCheckoutButton,
};
$self->appendCartVariables($var);
my $output = $self->processTemplate($self->get("summaryTemplateId"), $var);
return $session->style->userStyle($output);
}
#-------------------------------------------------------------------
=head2 www_processTransaction ( )
This method is called by the post sale notfication.

View file

@ -339,4 +339,3 @@ sub getPaypalCountry {
}
1;

View file

@ -106,6 +106,14 @@ sub definition {
$fields{paypal}{defaultValue} = 'https://www.paypal.com/webscr';
$fields{api}{defaultValue} = 'https://api-3t.payPal.com/nvp';
$fields{summaryTemplateId} = {
fieldType => 'template',
label => $i18n->get('summary template'),
hoverHelp => $i18n->get('summary template help'),
namespace => 'Shop/Credentials',
defaultValue => 'GqnZPB0gLoZmqQzYFaq7bg',
},
push @{$definition}, {
name => $i18n->get('name'),
properties => \%fields,

View file

@ -123,6 +123,13 @@ sub definition {
hoverHelp => $i18n->get('button image help'),
defaultValue => '',
},
summaryTemplateId => {
fieldType => 'template',
label => $i18n->get('summary template'),
hoverHelp => $i18n->get('summary template help'),
namespace => 'Shop/Credentials',
defaultValue => '',
},
);
push @{$definition},
@ -164,7 +171,7 @@ sub getButton {
# do a submit button with i18n'd paypal text. If they did, we'll use an
# image submit.
my $button;
my $i18n = WebGUI::International->new( $session, 'PayDriver_PayPalStd' );
my $i18n = WebGUI::International->new( $session, 'PayDriver_PayPalStd' );
my $text = $i18n->get('PayPal');
if ( $self->get('buttonImage') ) {
my $raw = $self->get('buttonImage');
@ -329,5 +336,5 @@ sub www_completeTransaction {
: $self->displayPaymentError($transaction);
}
1;
1;