Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{"error":{"code":"BAD_REQUEST_ERROR","description":"Authentication failed"}} #410

Open
sai-chandra22 opened this issue Aug 26, 2024 · 3 comments

Comments

@sai-chandra22
Copy link

sai-chandra22 commented Aug 26, 2024

 Future<bool> createOrder(CreditPlanModel creditPlanModel) async {
    showLoader = true;
    hasError = "";
    notifyListeners();
    var mapHeader = <String, String>{};
    mapHeader['Authorization'] =
        'Basic ${base64Encode(utf8.encode(razorPayKey))}';
    mapHeader['Accept'] = "application/json";
    mapHeader['Content-Type'] = "application/x-www-form-urlencoded";
    var map = <String, String>{};
    map['amount'] = ((num.parse(creditPlanModel.planPrice ?? "1") * 0.18 +
                num.parse(creditPlanModel.planPrice ?? "1")) *
            100)
        .toInt()
        .toString(); // --> This is purely our business logic
    map['currency'] = "INR";
    map['receipt'] = "receipt1";
    print("map $map");
    var response = await http.post(Uri.https("api.razorpay.com", "/v1/orders"),
        headers: mapHeader, body: map);
    print("....${response.body}");
    if (response.statusCode == 200) {
      razorPayOrderModel =
          RazorPayOrderModel.fromJson(json.decode(response.body));
      return true;
    } else {
      showLoader = false;
      hasError = "";
      notifyListeners();
      return false;
    }
  }

Usage:
 String? value =  await orderSummaryVM.payUsingRazorPay();
  if (value == "200") {
  var options = {
                  'key': razorPayShortKey,
                   'amount': ((num.parse(orderSummaryVM
                                                                .price ??
                                                            "1") *
                                                        0.18 +
                                                    num.parse(
                                                        orderSummaryVM.price ??
                                                            "1")) *
                                                100)
                                            .toInt()
                                            .toString(),
                     'name': 'xxxxxx',
                                        // 'Service 1',
                                        // 'prefill': {
                                        //   'contact': '+917876922477',
                                        //   'email': '[email protected]'
                                        // },
                                        'order_id':
                                            '${orderSummaryVM.razorPayOrderModel.id}',
                                      };
                                      orderSummaryVM.cartOrderList;
                                      await appRazorpayService
                                          .makePayment(options);
                                    } else {
                                      Util().showToast(value!);
                                    }

Where razorPayKey = KEY_ID:KEY_SECRET, the test version mode is working fine, but the live mode is not working and throwing the error, what can be the issue or am i missing any point here, Please let me know

@sai-chandra22
Copy link
Author

sai-chandra22 commented Aug 26, 2024

What is this about? @swaggy111 @pngjian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@sai-chandra22 and others