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.