I am using razor pay flutter package to make payment in flutter in test mode . I have options to handle the events and also save the payment id in my database .
I want to refund the amount based on the payment id . I dont have much clarification on how to do the same . Here is my code for sending payment request
Razorpay? _razorpay = Razorpay();
void openPaymentPortal() async {
var options = {
'key': 'My_key',
'amount': 100000,
'name': 'test',
'description': 'Payment for Pro account',
'prefill': {'contact': '9999999999', 'email': '[email protected]'},
'external': {
'wallets': ['paytm']
}
};
try {
_razorpay?.open(options);
} catch (e) {
debugPrint(e.toString());
}
}
void _handlePaymentSuccess(PaymentSuccessResponse response) {
Fluttertoast.showToast(
msg: "SUCCESS PAYMENT: ${response.paymentId}", timeInSecForIosWeb: 5);
onSubmit(false, response.paymentId.toString());
}
void _handlePaymentError(PaymentFailureResponse response) {
Fluttertoast.showToast(
msg: "ERROR HERE: ${response.code} - ${response.message}",
timeInSecForIosWeb: 4);
}
void _handleExternalWallet(ExternalWalletResponse response) {
Fluttertoast.showToast(
msg: "EXTERNAL_WALLET IS : ${response.walletName}",
timeInSecForIosWeb: 4);
}
How to process refund of the amount to the user ? I followed something like the below code but it is not working
void processRefund(String paymentId) async {
var url =
Uri.parse('https://api.razorpay.com/v1/payments/$paymentId/refund');
try {
var response = await http.post(
url,
headers: {
'Authorization': 'Bearer My_Key',
'Content-Type': 'application/json'
},
);
if (response.statusCode == 200) {
// Refund processed successfully
print('Refund processed successfully');
} else {
// Refund failed
print('Refund failed with status code: ${response.statusCode}');
print('Response body: ${response.body}');
}
} catch (e) {
// Error occurred while making the refund request
print('Error occurred during refund process: $e');
}
}
2
Answers
I solved my case as follows
}