gpt4 book ai didi

Flutter web app razorpay payment gateway 404 error in payment page(Flutter网络应用razorpay支付网关404支付页面错误)

转载 作者:bug小助手 更新时间:2023-10-22 15:46:45 27 4
gpt4 key购买 nike



I am trying to implement razorpay payment gateway in my flutter web app. In android and Ios work perfectly and also web in localhost payment gateway working fine. But i am deploying in the server then getting 404 page not found error.

我正在尝试在我的flutter web应用程序中实现razorpay支付网关。在android和Ios中工作完美,在localhost中的web支付网关也工作良好。但我在服务器上部署时得到404页面未找到错误。


here is my code

这是我的代码


class AcademyWebpayment extends StatefulWidget {
final String? name;
final String? keyrzor;
final int? price;
final String? orderId;
final String? email;
final String? mobileNo;
final int? subscriptionId;

AcademyWebpayment({
this.name,
this.price,
this.keyrzor,
this.orderId,
this.email,
this.mobileNo,
this.subscriptionId,
});

@override
_AcademyWebpaymentState createState() => _AcademyWebpaymentState();
}

class _AcademyWebpaymentState extends State<AcademyWebpayment> {
bool _isLoading = false;

@override
Widget build(BuildContext context) {
ui.platformViewRegistry.registerViewFactory("rzp-html",(int viewId) {
IFrameElement element=IFrameElement();
window.onMessage.forEach((messageEvent) async {
final dynamic messageData = messageEvent.data;
final String event = messageData['event'];
// print('Event Received in callback: ${messageEvent.data}');
if(event=='MODAL_CLOSED'){
print('PAYMENT unsuccessfull!!!!!!!${messageEvent.data}');
Navigator.pop(context);
Fluttertoast.showToast(
msg: "Payment Failed!",
toastLength: Toast.LENGTH_SHORT, // Toast.LENGTH_LONG for a longer duration
gravity: ToastGravity.BOTTOM, // ToastGravity.TOP for top gravity
backgroundColor: Colors.black54,
textColor: Colors.white,
fontSize: 16.0,
);
}
else if (event == 'PAYMENT_SUCCESS'){
setState(() {
_isLoading = true; // Show circular progress indicator
});
print('PAYMENT SUCCESSFULL!!!!!!!${messageEvent.data}');
// Parse the payment response data
final dynamic paymentResponse = messageData['response'];
final String paymentId = paymentResponse['razorpay_payment_id'];
final String orderId = paymentResponse['razorpay_order_id'];
final String signature = paymentResponse['razorpay_signature'];
print('PAYMENT SUCCESSFULL!!!!!!!$paymentId');

SharedPreferences prefs = await SharedPreferences.getInstance();
int? userId = prefs.getInt('userId');

final Map<String, dynamic> requestBody = {
"status": "paid",
"user_id": userId,
"order_id": orderId,
"payment_id": paymentId,
"subscription_id": widget.subscriptionId,
};

try {
Dio dio = Dio();
final response = await dio.put(
"https://api.replsports.com/api/academySubscription/payment",
data: requestBody,
);

if (response.statusCode == 200) {
setState(() {
_isLoading = false; // Hide circular progress indicator
});
final data = response.data;
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BottomNavigation(),
),
);

Fluttertoast.showToast(
msg: "Paid Successfully",
toastLength: Toast.LENGTH_SHORT, // Toast.LENGTH_LONG for a longer duration
gravity: ToastGravity.BOTTOM, // ToastGravity.TOP for top gravity
backgroundColor: Colors.black54,
textColor: Colors.white,
fontSize: 16.0,
);
} else {
setState(() {
_isLoading = false; // Hide circular progress indicator
});
print('Payment Failed: ${response.statusCode}');
}
} catch (e) {
setState(() {
_isLoading = false; // Hide circular progress indicator
});
print('Error in create booking: $e');
}
}
});
element.requestFullscreen();
element.src='assets/payments.html?name=${widget.name}&price=${widget.price}&keyrzor=${widget.keyrzor}&orderId=${widget.orderId}&email=${widget.email}&mobileNo=${widget.mobileNo}';
element.style.border = 'none';

return element;
});
return Stack(
children: [
Container(
child: const HtmlElementView(viewType: 'rzp-html'),
),
if (_isLoading)
Container(
color: Colors.black.withOpacity(0.5),
child: const Center(
child: CircularProgressIndicator(),
),
),
],
);
}

}

and this is my html code

这是我的html代码


<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width">
<head><title>REPL Sports</title></head>
<body>
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script>
const queryString = window.location.search;
console.log(queryString);
const urlParams = new URLSearchParams(queryString);
const name = urlParams.get('name')
const price = urlParams.get('price')
const keyrzor = urlParams.get('keyrzor')
const orderId = urlParams.get('orderId')
const email = urlParams.get('email')
const mobileNo = urlParams.get('mobileNo')

options = {
"key": keyrzor,
"amount": price,
"currency": "INR",
"name":name,
"description": "Sports",
"order_id" : orderId,
"handler": function (response){
window.parent.postMessage({ event: "PAYMENT_SUCCESS", response: response }, "*");
},
"prefill": {
"name": name,
"email":email,
"contact":"+91-",
},
"notes": {
"address": "Autofy"
},
"theme": {
"color": "#DF0145"
},
"modal": {
"ondismiss": function(){
window.parent.postMessage({ event: "MODAL_CLOSED" }, "*");
}
}
};
var rzp1 = new Razorpay(options);
window.onload = function(e){ //1
rzp1.open();
e.preventDefault();
}
</script>
</body>
</html>


Please give me solution how to integrate razorpay flutter web in live server.

请给我如何在实时服务器中集成razorpay flutter web的解决方案。


更多回答
优秀答案推荐

I was facing the same issue. The issue was that when I Ran flutter build web, so it created assets folder inside an assets folder.

我也面临同样的问题。问题是,当我运行flutter构建web时,它在资产文件夹中创建了资产文件夹。


So when I replaced this:
element.src='assets/payments.html?"

所以当我替换这个元素时:element.src='assets/payments.html?“


With this :
element.src='assets/assets/payments.html?" (Note- for localhost you will need to change it again)

使用以下内容:element.src='assets/assets/payments.html?“(注意-对于localhost,您需要再次更改它)


So it worked fine. This might not be the best solution, but it fixed the issue.

所以效果很好。这可能不是最好的解决方案,但它解决了这个问题。


更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com