Check for valid shipping and payment drivers for checkout. Rebuild transaction to take all info from the Cart.
This commit is contained in:
parent
1ef4aa8ef0
commit
d48d9bc90f
3 changed files with 81 additions and 48 deletions
|
|
@ -291,6 +291,19 @@ sub getBillingAddress {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getPaymentGateway ()
|
||||
|
||||
Returns the WebGUI::Shop::PayDriver object that is attached to this cart for payment.
|
||||
|
||||
=cut
|
||||
|
||||
sub getPaymentGateway {
|
||||
my $self = shift;
|
||||
return WebGUI::Shop::Pay->new($self->session)->getPaymentGateway($self->get("gatewayId"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ()
|
||||
|
||||
Returns the unique id for this cart.
|
||||
|
|
@ -520,6 +533,7 @@ Returns whether all the required properties of the the cart are set.
|
|||
|
||||
sub readyForCheckout {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
# Check if the billing address is set and correct
|
||||
my $address = eval{$self->getBillingAddress};
|
||||
|
|
@ -551,9 +565,21 @@ sub readyForCheckout {
|
|||
##Must have a configured shipping id.
|
||||
return 0 if ! $self->get('shipperId');
|
||||
|
||||
my $shipper = eval { WebGUI::Shop::ShipDriver->new($session, $self->get('shipperId'))};
|
||||
if (my $e = WebGUI::Error->caught) {
|
||||
$self->error($e->error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
##Must have a configured payment method.
|
||||
return 0 if ! $self->get('gatewayId');
|
||||
|
||||
my $gateway = eval { WebGUI::Shop::PayDriver->new($session, $self->get('gatewayId'))};
|
||||
if (my $e = WebGUI::Error->caught) {
|
||||
$self->error($e->error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
##Check for any other logged errors
|
||||
return 0 if $error{ id $self };
|
||||
|
||||
|
|
@ -733,23 +759,23 @@ sub updateFromForm {
|
|||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_checkout ( )
|
||||
|
||||
Update the cart and then redirect the user to the payment gateway screen.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_checkout {
|
||||
my $self = shift;
|
||||
$self->updateFromForm;
|
||||
if ($error{id $self} ne "") {
|
||||
return $self->www_view;
|
||||
}
|
||||
$self->session->http->setRedirect($self->session->url->page('shop=pay;method=selectPaymentGateway'));
|
||||
return undef;
|
||||
}
|
||||
|
||||
#
|
||||
#=head2 www_checkout ( )
|
||||
#
|
||||
#Update the cart and then redirect the user to the payment gateway screen.
|
||||
#
|
||||
#=cut
|
||||
#
|
||||
#sub www_checkout {
|
||||
# my $self = shift;
|
||||
# $self->updateFromForm;
|
||||
# if ($error{id $self} ne "") {
|
||||
# return $self->www_view;
|
||||
# }
|
||||
# $self->session->http->setRedirect($self->session->url->page('shop=pay;method=selectPaymentGateway'));
|
||||
# return undef;
|
||||
#}
|
||||
#
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_continueShopping ( )
|
||||
|
|
@ -855,6 +881,9 @@ Updates the cart totals and then displays the cart again.
|
|||
sub www_update {
|
||||
my $self = shift;
|
||||
$self->updateFromForm;
|
||||
if ($self->session->form->get('checkout') && $self->readyForCheckout()) {
|
||||
|
||||
}
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -625,7 +625,6 @@ sub processTransaction {
|
|||
my $transactionProperties;
|
||||
$transactionProperties->{ paymentMethod } = $self;
|
||||
$transactionProperties->{ cart } = $cart;
|
||||
$transactionProperties->{ paymentAddress } = $paymentAddress if defined $paymentAddress;
|
||||
$transactionProperties->{ isRecurring } = $cart->requiresRecurringPayment;
|
||||
|
||||
# Create a transaction...
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ This package keeps records of every puchase made.
|
|||
my $transaction = WebGUI::Shop::Transaction->new($session, $id);
|
||||
|
||||
# typical transaction goes like this:
|
||||
my $transaction = WebGUI::Shop::Transaction->create({ cart=>$cart, paymentMethod=>$paymentMethod, paymentAddress=>$address});
|
||||
my $transaction = WebGUI::Shop::Transaction->create({ cart=>$cart });
|
||||
my ($transactionNumber, $status, $message) = $paymentMethod->tryTransaction;
|
||||
if ($status eq "somekindofsuccess") {
|
||||
$transaction->completePurchase($cart, $transactionNumber, $status, $message);
|
||||
|
|
@ -745,44 +745,49 @@ sub update {
|
|||
if (exists $newProperties->{cart}) {
|
||||
my $cart = $newProperties->{cart};
|
||||
$newProperties->{taxes} = $cart->calculateTaxes;
|
||||
my $address = $cart->getShippingAddress;
|
||||
$newProperties->{shippingAddressId} = $address->getId;
|
||||
$newProperties->{shippingAddressName} = $address->get('firstName') . " " .$address->get('lastName');
|
||||
$newProperties->{shippingAddress1} = $address->get('address1');
|
||||
$newProperties->{shippingAddress2} = $address->get('address2');
|
||||
$newProperties->{shippingAddress3} = $address->get('address3');
|
||||
$newProperties->{shippingCity} = $address->get('city');
|
||||
$newProperties->{shippingState} = $address->get('state');
|
||||
$newProperties->{shippingCountry} = $address->get('country');
|
||||
$newProperties->{shippingCode} = $address->get('code');
|
||||
$newProperties->{shippingPhoneNumber} = $address->get('phoneNumber');
|
||||
my $shippingAddress = $cart->getShippingAddress;
|
||||
$newProperties->{shippingAddressId} = $shippingAddress->getId;
|
||||
$newProperties->{shippingAddressName} = $shippingAddress->get('firstName') . " " . $shippingAddress->get('lastName');
|
||||
$newProperties->{shippingAddress1} = $shippingAddress->get('address1');
|
||||
$newProperties->{shippingAddress2} = $shippingAddress->get('address2');
|
||||
$newProperties->{shippingAddress3} = $shippingAddress->get('address3');
|
||||
$newProperties->{shippingCity} = $shippingAddress->get('city');
|
||||
$newProperties->{shippingState} = $shippingAddress->get('state');
|
||||
$newProperties->{shippingCountry} = $shippingAddress->get('country');
|
||||
$newProperties->{shippingCode} = $shippingAddress->get('code');
|
||||
$newProperties->{shippingPhoneNumber} = $shippingAddress->get('phoneNumber');
|
||||
|
||||
my $billingAddress = $cart->getBillingAddress;
|
||||
$newProperties->{paymentAddressId} = $billingAddress->getId;
|
||||
$newProperties->{paymentAddressName} = $billingAddress->get('firstName') . " " . $billingAddress->get('lastName');
|
||||
$newProperties->{paymentAddress1} = $billingAddress->get('address1');
|
||||
$newProperties->{paymentAddress2} = $billingAddress->get('address2');
|
||||
$newProperties->{paymentAddress3} = $billingAddress->get('address3');
|
||||
$newProperties->{paymentCity} = $billingAddress->get('city');
|
||||
$newProperties->{paymentState} = $billingAddress->get('state');
|
||||
$newProperties->{paymentCountry} = $billingAddress->get('country');
|
||||
$newProperties->{paymentCode} = $billingAddress->get('code');
|
||||
$newProperties->{paymentPhoneNumber} = $billingAddress->get('phoneNumber');
|
||||
|
||||
my $shipper = $cart->getShipper;
|
||||
$newProperties->{shippingDriverId} = $shipper->getId;
|
||||
$newProperties->{shippingDriverId} = $shipper->getId;
|
||||
$newProperties->{shippingDriverLabel} = $shipper->get('label');
|
||||
$newProperties->{shippingPrice} = $shipper->calculate($cart);
|
||||
$newProperties->{amount} = $cart->calculateTotal + $newProperties->{shopCreditDeduction};
|
||||
$newProperties->{shippingPrice} = $shipper->calculate($cart);
|
||||
$newProperties->{amount} = $cart->calculateTotal + $newProperties->{shopCreditDeduction};
|
||||
$newProperties->{shopCreditDeduction} = $cart->calculateShopCreditDeduction($newProperties->{amount});
|
||||
$newProperties->{amount} += $newProperties->{shopCreditDeduction};
|
||||
$newProperties->{amount} += $newProperties->{shopCreditDeduction};
|
||||
|
||||
my $pay = $cart->getPaymentGateway;
|
||||
$newProperties->{paymentDriverId} = $pay->getId;
|
||||
$newProperties->{paymentDriverLabel} = $pay->get('label');
|
||||
|
||||
foreach my $item (@{$cart->getItems}) {
|
||||
$self->addItem({item=>$item});
|
||||
}
|
||||
}
|
||||
if (exists $newProperties->{paymentAddress}) {
|
||||
my $address = $newProperties->{paymentAddress};
|
||||
$newProperties->{paymentAddressId} = $address->getId;
|
||||
$newProperties->{paymentAddressName} = $address->get('firstName') ." ". $address->get('lastName');
|
||||
$newProperties->{paymentAddress1} = $address->get('address1');
|
||||
$newProperties->{paymentAddress2} = $address->get('address2');
|
||||
$newProperties->{paymentAddress3} = $address->get('address3');
|
||||
$newProperties->{paymentCity} = $address->get('city');
|
||||
$newProperties->{paymentState} = $address->get('state');
|
||||
$newProperties->{paymentCountry} = $address->get('country');
|
||||
$newProperties->{paymentCode} = $address->get('code');
|
||||
$newProperties->{paymentPhoneNumber} = $address->get('phoneNumber');
|
||||
}
|
||||
if (exists $newProperties->{paymentMethod}) {
|
||||
my $pay = $newProperties->{paymentMethod};
|
||||
$newProperties->{paymentDriverId} = $pay->getId;
|
||||
$newProperties->{paymentDriverId} = $pay->getId;
|
||||
$newProperties->{paymentDriverLabel} = $pay->get('label');
|
||||
}
|
||||
my @fields = (qw( isSuccessful transactionCode statusCode statusMessage amount shippingAddressId
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue