Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions lib/Shipment/Purolator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,185 @@ sub ship {

}

=head2 return

This calls CreateReturnsManagementShipment from the ReturnsManagement API

It also calls fetch_documents which is a separate method since Purolator does not return the label along with the create shipment response.

=cut

sub return {
my ( $self, $service_id ) = @_;

try {
$service_id = $self->services->{$service_id}->id;
} catch {
warn $_ if $self->debug;
warn "service ($service_id) not available" if $self->debug;
$self->error( "service ($service_id) not available" );
$service_id = '';
};
return unless $service_id;

my $total_weight;
$total_weight += $_->weight for @{ $self->packages };

my @pieces;
foreach (@{ $self->packages }) {
if ($self->package_type eq 'custom') {
push @pieces,
{
Weight => {
Value => sprintf("%.0f", $_->weight) || 1,
WeightUnit => $self->weight_unit,
},
Length => {
Value => $_->length,
DimensionUnit => $self->dim_unit,
},
Width => {
Value => $_->width,
DimensionUnit => $self->dim_unit,
},
Height => {
Value => $_->height,
DimensionUnit => $self->dim_unit,
},
};
}
else {
push @pieces,
{
Weight => {
Value => sprintf("%.0f", $_->weight) || 1,
WeightUnit => $self->weight_unit,
},
};
}
}

use Shipment::Purolator::WSDLV2::Interfaces::ReturnsManagement::ReturnsManagementServiceEndpoint;
my $interface = Shipment::Purolator::WSDLV2::Interfaces::ReturnsManagement::ReturnsManagementServiceEndpoint->new(
{
proxy_domain => $self->proxy_domain,
key => $self->key,
password => $self->password,
}
);

$Shipment::SOAP::WSDL::Debug = 1 if $self->debug > 1;
my $response = $interface->CreateReturnsManagementShipment(
{
ReturnsManagementShipment => {
SenderInformation => {
Address => {
Name => $self->from_address->name,
Company => $self->from_address->company,
StreetNumber => $self->from_address->address_components->{number},
StreetName => $self->from_address->address_components->{street} . ' ' . $self->from_address->address_components->{direction},
StreetAddress2 => $self->from_address->address2,
City => $self->from_address->city,
Province => $self->from_address->province_code,
Country => $self->from_address->country_code,
PostalCode => $self->from_address->postal_code,
PhoneNumber => {
CountryCode => $self->from_address->phone_components->{country},
AreaCode => $self->from_address->phone_components->{area},
Phone => $self->from_address->phone_components->{phone},
},
},
},
ReceiverInformation => {
Address => {
Name => $self->to_address->name,
Company => $self->to_address->company,
StreetNumber => $self->to_address->address_components->{number},
StreetName => $self->to_address->address_components->{street} . ' ' . $self->to_address->address_components->{direction},
StreetAddress2 => $self->to_address->address2,
City => $self->to_address->city,
Province => $self->to_address->province_code,
Country => $self->to_address->country_code,
PostalCode => $self->to_address->postal_code,
PhoneNumber => {
CountryCode => $self->to_address->phone_components->{country},
AreaCode => $self->to_address->phone_components->{area},
Phone => $self->to_address->phone_components->{phone},
},
},
},
PackageInformation => {
ServiceID => $service_id,
TotalWeight => {
Value => sprintf("%.0f", $total_weight) || 1,
WeightUnit => $self->weight_unit,
},
TotalPieces => scalar @{ $self->packages },
PiecesInformation => {
Piece => \@pieces,
},
},
PaymentInformation => {
PaymentType => $bill_type_map{$self->bill_type} || $self->bill_type,
RegisteredAccountNumber => $self->account,
BillingAccountNumber => $self->bill_account,
},
PickupInformation => {
PickupType => $pickup_type_map{$self->pickup_type} || $self->pickup_type,
},
TrackingReferenceInformation => {
Reference1 => $self->get_reference(0),
Reference2 => $self->get_reference(1),
Reference3 => $self->get_reference(2),
Reference4 => $self->get_reference(3),
},
OtherInformation => {
SpecialInstructions => $self->special_instructions,
},
},
PrinterType => $printer_type_map{$self->printer_type} || $self->printer_type,
},
{
'Version' => '2.0',
'Language' => 'en',
'GroupID' => 'xxx',
'RequestReference' => 'Shipment::Purolator::return'
},
);

$Shipment::SOAP::WSDL::Debug = 0;
warn "Response\n" . $response if $self->debug > 1;

try {
$self->tracking_id( $response->get_ShipmentPIN()->get_Value()->get_value );
use Shipment::Label;
my $package_index = 0;
foreach (@{ $response->get_PiecePINs()->get_PIN() }) {
$self->get_package($package_index)->tracking_id($_->get_Value()->get_value);
$self->get_package($package_index)->label(
Shipment::Label->new(
{
tracking_id => $_->get_Value()->get_value,
},
)
);
$package_index++
}
} catch {
try {
warn $_ if $self->debug;
warn $response->get_ResponseInformation()->get_Errors()->get_Error()->[0]->get_Description if $self->debug;
$self->error( $response->get_ResponseInformation()->get_Errors()->get_Error()->[0]->get_Description->get_value );
} catch {
warn $_ if $self->debug;
warn $response->get_faultstring if $self->debug;
$self->error( $response->get_faultstring->get_value );
};
};

$self->fetch_documents();
}

=head2 fetch_documents

Calls GetDocuments from the Shipping Documents API
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@

package Shipment::Purolator::WSDLV2::Elements::CreateReturnsManagementShipmentRequest;
use strict;
use warnings;

{ # BLOCK to scope variables

sub get_xmlns { 'http://purolator.com/pws/datatypes/v2' }

__PACKAGE__->__set_name('CreateReturnsManagementShipmentRequest');
__PACKAGE__->__set_nillable(1);
__PACKAGE__->__set_minOccurs();
__PACKAGE__->__set_maxOccurs();
__PACKAGE__->__set_ref();
use base qw(
SOAP::WSDL::XSD::Typelib::Element
Shipment::Purolator::WSDLV2::Types::CreateReturnsManagementShipmentRequestContainer
);

}

1;


=pod

=head1 NAME

Shipment::Purolator::WSDLV2::Elements::CreateReturnsManagementShipmentRequest

=head1 DESCRIPTION

Perl data type class for the XML Schema defined element
CreateReturnsManagementShipmentRequest from the namespace http://purolator.com/pws/datatypes/v2.







=head1 METHODS

=head2 new

my $element = Shipment::Purolator::WSDLV2::Elements::CreateReturnsManagementShipmentRequest->new($data);

Constructor. The following data structure may be passed to new():

{ # Shipment::Purolator::WSDLV2::Types::CreateReturnsManagementShipmentRequest
ReturnsManagementShipment => { # Shipment::Purolator::WSDLV2::Types::Shipment
SenderInformation => { # Shipment::Purolator::WSDLV2::Types::SenderInformation
Address => { # Shipment::Purolator::WSDLV2::Types::Address
Name => $some_value, # string
Company => $some_value, # string
Department => $some_value, # string
StreetNumber => $some_value, # string
StreetSuffix => $some_value, # string
StreetName => $some_value, # string
StreetType => $some_value, # string
StreetDirection => $some_value, # string
Suite => $some_value, # string
Floor => $some_value, # string
StreetAddress2 => $some_value, # string
StreetAddress3 => $some_value, # string
City => $some_value, # string
Province => $some_value, # string
Country => $some_value, # string
PostalCode => $some_value, # string
PhoneNumber => { # Shipment::Purolator::WSDLV2::Types::PhoneNumber
CountryCode => $some_value, # string
AreaCode => $some_value, # string
Phone => $some_value, # string
Extension => $some_value, # string
},
FaxNumber => {}, # Shipment::Purolator::WSDLV2::Types::PhoneNumber
},
TaxNumber => $some_value, # string
},
ReceiverInformation => { # Shipment::Purolator::WSDLV2::Types::ReceiverInformation
Address => {}, # Shipment::Purolator::WSDLV2::Types::Address
TaxNumber => $some_value, # string
},
PackageInformation => { # Shipment::Purolator::WSDLV2::Types::PackageInformation
ServiceID => $some_value, # string
Description => $some_value, # string
TotalWeight => { # Shipment::Purolator::WSDLV2::Types::TotalWeight
Value => $some_value, # int
WeightUnit => $some_value, # WeightUnit
},
TotalPieces => $some_value, # int
PiecesInformation => { # Shipment::Purolator::WSDLV2::Types::ArrayOfPiece
Piece => { # Shipment::Purolator::WSDLV2::Types::Piece
Weight => { # Shipment::Purolator::WSDLV2::Types::Weight
Value => $some_value, # decimal
WeightUnit => $some_value, # WeightUnit
},
Length => { # Shipment::Purolator::WSDLV2::Types::Dimension
Value => $some_value, # decimal
DimensionUnit => $some_value, # DimensionUnit
},
Width => {}, # Shipment::Purolator::WSDLV2::Types::Dimension
Height => {}, # Shipment::Purolator::WSDLV2::Types::Dimension
Options => { # Shipment::Purolator::WSDLV2::Types::ArrayOfOptionIDValuePair
OptionIDValuePair => { # Shipment::Purolator::WSDLV2::Types::OptionIDValuePair
ID => $some_value, # string
Value => $some_value, # string
},
},
},
},
DangerousGoodsDeclarationDocumentIndicator => $some_value, # boolean
},
PaymentInformation => {}, # Shipment::Purolator::WSDLV2::Types::PaymentInformation
PickupInformation => {}, # Shipment::Purolator::WSDLV2::Types::PickupInformation
TrackingReferenceInformation => {}, # Shipment::Purolator::WSDLV2::Types::TrackingReferenceInformation
OtherInformation => {}, # Shipment::Purolator::WSDLV2::Types::OtherInformation
},
PrinterType => $some_value, # PrinterType
},

=head1 AUTHOR

Generated by SOAP::WSDL

=cut

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

package Shipment::Purolator::WSDLV2::Elements::CreateReturnsManagementShipmentResponse;
use strict;
use warnings;

{ # BLOCK to scope variables

sub get_xmlns { 'http://purolator.com/pws/datatypes/v2' }

__PACKAGE__->__set_name('CreateReturnsManagementShipmentResponse');
__PACKAGE__->__set_nillable(1);
__PACKAGE__->__set_minOccurs();
__PACKAGE__->__set_maxOccurs();
__PACKAGE__->__set_ref();
use base qw(
SOAP::WSDL::XSD::Typelib::Element
Shipment::Purolator::WSDLV2::Types::CreateReturnsManagementShipmentResponseContainer
);

}

1;


=pod

=head1 NAME

Shipment::Purolator::WSDLV2::Elements::CreateReturnsManagementShipmentResponse

=head1 DESCRIPTION

Perl data type class for the XML Schema defined element
CreateReturnsManagementShipmentResponse from the namespace http://purolator.com/pws/datatypes/v2.







=head1 METHODS

=head2 new

my $element = Shipment::Purolator::WSDLV2::Elements::CreateReturnsManagementShipmentResponse->new($data);

Constructor. The following data structure may be passed to new():

{ # Shipment::Purolator::WSDLV2::Types::CreateReturnsManagementShipmentResponseContainer
ShipmentPIN => { # Shipment::Purolator::WSDLV2::Types::PIN
Value => $some_value, # string
},
PiecePINs => { # Shipment::Purolator::WSDLV2::Types::ArrayOfPIN
PIN => {}, # Shipment::Purolator::WSDLV2::Types::PIN
},
RMA => # SOAP::WSDL::XSD::Typelib::Builtin::string
},

=head1 AUTHOR

Generated by SOAP::WSDL

=cut

Loading