UPI COLLECT

Parameter NameData TypeMandatoryDescription
merchantOrderIdStringyesUnique order ID generated by merchant
amountlongyesAmount of order in Paisa
contraintsList<InstrumentConstraint>yesDifferent type of constraints that must be applied to the payment
VPAStringYesVPA against which collect request need to be raised
import pkg from '@phonepe-pg/pg-sdk-node';
const { CustomCheckoutClient, Env, MetaInfo, CustomCheckoutPayRequest } = pkg;
import { v4 as uuid } from 'uuid';


const clientId = "<clientId>"; 
const clientSecret = "<clientSecret>"; 
const clientVersion = 1;  //insert your client version here 
const env = Env.SANDBOX;          // change to Env.PRODUCTION when you go live

const client = CustomCheckoutClient.getInstance(clientId, clientSecret, clientVersion, env);

const merchantOrderId = uuid();
const amount = 100;
const deviceOS = "IOS";
const vpa = "success@ybl";

const metaInfo = MetaInfo.builder()
  .udf1("free-text-value-1")
  .udf2("free-text-value-2")
  .udf3("free-text-value-3")
  .udf4("free-text-value-4")
  .udf5("free-text-value-5")
  .udf6("free-text-value-6")
  .udf7("free-text-value-7")
  .udf8("free-text-value-8")
  .udf9("free-text-value-9")
  .udf10("free-text-value-10")
  .udf11("ref_11")
  .udf12("tag-12")
  .udf13("user@13")
  .udf14("code.14")
  .udf15("val+15")
  .build();

const request = CustomCheckoutPayRequest.UpiCollectPayViaVpaRequestBuilder()
  .vpa(vpa)
  .amount(amount)
  .deviceOS(deviceOS)
  .merchantOrderId(merchantOrderId)
  .message("collect_message")
  .metaInfo(metaInfo)
  .build();

client.pay(request).then((response) => {
  const state = response.state;
  const orderId = response.orderId;
  const redirectUrl = response.redirectUrl;
  console.log("Order ID:", orderId);
  console.log("Payment State:", state);
  console.log("Redirect URL:", redirectUrl);
});

The function will raise the collect request to the above mentioned vpa.

PropertyTypeDescription
orderIdStringOrder Id created by PhonePe
stateStringState of the order. Initially it will be PENDING.
expireAtLongOrder expire date in epoch
Is this article helpful?