{"id":767,"date":"2026-11-25T07:15:00","date_gmt":"2026-11-25T07:15:00","guid":{"rendered":"https:\/\/paymentsetu.com\/blog\/?p=767"},"modified":"2026-11-25T07:15:00","modified_gmt":"2026-11-25T07:15:00","slug":"upi-payment-integration-java-spring-boot","status":"publish","type":"post","link":"https:\/\/paymentsetu.com\/blog\/upi-payment-integration-java-spring-boot\/","title":{"rendered":"UPI Payment Integration in Java: Spring Boot Example"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">UPI payment integration in java is easiest to maintain when your Spring Boot server owns the order, amount and confirmation state. This guide builds a plain REST integration with <code>RestClient<\/code>: create an order, redirect to the hosted QR, verify the HMAC-signed webhook, update the order idempotently and check API credits.<\/p>\n\n\n\n<aside class=\"ap-card\" aria-label=\"PaymentSetu Pro\">\n<span class=\"ap-card__badge\">Best for developers<\/span>\n<div class=\"ap-card__body\"><p class=\"ap-card__name\">PaymentSetu Pro<\/p><p class=\"ap-card__best\">Best for growing WooCommerce \/ WHMCS stores and service businesses with up to 1,000 UPI payments a month (most popular)<\/p><ul class=\"ap-card__features\"><li>1,000 credits (1 credit = 1 successful payment verified)<\/li><li>0% commission, direct-to-bank UPI settlement<\/li><li>Dynamic QR, webhooks and API access<\/li><li>WooCommerce and WHMCS plugins<\/li><li>Priority support<\/li><\/ul><\/div>\n<div class=\"ap-card__side\"><p class=\"ap-card__price\">\u20b9999 <small>Most popular \u00b7 \u20b9999 \/ 30 days \u00b7 1,000 verified payments<\/small><\/p><a class=\"ap-card__btn\" href=\"https:\/\/paymentsetu.com\/auth\/register\">Get Pro \u2192<\/a><\/div>\n<\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">What you will build<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The finished flow has a checkout endpoint, a webhook endpoint and a server-side status fallback:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>Your application calculates the payable amount and saves a pending order.<\/li>\n\n\n<li>Spring Boot calls <code>POST \/api\/create_order<\/code> with a unique <code>order_id<\/code> and the amount in integer paisa.<\/li>\n\n\n<li>PaymentSetu returns a <code>payment_url<\/code>; your application redirects the customer to the hosted QR page.<\/li>\n\n\n<li>The customer pays by UPI directly into your connected Paytm Business or PhonePe Business merchant account.<\/li>\n\n\n<li>PaymentSetu matches the payment to the order and sends an HMAC-signed JSON webhook.<\/li>\n\n\n<li>Your webhook controller verifies the raw request, checks the order and amount, and marks it paid once.<\/li>\n\n\n<li>A scheduled job or return page can use <code>GET \/api\/order_status\/{client_txn_id}<\/code> to reconcile a pending record.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">PaymentSetu is a payment verification service, not a payment gateway. The customer\u2019s payment goes to your own merchant account; PaymentSetu matches the UTR and amount to the order and sends your application the verification event. It does not hold the money.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a ready-made platform integration, see the <a href=\"https:\/\/paymentsetu.com\/woocommerce-plugin\">PaymentSetu WooCommerce plugin<\/a>. This article is for a custom Java or Spring Boot checkout where you control the database and fulfilment logic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What you need before starting<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: the API key, webhook secret, order reference and expected amount must be decided before code changes payment state.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Prepare:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>A Spring Boot MVC application with HTTPS and Jackson, using a Spring version that provides <code>RestClient<\/code>.<\/li>\n\n\n<li>Java 21 or another supported Java version with <code>javax.crypto.Mac<\/code> available.<\/li>\n\n\n<li>A PaymentSetu account with a connected Paytm Business or PhonePe Business merchant account.<\/li>\n\n\n<li>An API key and the webhook signing value shown in your PaymentSetu configuration. If your account uses the API key to sign webhooks, use that same server-side value for both.<\/li>\n\n\n<li>A public HTTPS endpoint such as <code>https:\/\/shop.example.com\/webhooks\/paymentsetu<\/code>.<\/li>\n\n\n<li>An orders table containing your reference, expected amount in paisa, status and UTR.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Keep secrets outside <code>application.properties<\/code> committed to source control. Environment variables are enough for a small deployment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PAYMENTSETU_API_KEY=replace-with-your-api-key\nPAYMENTSETU_WEBHOOK_SECRET=replace-with-your-webhook-secret<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Set <code>PAYMENTSETU_WEBHOOK_SECRET<\/code> to the documented signing value for your account; it may be the same value as <code>PAYMENTSETU_API_KEY<\/code>. Never send either value to the browser.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PaymentSetu Pro is <strong>\u20b9999 per 30 days<\/strong> for <strong>1,000 credits<\/strong>, with one credit representing one successful payment verified. It includes dynamic QR, webhooks, REST API access and the unified dashboard. Compare the available plans in the <a href=\"https:\/\/paymentsetu.com\/#pricing\">PaymentSetu pricing section<\/a>, or <a href=\"https:\/\/paymentsetu.com\/auth\/register\">create an account<\/a> before you begin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Spring\u2019s <a href=\"https:\/\/docs.spring.io\/spring-framework\/reference\/integration\/rest-clients.html\" target=\"_blank\" rel=\"noopener\">official REST client reference<\/a> describes <code>RestClient<\/code> as a synchronous fluent client with JSON message conversion. Java\u2019s <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/21\/docs\/api\/java.base\/javax\/crypto\/Mac.html\" target=\"_blank\" rel=\"noopener\">official <code>Mac<\/code> documentation<\/a> documents <code>HmacSHA256<\/code>, <code>init<\/code> and <code>doFinal<\/code>, which are the primitives used below.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Configure a reusable RestClient<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: one configured client keeps the base URL and bearer authentication in one server-side place, so individual calls cannot accidentally expose the API key to the browser.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a bean. The <code>Authorization<\/code> header is added only to server-to-server calls:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.example.payments;\n\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.http.HttpHeaders;\nimport org.springframework.web.client.RestClient;\n\n@Configuration\npublic class PaymentSetuConfig {\n\n    @Bean\n    RestClient paymentSetuClient(\n            @Value(\"${paymentsetu.api-key}\") String apiKey,\n            @Value(\"${paymentsetu.base-url:https:\/\/paymentsetu.com\/api}\") String baseUrl) {\n        return RestClient.builder()\n                .baseUrl(baseUrl)\n                .defaultHeader(HttpHeaders.AUTHORIZATION, \"Bearer \" + apiKey)\n                .defaultHeader(HttpHeaders.ACCEPT, \"application\/json\")\n                .build();\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Map the environment variables into your deployment configuration rather than placing literal secrets in the repository. For example, the property names above can be supplied as <code>PAYMENTSETU_API_KEY<\/code> and <code>PAYMENTSETU_WEBHOOK_SECRET<\/code> by Spring\u2019s relaxed environment-variable binding.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Success looks like this: the application starts with a configured <code>RestClient<\/code>, and no API key appears in page source, JavaScript, logs or a response sent to the customer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Call create_order with RestClient<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: the unique order reference and server-calculated amount connect your local order to the hosted QR and later webhook.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a record for the request and a small JSON tree for the response. PaymentSetu expects <code>amount<\/code> in paisa, so \u20b9249 becomes <code>24900<\/code>. Save the local order as <code>PENDING<\/code> before the external call.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.example.payments;\n\nimport com.fasterxml.jackson.databind.JsonNode;\nimport org.springframework.http.MediaType;\nimport org.springframework.stereotype.Service;\nimport org.springframework.web.client.RestClient;\n\n@Service\npublic class PaymentSetuService {\n\n    private final RestClient client;\n\n    public PaymentSetuService(RestClient paymentSetuClient) {\n        this.client = paymentSetuClient;\n    }\n\n    public String createOrder(LocalOrder order) {\n        CreateOrderRequest request = new CreateOrderRequest(\n                order.id(),\n                order.amountPaise(),\n                \"https:\/\/shop.example.com\/payment-return\",\n                order.customerName(),\n                order.customerEmail(),\n                order.customerMobile(),\n                \"Order \" + order.id());\n\n        JsonNode response = client.post()\n                .uri(\"\/create_order\")\n                .contentType(MediaType.APPLICATION_JSON)\n                .body(request)\n                .retrieve()\n                .body(JsonNode.class);\n\n        if (response == null || !response.path(\"status\").asBoolean(false)) {\n            throw new IllegalStateException(\"PaymentSetu did not create the order\");\n        }\n\n        String paymentUrl = response.path(\"payment_url\").asText(\"\");\n        if (paymentUrl.isBlank()) {\n            throw new IllegalStateException(\"PaymentSetu response has no payment_url\");\n        }\n        return paymentUrl;\n    }\n\n    public record CreateOrderRequest(\n            String order_id,\n            long amount,\n            String redirect_url,\n            String customer_name,\n            String customer_email,\n            String customer_mobile,\n            String remarks) {}\n\n    public record LocalOrder(\n            String id,\n            long amountPaise,\n            String customerName,\n            String customerEmail,\n            String customerMobile) {}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The record field names intentionally match the API\u2019s JSON keys. If your project uses JavaBeans instead of records, use Jackson annotations or matching getter names. <code>RestClient.retrieve().body(JsonNode.class)<\/code> lets Jackson convert the JSON response; Spring documents this message-conversion pattern in its REST client reference.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Your controller should create the order from a trusted cart or invoice ID, not from an amount supplied by the browser:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@PostMapping(\"\/checkout\/{cartId}\")\npublic ResponseEntity&lt;Void&gt; checkout(@PathVariable String cartId) {\n    LocalOrder order = orderService.createPendingOrderFromCart(cartId);\n    String paymentUrl = paymentSetuService.createOrder(order);\n    return ResponseEntity.status(HttpStatus.SEE_OTHER)\n            .location(URI.create(paymentUrl))\n            .build();\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In these snippets, <code>LocalOrder<\/code> and <code>OrderService<\/code> represent your application\u2019s domain and repository types. If you keep the sample record nested inside <code>PaymentSetuService<\/code>, refer to it as <code>PaymentSetuService.LocalOrder<\/code> from another class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>createPendingOrderFromCart<\/code> method should calculate the total from your catalogue and save the expected paisa amount. Do not trust a hidden field such as <code>amount=24900<\/code>; customers can edit it. If the API call fails, leave the record available for reconciliation and show a generic checkout message rather than exposing credentials or a stack trace.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Success looks like this: a pending local order has one unique ID and amount, the API returns <code>status: true<\/code> and <code>payment_url<\/code>, and the customer reaches the hosted QR page. The redirect back to <code>redirect_url<\/code> is only navigation, not proof that the payment succeeded.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Show the QR or intent link safely<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: the browser needs only a payment URL; your API key and webhook secret must remain on the Spring Boot server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The simplest checkout is the <code>303 See Other<\/code> redirect shown above. If you need a custom waiting page, return the URL from your own backend and redirect in the browser:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public record CheckoutResponse(String orderId, String paymentUrl) {}\n\n@PostMapping(\"\/checkout\")\npublic CheckoutResponse createCheckout(@RequestBody CartRequest request) {\n    LocalOrder order = orderService.createPendingOrderFromCart(request.cartId());\n    return new CheckoutResponse(\n            order.id(),\n            paymentSetuService.createOrder(order));\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Your frontend can navigate to <code>paymentUrl<\/code> or display it as a link. Do not try to call <code>paymentsetu.com\/api\/create_order<\/code> from browser JavaScript. A bearer key in a browser bundle can be copied and used by anyone.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The customer sees the hosted QR and pays into your connected merchant account. After paying, the customer may return to your waiting page. That page can say \u201cWe are checking your payment\u201d and poll your own order endpoint, but it must never mark the order paid because a redirect occurred or because the customer uploaded a screenshot.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Success looks like this: the QR page opens with the order\u2019s amount, your application still shows <code>PENDING<\/code>, and only the webhook path can trigger fulfilment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Verify the HMAC webhook in a controller<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: a signed webhook gives your server an authenticated event, while a browser callback is only a client-side navigation event.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Read the body as <code>byte[]<\/code> and calculate the signature before parsing JSON. The PaymentSetu webhook uses these headers:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li><code>X-PaymentSetu-Timestamp<\/code>: the Unix timestamp for the signed request.<\/li>\n\n\n<li><code>X-PaymentSetu-Signature<\/code>: the hexadecimal HMAC-SHA256 value.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The signed message is <code>timestamp + \".\" + raw JSON body<\/code>. The timestamp check below uses a five-minute freshness window; keep it aligned with the webhook contract configured for your account.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package com.example.payments;\n\nimport com.fasterxml.jackson.databind.JsonNode;\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.http.HttpStatus;\nimport org.springframework.http.ResponseEntity;\nimport org.springframework.web.bind.annotation.*;\n\nimport javax.crypto.Mac;\nimport javax.crypto.spec.SecretKeySpec;\nimport java.nio.charset.StandardCharsets;\nimport java.security.GeneralSecurityException;\nimport java.security.MessageDigest;\nimport java.time.Instant;\n\n@RestController\n@RequestMapping(\"\/webhooks\/paymentsetu\")\npublic class PaymentSetuWebhookController {\n\n    private final ObjectMapper objectMapper;\n    private final OrderService orders;\n    private final String webhookSecret;\n\n    public PaymentSetuWebhookController(\n            ObjectMapper objectMapper,\n            OrderService orders,\n            @Value(\"${paymentsetu.webhook-secret}\") String webhookSecret) {\n        this.objectMapper = objectMapper;\n        this.orders = orders;\n        this.webhookSecret = webhookSecret;\n    }\n\n    @PostMapping\n    public ResponseEntity&lt;String&gt; receive(\n            @RequestHeader(value = \"X-PaymentSetu-Timestamp\", required = false)\n            String timestamp,\n            @RequestHeader(value = \"X-PaymentSetu-Signature\", required = false)\n            String signature,\n            @RequestBody byte[] rawBody) {\n\n        if (!isValidSignature(timestamp, signature, rawBody)) {\n            return ResponseEntity.status(HttpStatus.UNAUTHORIZED)\n                    .body(\"invalid webhook\");\n        }\n\n        try {\n            JsonNode event = objectMapper.readTree(rawBody);\n            String orderId = event.path(\"order_id\").asText(\"\");\n            String status = event.path(\"status\").asText(\"\").toLowerCase();\n            long amountPaise = event.path(\"amount\").asLong(-1);\n            String utr = event.path(\"txn_utr\").asText(\"\");\n\n            if (orderId.isBlank() || amountPaise &lt; 0 || utr.isBlank()) {\n                return ResponseEntity.badRequest().body(\"incomplete event\");\n            }\n\n            LocalOrder order = orders.findById(orderId);\n            if (order == null || order.amountPaise() != amountPaise) {\n                return ResponseEntity.badRequest().body(\"order mismatch\");\n            }\n\n            if (\"success\".equals(status)) {\n                \/\/ This method must use one transaction and a unique UTR\/event key.\n                orders.markPaidOnce(orderId, amountPaise, utr);\n            }\n\n            return ResponseEntity.ok(\"accepted\");\n        } catch (Exception exception) {\n            return ResponseEntity.badRequest().body(\"invalid event\");\n        }\n    }\n\n    private boolean isValidSignature(String timestamp, String received,\n                                     byte[] rawBody) {\n        if (timestamp == null || !timestamp.matches(\"\\\\d+\")\n                || received == null || received.isBlank()) {\n            return false;\n        }\n\n        long sentAt;\n        try {\n            sentAt = Long.parseLong(timestamp);\n        } catch (NumberFormatException exception) {\n            return false;\n        }\n\n        if (Math.abs(Instant.now().getEpochSecond() - sentAt) &gt; 300) {\n            return false;\n        }\n\n        try {\n            Mac mac = Mac.getInstance(\"HmacSHA256\");\n            mac.init(new SecretKeySpec(\n                    webhookSecret.getBytes(StandardCharsets.UTF_8),\n                    \"HmacSHA256\"));\n            byte[] prefix = (timestamp + \".\").getBytes(StandardCharsets.UTF_8);\n            byte[] signed = new byte[prefix.length + rawBody.length];\n            System.arraycopy(prefix, 0, signed, 0, prefix.length);\n            System.arraycopy(rawBody, 0, signed, prefix.length, rawBody.length);\n\n            byte[] expected = mac.doFinal(signed);\n            byte[] actual = hexToBytes(received);\n            return actual != null &amp;&amp; MessageDigest.isEqual(expected, actual);\n        } catch (GeneralSecurityException exception) {\n            return false;\n        }\n    }\n\n    private static byte[] hexToBytes(String value) {\n        if (!value.matches(\"(?i)[0-9a-f]{64}\")) return null;\n        byte[] result = new byte[32];\n        for (int i = 0; i &lt; result.length; i++) {\n            result[i] = (byte) Integer.parseInt(\n                    value.substring(i * 2, i * 2 + 2), 16);\n        }\n        return result;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>MessageDigest.isEqual<\/code> compares the digest bytes without an ordinary early-exit string comparison. Never parse the JSON and serialise it again before calculating HMAC: whitespace, escaping and property order can change the signed bytes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your account\u2019s API documentation specifies a different header encoding or a documented prefix, follow that contract exactly. Do not silently trim, lowercase or Base64-decode a value unless the contract says to do so.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Success looks like this: a valid request passes the signature and timestamp checks, an altered body returns <code>401<\/code>, and no order update happens before verification and amount validation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a deeper explanation of raw-body HMAC handling, see <a href=\"https:\/\/paymentsetu.com\/blog\/verify-hmac-webhook-signature-php-python-node\/\">Verify Webhook Signature HMAC in PHP, Python and Node.js<\/a>. The language changes, but the security order is the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Make order updates idempotent<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: a valid webhook may be delivered again, and a retry must not fulfil the same order twice.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Signature verification proves integrity and authenticity; it does not replace a database transaction. Your <code>markPaidOnce<\/code> operation should:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n\n<li>Load the order by your saved <code>order_id<\/code>.<\/li>\n\n\n<li>Compare the event amount in paisa with the stored amount.<\/li>\n\n\n<li>Require <code>status=success<\/code> and a non-empty UTR.<\/li>\n\n\n<li>Insert the UTR or event identifier into a column with a unique constraint.<\/li>\n\n\n<li>Change <code>PENDING<\/code> to <code>PAID<\/code> only if the current state is still <code>PENDING<\/code>.<\/li>\n\n\n<li>Commit before sending goods, access, email or a booking confirmation.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">A repository method can express the transition like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Transactional\npublic boolean markPaidOnce(String orderId, long amountPaise, String utr) {\n    int changed = jdbc.update(\"\"\"\n        UPDATE orders\n           SET status = 'PAID', txn_utr = ?\n         WHERE order_id = ?\n           AND amount_paise = ?\n           AND status = 'PENDING'\n        \"\"\", utr, orderId, amountPaise);\n\n    return changed == 1;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In production, also enforce uniqueness for <code>txn_utr<\/code> or the provider\u2019s event ID. If <code>changed<\/code> is zero because the order is already paid, acknowledge the repeated event without running fulfilment again. If your database sees two requests concurrently, the conditional update and unique constraint decide the winner.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not mark an order paid just because the customer returns from the QR page. A screenshot, a front-end callback and an HTTP redirect are not substitutes for a verified event.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Success looks like this: the first valid event changes one row and triggers fulfilment once; the same event again returns safely with no second side effect.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 6: Check status and credits from the server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: status checks help reconcile a return page or pending queue, while the credits check helps your operations screen know whether new orders can be created.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call the status endpoint with the same authenticated <code>RestClient<\/code>. Encode the local ID because it becomes part of a URL path:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public JsonNode getOrderStatus(String clientTxnId) {\n    return client.get()\n            .uri(uriBuilder -&gt; uriBuilder\n                    .path(\"\/order_status\/{client_txn_id}\")\n                    .build(clientTxnId))\n            .retrieve()\n            .body(JsonNode.class);\n}\n\npublic JsonNode getCredits() {\n    return client.get()\n            .uri(\"\/check_credits\")\n            .retrieve()\n            .body(JsonNode.class);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>getOrderStatus<\/code> from a scheduled reconciliation job or your own authenticated order-status endpoint. Inspect the documented response, then apply the same local order, amount, UTR and idempotency checks used by the webhook path before changing state. Do not let a browser call the PaymentSetu endpoint with your API key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The credits response can be logged or displayed as a small operational value. Do not hard-code the remaining balance because it changes as payment links are created. A plan credit represents one successful payment verified.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Success looks like this: a pending order can be reconciled from your server, and your operations view reads the current credit response rather than a stale number.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the integration end to end<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run these checks in a test environment before enabling fulfilment:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>Create a cart and confirm the database stores one pending order with the correct amount in paisa.<\/li>\n\n\n<li>Confirm the <code>create_order<\/code> response contains <code>status: true<\/code> and a non-empty <code>payment_url<\/code>.<\/li>\n\n\n<li>Open the URL and check that the displayed amount matches your local order.<\/li>\n\n\n<li>Send a valid signed webhook fixture and confirm that one database row changes to <code>PAID<\/code>.<\/li>\n\n\n<li>Send the same fixture again and confirm that fulfilment does not run twice.<\/li>\n\n\n<li>Change one byte of the raw JSON and confirm the controller rejects it before parsing or updating.<\/li>\n\n\n<li>Send the right body with the wrong secret and confirm it is rejected.<\/li>\n\n\n<li>Call your own status endpoint after returning from the hosted page; verify it reads server state.<\/li>\n\n\n<li>Call <code>check_credits<\/code> from the server and record the response without exposing the API key.<\/li>\n\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Log an internal order ID and result, not the API key, webhook secret or complete payment payload. Keep the return page useful for the customer, but make the signed webhook and database transition the source of fulfilment truth.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Every webhook has an invalid signature<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm that the controller receives the original body as <code>byte[]<\/code>, that the timestamp is included in the signed message, and that you use the exact header names. Check whether your account specifies hexadecimal or another digest representation. Do not calculate HMAC from <code>JsonNode.toString()<\/code> after parsing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The API returns an error from create_order<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Check the bearer header, JSON content type, unique order ID and integer paisa amount. Also confirm that the API key is active and that your plan has available credits. Log the HTTP status and a safe provider message on the server, not the credential.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The customer paid but the order is still pending<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Treat the browser return as navigation only. Check your HTTPS webhook route, inspect the server\u2019s signature result and use <code>order_status\/{client_txn_id}<\/code> from a server-side reconciliation task. Before changing state, compare the returned order ID, amount and UTR with your local record.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The same order is fulfilled twice<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Move the state transition into one database transaction and add a unique constraint for the UTR or event ID. The method must return a \u201cchanged one row\u201d result; only that result may call fulfilment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Is PaymentSetu a Java payment gateway?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. PaymentSetu is a payment verification service. Your customer pays by UPI into your own connected Paytm Business or PhonePe Business merchant account, while PaymentSetu matches the payment to the order and sends a webhook.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I create a UPI QR order in Spring Boot?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Save a pending order, calculate the total in integer paisa and call <code>POST \/api\/create_order<\/code> with the bearer API key. Redirect the customer to the returned <code>payment_url<\/code>; keep order confirmation on your signed webhook path.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should the Java webhook parse JSON before checking HMAC?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Read the raw request body as <code>byte[]<\/code>, verify the timestamped HMAC-SHA256 value, and parse the JSON only after the signature passes. Re-serialising parsed JSON can change the bytes and invalidate the signature check.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I stop duplicate webhook processing in Spring Boot?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use a database transaction, a unique UTR or event identifier, and a conditional <code>PENDING<\/code> to <code>PAID<\/code> update. If the update changes zero rows because the event was already accepted, return success without running fulfilment again.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Which PaymentSetu plan suits a Spring Boot integration?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PaymentSetu Pro is <strong>\u20b9999 per 30 days<\/strong> with <strong>1,000 verified-payment credits<\/strong>, API access, webhooks and priority support. Smaller projects can compare Starter at \u20b9399 per 30 days, while higher-volume systems can review Business at \u20b91,499 per 30 days on the <a href=\"https:\/\/paymentsetu.com\/#pricing\">pricing page<\/a>.<\/p>\n\n\n\n<aside class=\"ap-cta\" aria-label=\"Verify UPI orders in Spring Boot\"><div class=\"ap-cta__content\"><p class=\"ap-cta__eyebrow\">Start Java integration<\/p><p class=\"ap-cta__title\">Verify UPI orders in Spring Boot<\/p><p class=\"ap-cta__text\">Connect your own merchant account, create QR orders and receive signed webhooks with 0% commission.<\/p><\/div><a class=\"ap-cta__btn\" href=\"https:\/\/paymentsetu.com\/auth\/register\">Create your account<\/a><\/aside>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Is PaymentSetu a Java payment gateway?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. PaymentSetu is a payment verification service. Your customer pays by UPI into your own connected Paytm Business or PhonePe Business merchant account, while PaymentSetu matches the payment to the order and sends a webhook.\"}}, {\"@type\": \"Question\", \"name\": \"How do I create a UPI QR order in Spring Boot?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Save a pending order, calculate the total in integer paisa and call POST \/api\/create_order with the bearer API key. Redirect the customer to the returned payment_url; keep order confirmation on your signed webhook path.\"}}, {\"@type\": \"Question\", \"name\": \"Should the Java webhook parse JSON before checking HMAC?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. Read the raw request body as byte[], verify the timestamped HMAC-SHA256 value, and parse the JSON only after the signature passes. Re-serialising parsed JSON can change the bytes and invalidate the signature check.\"}}, {\"@type\": \"Question\", \"name\": \"How do I stop duplicate webhook processing in Spring Boot?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Use a database transaction, a unique UTR or event identifier, and a conditional PENDING to PAID update. If the update changes zero rows because the event was already accepted, return success without running fulfilment again.\"}}, {\"@type\": \"Question\", \"name\": \"Which PaymentSetu plan suits a Spring Boot integration?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"PaymentSetu Pro is \u20b9999 per 30 days with 1,000 verified-payment credits, API access, webhooks and priority support. Smaller projects can compare Starter at \u20b9399 per 30 days, while higher-volume systems can review Business at \u20b91,499 per 30 days on the pricing page.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Learn upi payment integration in java with Spring Boot: create a QR order, verify HMAC webhooks, update orders once, check credits and reconcile safely.","protected":false},"author":1,"featured_media":766,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_singular_sidebar":"","csco_page_header_type":"","csco_page_load_nextpost":"","footnotes":""},"categories":[29],"tags":[244,265,266,30,28],"class_list":["post-767","post","type-post","status-publish","format-standard","has-post-thumbnail","category-upi-payment-verification","tag-api-integration-2","tag-java","tag-spring-boot","tag-upi","tag-webhooks","cs-entry"],"_links":{"self":[{"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/posts\/767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/comments?post=767"}],"version-history":[{"count":1,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/posts\/767\/revisions"}],"predecessor-version":[{"id":977,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/posts\/767\/revisions\/977"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/media\/766"}],"wp:attachment":[{"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/media?parent=767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/categories?post=767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/paymentsetu.com\/blog\/wp-json\/wp\/v2\/tags?post=767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}