Sequence
- Validate VPA
- Custom – UPI Collect
Validate VPA
Used to check if the given VPA is valid or not.
Parameters
Parameter | Type | Mandatory | Description |
---|---|---|---|
vpa | mixed | Yes | The Virtual Payment Address (VPA) for the payment. |
Example – Valid VPA
const $MERCHANTID="<merchantId>";
const $SALTKEY="<saltKey>";
const $SALTINDEX="<saltIndex>";
const $env=Env::UAT;
const $SHOULDPUBLISHEVENTS=true;
$phonePePaymentsClient = new PhonePePaymentClient(MERCHANTID, SALTKEY, SALTINDEX, Env::UAT, SHOLDPUBLISHEVENTS);
String vpa="abc@ybl";
try {
$validateVpaResponse = $phonePePaymentsClient->validateVpa("abc@ybl");
$name = $validateVpaResponse->getName();
}
catch (Exception $e) {
// Handle PhonePeException thrown in case of invalid vpa.
}
Returns
The function returns a PgValidateVpaResponse
object with the following properties if vpa is valid:
PgValidateVpaResponse Properties
Property | Type | Description |
---|---|---|
vpa | str | The VPA sent in the request. |
name | str | The name linked to the VPA. |
Custom – UPI Collect
Builds PgPayRequest with UPI Collect as the payment instrument.
Parameters
Parameter | Type | Mandatory | Description |
---|---|---|---|
vpa | mixed | Yes | The Virtual Payment Address (VPA) for the payment. |
Before initiating the transaction with UPI Collect with VPA you need to validate the vpa using the validateVpa
function.
Example (Custom – UPI Collect)
const $MERCHANTID="<merchantId>";
const $SALTKEY="<saltKey>";
const $SALTINDEX="<saltIndex>";
const $env=Env::UAT;
const $SHOULDPUBLISHEVENTS=true;
$phonePePaymentsClient = new PhonePePaymentClient(MERCHANTID, SALTKEY, SALTINDEX, Env::UAT, SHOLDPUBLISHEVENTS);
// validating vpa before initiating payment.
$vpa = "12345678@ybl";
$pgValidateVpaResponse = $phonePePaymentsClient->validateVpa($vpa);
echo json_encode($pgValidateVpaResponse);
//If validateVpa function does not throws PhonePeException with Invalid Vpa message go ahead with following request
$merchantTransactionId = ""<merchantTransactionId>"";
$request = PgPayRequestBuilder::builder()
->mobileNumber("9090909090")
->callbackUrl("https://webhook.in/test ")
->merchantId(MERCHANTID)
->merchantUserId("<merchantUserId>")
->amount(<amountInPaise>)
->merchantTransactionId($merchantTransactionId)
->paymentInstrument(
InstrumentBuilder::getUpiCollectInstrumentBuilder()
->vpa($vpa)
->build()
)
->build();
$response = $phonePePaymentsClient->pay($request);