Skip to content
This repository was archived by the owner on Nov 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ public List<ScheduledPaymentResponseDto> 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(),
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion payment-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down