Package Tracking
Server-side configuration
- Place transaction
- Java
TransactionRequest request = new TransactionRequest()
.amount(request.queryParams("amount"))
.paymentMethodNonce(request.queryParams("paymentMethodNonce"))
.deviceData(request.queryParams("device_data"))
.orderId("Mapped to PayPal Invoice Number")
.options()
.submitForSettlement(true)
.paypal()
.customField("PayPal custom field")
.description("Description for PayPal email receipt")
.done()
.storeInVaultOnSuccess(true)
.done()
.lineItem()
.name("Product")
.kind(TransactionLineItem.Kind.DEBIT)
.quantity(new BigDecimal("10.0000"))
.unitAmount(new BigDecimal("9.5000"))
.unitOfMeasure("unit")
.totalAmount(new BigDecimal("95.00"))
.taxAmount(new BigDecimal("5.00"))
.discountAmount(new BigDecimal("0.00"))
.productCode("54321")
.upcCode("01234567812") //new field
.upcType("UPC-A") //new field
.url("https://example.com")
.imageUrl("https://example.com/product1.jpeg") //new field
.done();
Result<Transaction> saleResult = gateway.transaction().sale(request);
if (result.isSuccess()) {
Transaction transaction = result.getTarget();
System.out.println("Success ID: " + transaction.getId());
} else {
System.out.println("Message: " + result.getMessage());
}
- Create tracking for transaction after submitting for settlement:
- Java
/*
* Create or retrieve Transaction for which package tracking information needs
* to be supplemented with transaction.sale(), find() etc.
*/
Transaction transaction = result.getTarget();
/* Optionally create line items */
TransactionLineItemRequest packageLine1 = new TransactionLineItemRequest()
.productCode("ABC 01")
.quantity(new BigDecimal(1))
.name("Product Name")
.description("Product Description")
.upcCode("01234567812") //new field
.upcType("UPC-A") //new field
.url("https://example.com")
.imageUrl("https://example.com/product1.jpeg"); //new field
/* Optionally create line items */
TransactionLineItemRequest packageLine2 = new TransactionLineItemRequest()
.productCode("ABC 02")
.quantity(new BigDecimal(1))
.name("Product Name")
.description("Product Description")
.upcCode("01234567812") //new field
.upcType("UPC-A") //new field
.url("https://example.com")
.imageUrl("https://example.com/product2.jpeg"); //new field
/*
* Create a Package Tracking request with optional line items
*/
PackageTrackingRequest package = new PackageTrackingRequest ()
.carrier("UPS")
.notifyPayer(true)
.trackingNumber("tracking_number_1")
.addLineItem(packageLine1)
.addLineItem(packageLine2);
/* Send the package tracking request for the transaction */
Result<Transaction> packageTrackingResult = gateway.transaction()
.packageTracking(transaction.getId(), package);
Transaction transactionWithPackageDetails = packageTrackingResult.getTarget();
List<PackageDetails> packages = transactionWithPackageDetails.getPackages();
String id = packages.get(0).getId();
String trackingNumber = packages.get(0).getTrackingNumber();
String carrier = packages.get(0).getCarrier();
*
* The PayPal tracker ID will not be immediately available in response to
* packageTracking(). But should be there when merchant does a findTransaction
* request at a later stage.
*/
- Retrieve transactions with package trackers:
- Java
/*
* Get more details of the individual packages like so,
* replace 0 with the element index.
*/
Transaction transaction = gateway.transaction().find(transactionId);
String id = transaction.packages.get(0).getId();
String trackingNumber = transaction.getPackages().get(0).getTrackingNumber();
String carrier = transaction.getPackages().get(0).getCarrier();
String paypalTrackerId = transaction.getPackages().get(0).getPayPalTrackerId();
/*
* The PayPal tracker ID will not be immediately available in response to
* packageTracking(). But should be there when merchant does a findTransaction
* request at a later stage.
*/