Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.getDeviceDetails is not a function in razorpay integration with flutter

This is the Error Message that is showing I/chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: window.getDeviceDetails is not a function", source: https://api.razorpay.com/v1/checkout/public?version=1.5.16&library=checkoutjs&platform=android (1)

like image 973
Aashraya Singal Avatar asked Jan 19 '26 02:01

Aashraya Singal


1 Answers

You need to send a request to Razorpay to generate an Order ID. like this:

curl -u <YOUR_KEY_ID>:<YOUR_SECRET> \
-X POST https://api.razorpay.com/v1/orders \
-H "content-type: application/json" \
-d '{
  "amount": 50000,
  "currency": "INR",
  "receipt": "receipt#1",
  "payment_capture": 1
}'

I have created a distinct method to produce an Order ID within my application.

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<String> generateOrderId(String key, String secret,int amount) async{
  var authn = 'Basic ' + base64Encode(utf8.encode('$key:$secret'));

  var headers = {
    'content-type': 'application/json',
    'Authorization': authn,
  };

  var data = '{ "amount": $amount, "currency": "INR", "receipt": "receipt#R1", "payment_capture": 1 }'; // as per my experience the receipt doesn't play any role in helping you generate a certain pattern in your Order ID!!

  var res = await http.post('https://api.razorpay.com/v1/orders', headers: headers, body: data);
  if (res.statusCode != 200) throw Exception('http.post error: statusCode= ${res.statusCode}');
  print('ORDER ID response => ${res.body}');

  return json.decode(res.body)['id'].toString();
}
like image 179
Karma Avatar answered Jan 21 '26 16:01

Karma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!