iyzipay-java
iyzipay-java copied to clipboard
About the error message: "Geçersiz imza"
Hello,
I am not sure if this error is about the integration department of Iyzico, but we needed to inform you about the issue. The code below is just copied and pasted from the Iyzico Readme.
Indeed, it works quite well when we implement it as a JUnit test. We can even see the transaction on SandBox. But when we try it as a Spring Boot @Service method; the same method returns the aforementioned error message.
We try it on a Spring Boot project and on another pure Java project and got the same result.
Could you help us, please?
Kind regards.
void testSamplePayment() {
Options options = new Options();
options.setApiKey("sandbox-xxxx");
options.setSecretKey("sandbox-xxxx");
options.setBaseUrl("https://sandbox-api.iyzipay.com");
CreatePaymentRequest request = new CreatePaymentRequest();
request.setLocale(Locale.TR.getValue());
request.setConversationId("123456789");
request.setPrice(new BigDecimal("1"));
request.setPaidPrice(new BigDecimal("100"));
request.setCurrency(Currency.TRY.name());
request.setInstallment(1);
request.setBasketId("B67832");
request.setPaymentChannel(PaymentChannel.WEB.name());
request.setPaymentGroup(PaymentGroup.PRODUCT.name());
PaymentCard paymentCard = new PaymentCard();
paymentCard.setCardHolderName("John Doe");
paymentCard.setCardNumber("5528790000000008");
paymentCard.setExpireMonth("12");
paymentCard.setExpireYear("2030");
paymentCard.setCvc("123");
paymentCard.setRegisterCard(0);
request.setPaymentCard(paymentCard);
Buyer buyer = new Buyer();
buyer.setId("BY789");
buyer.setName("John");
buyer.setSurname("Doe");
buyer.setGsmNumber("+905350000000");
buyer.setEmail("[email protected]");
buyer.setIdentityNumber("74300864791");
buyer.setLastLoginDate("2015-10-05 12:43:35");
buyer.setRegistrationDate("2013-04-21 15:12:09");
buyer.setRegistrationAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
buyer.setIp("85.34.78.112");
buyer.setCity("Istanbul");
buyer.setCountry("Turkey");
buyer.setZipCode("34732");
request.setBuyer(buyer);
Address shippingAddress = new Address();
shippingAddress.setContactName("Jane Doe");
shippingAddress.setCity("Istanbul");
shippingAddress.setCountry("Turkey");
shippingAddress.setAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
shippingAddress.setZipCode("34742");
request.setShippingAddress(shippingAddress);
Address billingAddress = new Address();
billingAddress.setContactName("Jane Doe");
billingAddress.setCity("Istanbul");
billingAddress.setCountry("Turkey");
billingAddress.setAddress("Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1");
billingAddress.setZipCode("34742");
request.setBillingAddress(billingAddress);
List<BasketItem> basketItems = new ArrayList<BasketItem>();
BasketItem firstBasketItem = new BasketItem();
firstBasketItem.setId("BI101");
firstBasketItem.setName("Binocular");
firstBasketItem.setCategory1("Collectibles");
firstBasketItem.setCategory2("Accessories");
firstBasketItem.setItemType(BasketItemType.PHYSICAL.name());
firstBasketItem.setPrice(new BigDecimal("0.3"));
basketItems.add(firstBasketItem);
BasketItem secondBasketItem = new BasketItem();
secondBasketItem.setId("BI102");
secondBasketItem.setName("Game code");
secondBasketItem.setCategory1("Game");
secondBasketItem.setCategory2("Online Game Items");
secondBasketItem.setItemType(BasketItemType.VIRTUAL.name());
secondBasketItem.setPrice(new BigDecimal("0.5"));
basketItems.add(secondBasketItem);
BasketItem thirdBasketItem = new BasketItem();
thirdBasketItem.setId("BI103");
thirdBasketItem.setName("Usb");
thirdBasketItem.setCategory1("Electronics");
thirdBasketItem.setCategory2("Usb / Cable");
thirdBasketItem.setItemType(BasketItemType.PHYSICAL.name());
thirdBasketItem.setPrice(new BigDecimal("0.2"));
basketItems.add(thirdBasketItem);
request.setBasketItems(basketItems);
Payment payment = Payment.create(request, options);
}
The root cause of this problem is related to this line: https://github.com/iyzico/iyzipay-java/blob/03947b1a2b0e31b4c258a0060bd5cc278167b183/src/main/java/com/iyzipay/HashGenerator.java#L20
As the getBytes()
method uses the platform's default encoding, this line is platform-dependent.
Passing encoding parameter might be considered in the future: getBytes("UTF-8")
Hi @altayhunoglu ,
In a spring boot project, getBytes("UTF-8")
doesn't seem to work. Could you please help if you overcomed this ?
Thanks
Hello @ozelox34 Sure, glad to help you. Could you try to change your Java system's encoding to UTF-8?
For example if you use VSCode, you can edit launch.json for that.
Otherwise you can try this link:
https://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding
Thanks @altayhunoglu , I have tried several options and come to know that only some methods give this error where others work without any issue in sandbox environment. Getting touch with support. Thanks for your prompt response.
Problemin çözülmüş olması ve zaman aşımından dolayı kapatılmıştır.