剃须刀退款
Razorpay Refund
点击删除订单后,我想发起 razor pay 退款请求,但是当我点击删除订单后,我的应用程序立即崩溃并出现此错误。
我按照此 link 上发布的步骤进行操作
https://razorpay.com/docs/api/refunds/
我使用了java正常退款。
请帮助我谢谢。
代码:
if(payid!= null) {
RazorpayClient razorpay = null;
try {
razorpay = new RazorpayClient("<api_key>", "<api_secret>");
} catch (RazorpayException e) {
e.printStackTrace();
}
try {
// Partial Refund
JSONObject refundRequest = new JSONObject();
refundRequest.put("amount", Amount); // Amount should be in paise
Refund refund = razorpay.Payments.refund(payid, refundRequest); // this is line 341 of Order(Order.java:341)
} catch (RazorpayException | JSONException e) {
// Handle Exception
Toast.makeText(Order.this, "Error With Refund: " + e, Toast.LENGTH_SHORT).show();
}
runn();
}else {
runn();
}
错误
2020-05-28 00:12:30.697 27573-27573/com.example.customerapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.customerapp, PID: 27573
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1565)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:115)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at okhttp3.Dns.lookup(Dns.java:40)
at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:185)
at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:149)
at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:84)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:214)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:144)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
at okhttp3.RealCall.execute(RealCall.java:92)
at com.razorpay.ApiUtils.processRequest(ApiUtils.java:159)
at com.razorpay.ApiUtils.postRequest(ApiUtils.java:78)
at com.razorpay.ApiClient.post(ApiClient.java:40)
at com.razorpay.PaymentClient.post(PaymentClient.java:9)
at com.razorpay.PaymentClient.refund(PaymentClient.java:39)
at com.example.customerapp.Order.runn1(Order.java:341)
at com.example.customerapp.Order.run8(Order.java:319)
at com.example.customerapp.Order.onClick(Order.java:231)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:177)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7643)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
错误
android.os.NetworkOnMainThreadException at android.os.StrictMode
通常发生在应用程序试图在主线程中执行网络操作时。
为避免这种情况,我们必须在其他线程或异步 Class.
中调用网络请求
考虑以下代码:
setContentView(R.layout.user_login);
// put this below lines under setContentView in activity
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
点击删除订单后,我想发起 razor pay 退款请求,但是当我点击删除订单后,我的应用程序立即崩溃并出现此错误。
我按照此 link 上发布的步骤进行操作 https://razorpay.com/docs/api/refunds/
我使用了java正常退款。
请帮助我谢谢。
代码:
if(payid!= null) {
RazorpayClient razorpay = null;
try {
razorpay = new RazorpayClient("<api_key>", "<api_secret>");
} catch (RazorpayException e) {
e.printStackTrace();
}
try {
// Partial Refund
JSONObject refundRequest = new JSONObject();
refundRequest.put("amount", Amount); // Amount should be in paise
Refund refund = razorpay.Payments.refund(payid, refundRequest); // this is line 341 of Order(Order.java:341)
} catch (RazorpayException | JSONException e) {
// Handle Exception
Toast.makeText(Order.this, "Error With Refund: " + e, Toast.LENGTH_SHORT).show();
}
runn();
}else {
runn();
}
错误
2020-05-28 00:12:30.697 27573-27573/com.example.customerapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.customerapp, PID: 27573
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1565)
at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:115)
at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
at java.net.InetAddress.getAllByName(InetAddress.java:1152)
at okhttp3.Dns.lookup(Dns.java:40)
at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:185)
at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:149)
at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:84)
at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:214)
at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:144)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:254)
at okhttp3.RealCall.execute(RealCall.java:92)
at com.razorpay.ApiUtils.processRequest(ApiUtils.java:159)
at com.razorpay.ApiUtils.postRequest(ApiUtils.java:78)
at com.razorpay.ApiClient.post(ApiClient.java:40)
at com.razorpay.PaymentClient.post(PaymentClient.java:9)
at com.razorpay.PaymentClient.refund(PaymentClient.java:39)
at com.example.customerapp.Order.runn1(Order.java:341)
at com.example.customerapp.Order.run8(Order.java:319)
at com.example.customerapp.Order.onClick(Order.java:231)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:177)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7643)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
错误
android.os.NetworkOnMainThreadException at android.os.StrictMode
通常发生在应用程序试图在主线程中执行网络操作时。
为避免这种情况,我们必须在其他线程或异步 Class.
中调用网络请求
考虑以下代码:
setContentView(R.layout.user_login);
// put this below lines under setContentView in activity
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}