2. Check Package Status and Download Documents

Following up on the creating and sending a document package quick start guide, this guide will cover some things you can do after sending the package, such as: checking the package/signing status, downloading the e-signed documents, and downloading the evidence summary.

This guide will pick up right where you left off in the previous guide. If you followed along, you had just looked in your OneSpan Sign inbox to see that your document package (transaction in the new UI) was created and sent properly after executing the Java class built in the previous guide.

Capture

Configuration

Initial Setup

Create a new .java file for this guide. You can place it in the same location as in the last guide or you can start a new project. For example, “SimpleCheckStatusAndDownload.java”. If you need help with this setup, head over to the previous guide for further instructions.

Locating the Package ID of your Existing Project

Since the package you are working with was created previously, we need to find the package ID for use in this project. If you select the project from the UI inbox, as seen above, the URL will have the package ID, like this:

https://sandbox.esignlive.com/a/transaction/{packageId}

In the Java class you created in the last guide, you will see you had access to this package ID when you created the package and used it to send the package. If you were creating a more complex application, you would likely store this package ID for use within other parts of your application, versus looking it up in your OneSpan Sign URLs.

If you want to see this package ID coming from the Java class made in the previous guide, you could add the line:

System.out.println(“PackageId: “ + packageId);

After the line:

PackageId packageId = eslClient.createPackage( documentPackage );

If you run that class again, you will now see the package ID printed to the console view within Eclipse.

Capture

The Code

In this segment, the code will be explained section by section. You can get the complete sample code from the Developer Community Code Share, here.

Access the Package

The first few lines define your connection information for OneSpan Sign.

public static final String API_KEY = "";
public static final String API_URL = "https://sandbox.esignlive.com/api";
// USE https://apps.esignlive.com/api FOR PRODUCTION

Be sure to put your API_KEY in place of the placeholder.

Again, because this is a very simple example, the rest is done within the main method. The first line inside the main method is where you connect to OneSpan Sign using your connection info, from above.

//connect to OneSpan Sign
EslClient eslClient = new EslClient( API_KEY, API_URL );

Next, a PackageId object is created using the Package ID you got from your URL (or package creation Java class), above. Then, you will use that PackageId object to grab your previously sent package from the OneSpan Sign client.

//create a packageId using you packageId string
PackageId packageId = new PackageId("");
//get your package
DocumentPackage sentPackage = eslClient.getPackage(packageId);

Check the Status

Now that you have access to the document package, you can check your package to see what the package status is. The possible values are ARCHIVED, COMPLETED, DECLINED, DRAFT, EXPIRED, OPTED_OUT, and SENT. Print the status so you can see it in the console when you execute your class.

//checking package status
PackageStatus status = sentPackage.getStatus();
System.out.println(status);

Next, check the signing status of the package. The possible values for this one are ARCHIVED, CANCELED, COMPLETE, DECLINED, EXPIRED, INACTIVE, OPTED_OUT, COMPLETED, and SIGNING_PENDING. Print this status to the console, as well.

//checking signing status
SigningStatus sentSigningStatus = eslClient.getSigningStatus( packageId, null, null );
System.out.println(sentSigningStatus.getToken());

Download the Files

For the last part, you will check to see if the package is complete. If it is, the zip file of all documents will be downloaded, as well as the evidence summary. By putting just a file name for each file in the Files.saveTo… lines, the file will be saved to the root of your Java project in Eclipse. After each step, print to the console so that you know the event happened when you test the Java class in the next step.

if(sentSigningStatus.getToken() != "COMPLETED"){ //if signing is complete, download all documents
	
	System.out.println("Cannot Download: Signing not complete");
	
} else { //download zip file
	
 	byte[] documentZip = eslClient.downloadZippedDocuments(packageId);
 	Files.saveTo(documentZip, "documentZip.zip");
 	System.out.println("Document Zip File Downloaded");
         	
 	//download evidence summary
 	byte[] evidenceSummary = eslClient.downloadEvidenceSummary(packageId);
   	Files.saveTo(evidenceSummary, "evidenceSummary.pdf");
   	System.out.println("Evidence Summary Downloaded");
}

Running the Code

You can now execute your Java class. Run the class from the toolbar, menu bar, or by right clicking on the class in the Package Explorer and going to Run As -> Java Application.

If you have not yet signed your package, your Console should look like the following:

Capture

After signing your package, you will get the following output in your Console view:

Capture

If you refresh your project in your Package Explorer by right-clicking and going to Refresh, you will see that your files were successfully downloaded.

Capture

Get the Code