Import Plugin Integration

You can install the Cross-Border Payments Java SDK plugin and integrate it as described in this section.

Prerequisite

Download the Cross-Border Payments Import plugin and install it from the following GitHub location.

https://github.com/payu-india/sdk-java/releases/tag/V1.0.0.0

Procedure

To integrate the Cross-Border Payments Import plugin, refer the following recipe or step-by-step procedure:

  1. Import the PayU package:

import com.payu.*;

  1. Create an object for PayUClient :

PayuClient payuClient = PayuClient.init('\<payu\_key>', '\<payu\_salt>');Β 

  1. Pass the parameters for generating a hash to authenticate a transaction:

HasherParams hasherParams = new HashParams.Builder()Β 

.setTxnId("\<txnId>") Β 

.setAmount("\<amount>")Β 

.setProductInfo("\<productInfo>")Β 

.setFirstName("\<firstName>")Β 

.setEmail("\<email>")Β 

.build();Β 

String hashStr = payuClient.hasher.generateHash(hashParams);Β 
  1. Import the package for an HTTP request:

import okhttp3.\*;Β 

  1. Create hash for the UDF Update API:

PayuAPIHash udfUpdateHash = new Β PayuAPIHash();Β 

udfUpdateHash.key = payuClient.hasher.yourKey); Β 

udfUpdateHash.var1 = "e5b8663df04581c085f9";Β 

udfUpdateHash.salt = payuClient.hasher.yourSalt();Β 

//e.g.Β 

String hashForUdfUpdateApi = Β udfUpdateHash.generateHashForUdfUpdteApi();Β 
  1. Create UDF Update API with parameters similar to the following. For more information on UDF Update API, refer to UDF Update API.

PayuUdfs udfUpdate = new PayuUdfs();Β 

udfUpdate.key = "yourKey";Β 

udfUpdate.var1 = "e5b8663df04581c085f9";Β 

udfUpdate.var2 = "8000123";Β 

udfUpdate.var3 = "4334343";Β 

udfUpdate.var4 = "434343";Β 

udfUpdate.var5 = "Abcd123";Β 

udfUpdate.var6 = "INV0000000dd0599100";Β 
  1. Configure the environment as β€œTest”:

Note: It is recommended to configure the environment as β€œTest” for testing the flow before moving to live.


udfUpdate.environment = "Test";Β 

udfUpdate.hash = hashForUdfUpdateApi;Β 
  1. Perform reverse hash calculation with the response from PayU:

String reverseHash = "\<payuHash>" // hash received after payment from payuΒ 

String txnStatus = "\<payuTxnStatus>"// txn status received after payment from payuΒ 

boolean isVerified = payu.hash.validateHash(reverse\_hash, txnStatus, hashParams);Β 

Map\<String, String> optionalParams = new HashMap\<String, String>();Β 

HashParams hashParams = new HashParams.Builder()Β 

.setTxnId("\<txnId>")Β 

.setAmount("\<amount>")Β 

.setProductInfo("\<productInfo>")Β 

.setProductInfo("\<productInfo>")Β 

.setFirstName("\<firstName>")Β 

.setEmail("\<email>")Β 

.setUdf1("\<userDefinedParam1>")Β 

.setUdf2("\<userDefinedParam2>")Β 

.setAdditionalCharges("\<additionalCharges>")Β 

.build();Β 

boolean isVerified = payuClient.hasher.validateHash(reverse\_hash, txnStatus, hashParams);\`\`\`Β 
  1. Calculate hash for uploading the invoice:

PayuAPIHash hashInvoice = new Β PayuAPIHash();Β 

hashInvoice.key = payuClient.hasher.yourKey();

hashInvoice.var1 = "403993715525825059";Β 

hashInvoice.salt = payuClient.hasher.yourSalt();

hashForUdfUpdateApi = Β hashInvoice.generateHashForInvoiceUploadApi();
  1. Post the Invoice UploadAPI through SDK. For more information on Invoice Upload API, refer to Invoice Upload API.

PayuUpdateInvoice invoiceUpload = new PayuUpdateInvoice();Β 

invoiceUpload.key = "DGy1hY";Β 

invoiceUpload.environment = "Test";Β 

invoiceUpload.var1 = "403993715525825059";Β 

invoiceUpload.var2 = "INV0000000001";Β 

invoiceUpload.var3 = "Invoice";Β 
  1. Attach your invoice with the file path and file name:

invoiceUpload.file = new File("/Users/ashish.kumar/Desktop/productNeeote.pdf");Β 

invoiceUpload.fileName = new File ("productNote.pdf");Β 

invoiceObj.hash = hashForUdfUpdateApi;

String invoiceUpdateStatus = invoiceObj.updateInvoice();

πŸ“˜

Note:

The file size of the invoice to be uploaded must be less than 2MB.