public class InvokeSendLink { private static final String RAZORPAY_API_URL = 'https://api.razorpay.com/v1/payment_links/'; private static final String RAZORPAY_KEY_ID = System.label.Key_Id_of_Razor_Pay; private static final String RAZORPAY_KEY_SECRET = System.label.key_secret_of_RazorPay; public class SendLinkInput { @InvocableVariable(label = 'Opportunity Name' required=true) public String OppName; @InvocableVariable(label = 'Amount' required=true) public Decimal Amount; @InvocableVariable(label = 'Email' required=true) public String Email; @InvocableVariable(label = 'Phone' required=true) public String Phone; @InvocableVariable(label = 'ContactName' required=true) public String ContactName; } public class SendLinkOutput { @InvocableVariable(label = 'Payment ID') public String paymentId; @InvocableVariable(label = 'Status') public String status; } @InvocableMethod(label='Send Payment Link' description='Sending the Payment Link To Donor') public static List InvokeMethod(List inputs) { List outputs = new List(); if (inputs != null && !inputs.isEmpty()) { for (SendLinkInput input : inputs) { SendLinkOutput output = sendLinkMethod(input.Amount, input.Email, input.Phone, input.ContactName); outputs.add(output); } } System.debug(outputs); return outputs; } //Send Payment Link Method public static SendLinkOutput sendLinkMethod(Decimal Amount,String Email,String Phone,String ContactName){ HttpRequest req = new HttpRequest(); req.setEndpoint(RAZORPAY_API_URL); req.setMethod('POST'); req.setHeader('Content-Type', 'application/json'); req.setHeader('Authorization', 'Basic ' + EncodingUtil.base64Encode(Blob.valueOf(RAZORPAY_KEY_ID + ':' + RAZORPAY_KEY_SECRET))); Map requestBody = new Map{ 'amount' => (Integer)(Amount * 100), // Razorpay expects amount in paise 'currency' => 'INR', 'description' => 'Payment link expires in 24 hours', 'expire_by' => System.now().addDays(1).getTime() / 1000, 'customer' => new Map{ 'name' => ContactName, 'contact' => '+91'+Phone, 'email' => Email }, 'notify' => new Map{ 'sms' => true, 'email' => true } }; req.setBody(JSON.serialize(requestBody)); Http http = new Http(); HttpResponse res = http.send(req); if (res.getStatusCode() == 200) { Map responseBody = (Map)JSON.deserializeUntyped(res.getBody()); SendLinkOutput output = new SendLinkOutput(); output.paymentId = (String)responseBody.get('id'); output.status = (String)responseBody.get('status'); return output; } else { System.debug('Error creating payment link. Status code: ' + res.getStatusCode()); System.debug('Response body: ' + res.getBody()); return null; } } }