Last active
June 21, 2018 19:19
-
-
Save skenderbeu/af3ad9233dd7f7ffdf0809c8aa553842 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void createDomesticShipment( utcdatetime _shipmentDate, | |
SalesTable _salesTable, | |
str _noOfParcels = "1" | |
) | |
{ | |
RoyalMail.shippingAPIPortTypeClient serviceClient; | |
RoyalMail.createShipmentRequest shipmentRequest; | |
RoyalMail.createShipmentResponse shipmentResponse; | |
RoyalMail.contact contact; | |
RoyalMail.address address; | |
RoyalMail.requestedShipment requestedShipment; | |
RoyalMail.SecurityHeaderType securityHeaderType; | |
RoyalMail.integrationFooter integrationFooter; | |
ShipCarrierTrackingNum rmShipmentIdLocal; | |
System.Exception interopException; | |
SalesTable salesTable; | |
RMNotificationType notificationType; | |
container containerAddress; | |
str deliveryInstruction; | |
boolean signature; | |
RecId logRecId; | |
salesTable = _salesTable; | |
deliveryInstruction = _salesTable.OSSDeliveryInstruction; | |
notificationType = this.parmNotificationType(); | |
logRecId = this.logRequest(RM_RequestMethod::CreateShipment, salesTable.SalesId); | |
if(!this.parmShipmentCreationDate()) | |
{ | |
this.parmShipmentCreationDate(_shipmentDate); | |
} | |
if(!logRecId) | |
{ | |
logRecId = salesTable.RecId; | |
} | |
new InteropPermission(InteropKind::ClrInterop).assert(); | |
try | |
{ | |
serviceClient = this.getRMServiceClient(); | |
// Create Request | |
shipmentRequest = new RoyalMail.createShipmentRequest(); | |
shipmentRequest.set_integrationHeader(this.getIntegrationHeader(_salesTable.SalesId)); | |
contact = this.getContact(salesTable, notificationType); | |
containerAddress = this.getAddressFields(SalesTable.deliveryAddress().Address); | |
address = this.getAddress(salesTable.deliveryAddress().City, containerAddress, salesTable.deliveryAddress().ZipCode, "GB"); | |
signature = this.parmCarrierConfig().Signature == NoYes::Yes ? true: false; | |
shipmentRequest.set_requestedShipment(this.getShipment( | |
contact,address, _shipmentDate, | |
notificationType, _noOfParcels, | |
salesTable.SalesId, | |
deliveryInstruction, | |
signature, salesTable.OSSBrandId)); | |
securityHeaderType = this.GetSecurityHeaderType(logRecId); | |
// Handle Response | |
shipmentResponse = serviceClient.createShipment(securityHeaderType, shipmentRequest); | |
if(shipmentResponse) | |
{ | |
integrationFooter = shipmentResponse.get_integrationFooter(); | |
if(integrationFooter) | |
{ | |
this.processResponseWarnings(integrationFooter.get_warnings()); | |
if(!this.hasResponseErrors(integrationFooter.get_errors())) | |
{ | |
rmShipmentIdLocal = this.getShipmentID(shipmentResponse); | |
this.updateRequestLogStatus(logRecId); | |
} | |
} | |
else | |
{ | |
rmShipmentIdLocal = this.getShipmentID(shipmentResponse); | |
this.updateRequestLogStatus(logRecId); | |
} | |
} | |
else | |
{ | |
throw error("Error in response from Royal Mail create shipment service"); | |
} | |
serviceClient.Close(); | |
} | |
catch(Exception::CLRError) | |
{ | |
interopException = CLRInterop::getLastException(); | |
if(interopException) | |
{ | |
error(CLRInterop::getAnyTypeForObject(interopException.ToString())); | |
} | |
serviceClient.Abort(); | |
} | |
CodeAccessPermission::revertAssert(); | |
this.parmShipmentId(rmShipmentIdLocal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment