Reputation: 644
As mentioned in https://docs.razorpay.com/docs/orders, the API
is given to create a new order in razor(I need it for auto capturing as mentioned in https://docs.razorpay.com/page/orders). On the right side of the page the code is also given (JAVA), to create a new order, but when I run the code, I got the networkmainthread
exception, so I ran the code using asynctask
. But now the problem is how do I check the response of the code, and will I get the order id. This part is not mentioned in the documentation.
import com.razorpay.Order;
import org.json.JSONObject;
import com.razorpay.RazorpayClient;
import com.razorpay.RazorpayException;
RazorpayClient razorpay = new RazorpayClient("<api_key>", "<api_secret>");
try {
JSONObject orderRequest = new JSONObject();
orderRequest.put("amount", amount); // amount in paise
orderRequest.put("currency", "INR");
orderRequest.put("receipt", "test_1");
orderRequest.put("payment_capture", false);
Order order = razorpay.Orders.create(orderRequest);
} catch (RazorpayException e) {
// Handle Exception
System.out.println(e.getMessage());
}
Upvotes: 0
Views: 7003
Reputation: 66
Order order = razorpayClient.Orders.create(orderRequest);
JSONObject jsonObject = new JSONObject(String.valueOf(order));
String id = jsonObject.getString("id");
Upvotes: 3