Skip to content

Commit

Permalink
DEV-30004 adds refund v2 and threeds auth v2 response signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdurrahman Basgoynuk committed Dec 13, 2024
1 parent 8f8bb70 commit a89e4bb
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/iyzipay/model/Refund.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.iyzipay.IyzipayResource;
import com.iyzipay.Options;
import com.iyzipay.request.CreateRefundRequest;
import com.iyzipay.request.CreateRefundV2Request;

public class Refund extends IyzipayResource {

Expand All @@ -27,6 +28,15 @@ public static Refund create(CreateRefundRequest request, Options options) {
Refund.class);
}

public static Refund createV2(CreateRefundV2Request request, Options options) {
String path = "/v2/payment/refund";
return HttpClient.create().post(options.getBaseUrl() + path,
getHttpProxy(options),
getHttpHeadersV2(path, request, options),
request,
Refund.class);
}

public String getPaymentId() {
return paymentId;
}
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/iyzipay/request/CreateRefundV2Request.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.iyzipay.request;

import com.iyzipay.Request;
import com.iyzipay.ToStringRequestBuilder;

import java.math.BigDecimal;

public class CreateRefundV2Request extends Request {

private String paymentId;
private BigDecimal price;
private String ip;


public String getPaymentId() {
return paymentId;
}

public void setPaymentId(String paymentId) {
this.paymentId = paymentId;
}

public BigDecimal getPrice() {
return price;
}

public void setPrice(BigDecimal price) {
this.price = price;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

@Override
public String toString() {
return new ToStringRequestBuilder(this)
.appendSuper(super.toString())
.append("paymentId", paymentId)
.append("price", price)
.append("ip", ip)
.toString();
}
}
32 changes: 32 additions & 0 deletions src/test/java/com/iyzipay/functional/RefundTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.iyzipay.model.*;
import com.iyzipay.request.CreatePaymentRequest;
import com.iyzipay.request.CreateRefundRequest;
import com.iyzipay.request.CreateRefundV2Request;
import org.junit.Test;

import java.math.BigDecimal;
Expand Down Expand Up @@ -81,4 +82,35 @@ public void should_refund_fraudulent_payment() {
assertNull(refund.getErrorMessage());
assertNull(refund.getErrorGroup());
}

@Test
public void should_refund_v2_payment() {
CreatePaymentRequest paymentRequest = CreatePaymentRequestBuilder.create()
.standardListingPayment()
.build();

Payment payment = Payment.create(paymentRequest, options);

CreateRefundV2Request request = new CreateRefundV2Request();
request.setLocale(Locale.TR.getValue());
request.setConversationId("123456789");
request.setPaymentId(payment.getPaymentId());
request.setPrice(new BigDecimal("1.1"));
request.setIp("85.34.78.112");

Refund refund = Refund.createV2(request, options);

System.out.println(refund);

assertEquals(Status.SUCCESS.getValue(), refund.getStatus());
assertEquals(Locale.TR.getValue(), refund.getLocale());
assertTrue(payment.verifySignature(options.getSecretKey()));
assertEquals("123456789", refund.getConversationId());
assertEquals(payment.getPaymentId(), refund.getPaymentId());
assertNotEquals(0, refund.getSystemTime());
assertNotNull(refund.getHostReference());
assertNull(refund.getErrorCode());
assertNull(refund.getErrorMessage());
assertNull(refund.getErrorGroup());
}
}
23 changes: 23 additions & 0 deletions src/test/java/com/iyzipay/sample/RefundSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.iyzipay.model.RefundReason;
import com.iyzipay.model.Status;
import com.iyzipay.request.CreateRefundRequest;
import com.iyzipay.request.CreateRefundV2Request;
import org.junit.Test;

import java.math.BigDecimal;
Expand Down Expand Up @@ -88,4 +89,26 @@ public void should_refund_fraudulent_payment() {
assertNull(refund.getErrorMessage());
assertNull(refund.getErrorGroup());
}

@Test
public void should_refund_v2_payment() {
CreateRefundV2Request request = new CreateRefundV2Request();
request.setLocale(Locale.TR.getValue());
request.setConversationId("123456789");
request.setPaymentId("1");
request.setPrice(new BigDecimal("1.1"));
request.setIp("85.34.78.112");

Refund refund = Refund.createV2(request, options);

System.out.println(refund);

assertEquals(Status.SUCCESS.getValue(), refund.getStatus());
assertEquals(Locale.TR.getValue(), refund.getLocale());
assertEquals("123456789", refund.getConversationId());
assertNotEquals(0, refund.getSystemTime());
assertNull(refund.getErrorCode());
assertNull(refund.getErrorMessage());
assertNull(refund.getErrorGroup());
}
}
1 change: 1 addition & 0 deletions src/test/java/com/iyzipay/sample/ThreedsSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public void should_create_threeds_payment_v2() {

assertEquals(Status.SUCCESS.getValue(), threedsPayment.getStatus());
assertEquals(Locale.TR.getValue(), threedsPayment.getLocale());
assertTrue(threedsPayment.verifySignature(options.getSecretKey()));
assertEquals("123456789", threedsPayment.getConversationId());
assertNotEquals(0, threedsPayment.getSystemTime());
assertNull(threedsPayment.getErrorCode());
Expand Down

0 comments on commit a89e4bb

Please sign in to comment.