diff --git a/payment-service/src/main/java/com/techtorque/payment_service/service/impl/BillingServiceImpl.java b/payment-service/src/main/java/com/techtorque/payment_service/service/impl/BillingServiceImpl.java index 0765b2f..b1a9e35 100644 --- a/payment-service/src/main/java/com/techtorque/payment_service/service/impl/BillingServiceImpl.java +++ b/payment-service/src/main/java/com/techtorque/payment_service/service/impl/BillingServiceImpl.java @@ -315,6 +315,13 @@ public List getScheduledPaymentsForCustomer(String public PaymentInitiationResponseDto initiatePayHerePayment(PaymentInitiationDto dto) { log.info("Initiating PayHere payment for invoice: {}", dto.getInvoiceId()); + // Log payment details for debugging + log.info("Payment Details - Merchant ID: {}, Order ID: {}, Amount: {}, Currency: {}", + payHereConfig.getMerchantId(), + dto.getInvoiceId(), + dto.getAmount(), + dto.getCurrency()); + // Generate payment hash using utility method String hash = PayHereHashUtil.generatePaymentHash( payHereConfig.getMerchantId(), @@ -324,7 +331,7 @@ public PaymentInitiationResponseDto initiatePayHerePayment(PaymentInitiationDto payHereConfig.getMerchantSecret() ); - log.info("PayHere payment hash generated for order: {}", dto.getInvoiceId()); + log.info("PayHere payment hash generated: {} for order: {}", hash, dto.getInvoiceId()); // Build response with all PayHere required parameters PaymentInitiationResponseDto response = new PaymentInitiationResponseDto(); diff --git a/payment-service/src/main/java/com/techtorque/payment_service/util/PayHereHashUtil.java b/payment-service/src/main/java/com/techtorque/payment_service/util/PayHereHashUtil.java index 508673a..0044dee 100644 --- a/payment-service/src/main/java/com/techtorque/payment_service/util/PayHereHashUtil.java +++ b/payment-service/src/main/java/com/techtorque/payment_service/util/PayHereHashUtil.java @@ -54,18 +54,25 @@ public static String generatePaymentHash( // Try to decode as Base64 byte[] decodedBytes = Base64.getDecoder().decode(merchantSecret); decodedSecret = new String(decodedBytes); + System.out.println("DEBUG: Merchant secret was Base64 encoded, decoded successfully"); } catch (IllegalArgumentException e) { // If decoding fails, use as-is (it's already plain text) decodedSecret = merchantSecret; + System.out.println("DEBUG: Merchant secret is plain text (not Base64)"); } // Step 1: Hash the merchant secret String hashedSecret = getMd5(decodedSecret); + System.out.println("DEBUG: Hashed secret: " + hashedSecret); // Step 2: Concatenate: merchant_id + order_id + amount + currency + hashed_secret String concatenated = merchantId + orderId + formattedAmount + currency + hashedSecret; + System.out.println("DEBUG: Hash input string: " + concatenated); // Step 3: Hash the concatenated string - return getMd5(concatenated); + String finalHash = getMd5(concatenated); + System.out.println("DEBUG: Final hash: " + finalHash); + + return finalHash; } } diff --git a/payment-service/src/main/resources/application.properties b/payment-service/src/main/resources/application.properties index 228b71b..f23640b 100644 --- a/payment-service/src/main/resources/application.properties +++ b/payment-service/src/main/resources/application.properties @@ -21,7 +21,7 @@ spring.profiles.active=${SPRING_PROFILE:dev} # http://localhost:8086/swagger-ui/index.html # PayHere Payment Gateway Configuration (Sandbox) -# Domain: techtorque +# Domain: techtorque.randitha.net payhere.merchant.id=${PAYHERE_MERCHANT_ID:1231968} payhere.merchant.secret=${PAYHERE_MERCHANT_SECRET:MjE0Mzc0NzgxMjEzMDE1NzYxNzE1NDIzNzA1MTIzMDI2NTc1ODQw} payhere.sandbox=${PAYHERE_SANDBOX:true}